View difference between Paste ID: Wb4Yq1r6 and bUb7hqUG
SHOW: | | - or go back to the newest paste.
1
octave:9> sif = "/dev/ttyUSB0";
2
octave:10> s = serial(sif, 115200);
3
octave:11> 
4
octave:11> # Example 1: blocking read, returns exactly 6 bytes (old behavior)
5
octave:11> srl_flush(s) ; srl_write(s, "Hello1!"); [data, count] = srl_read(s, 7); char(data), count
6
ans = Hello1!
7
count =  7
8
octave:12> 
9
octave:12> # Example 2: non-blocking read, returns 6 bytes from buffer immediately (n.b. tried to read up to 10, only 6 written to the buffer)
10
octave:12> srl_timeout(s, 0); srl_flush(s) ; srl_write(s, "Hello2!"); sleep(1); tic(); [data, count] = srl_read(s, 10); toc(); char(data), count
11
Elapsed time is 0.00024 seconds.
12
ans = Hello2!
13
count =  7
14
octave:13> 
15
octave:13> # Example 3: non-blocking read, returns 6 bytes after a timeout of 3.0 seconds (n.b. tried to read up to 10)
16
octave:13> srl_timeout(s, 30); srl_flush(s) ; srl_write(s, "Hello3!"); sleep(1); tic(); [data, count] = srl_read(s, 10); toc(); char(data), count
17
Elapsed time is 3 seconds.
18
ans = Hello3!
19
count =  7
20
octave:14> 
21
octave:14> # Example 4: non-blocking read, returns no data after timeout of 3.0 seconds (n.b. there was no data available to the interface before reading)
22
octave:14> srl_timeout(s, 30); srl_flush(s) ; sleep (1); tic(); [data, count] = srl_read(s, 10); toc(); char(data), count,  srl_close(s);
23-
23+
24
ans = 
25
count = 0
26
octave:15>