Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- octave:9> sif = "/dev/ttyUSB0";
- octave:10> s = serial(sif, 115200);
- octave:11>
- octave:11> # Example 1: blocking read, returns exactly 6 bytes (old behavior)
- octave:11> srl_flush(s) ; srl_write(s, "Hello1!"); [data, count] = srl_read(s, 7); char(data), count
- ans = Hello1!
- count = 7
- octave:12>
- 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)
- 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
- Elapsed time is 0.00024 seconds.
- ans = Hello2!
- count = 7
- octave:13>
- 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)
- 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
- Elapsed time is 3 seconds.
- ans = Hello3!
- count = 7
- octave:14>
- 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)
- 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);
- Elapsed time is 3 seconds.
- ans =
- count = 0
- octave:15>
Advertisement
Add Comment
Please, Sign In to add comment