Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- octave:2> pkg load serial
- octave:3> sif = "/dev/ttyUSB0";
- octave:4> s = serial(sif, 115200);
- octave:5>
- octave:5> # Example 1: blocking read, returns exactly 6 bytes (old behavior)
- octave:5> srl_flush(s) ; srl_write(s, "Hello1!"); [data, count] = srl_read(s, 7); char(data), count
- ans = Hello1!
- count = 7
- octave:6>
- octave:6> # 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:6> 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.00025 seconds.
- ans = Hello2!
- count = 7
- octave:7>
- octave:7> # Example 3: non-blocking read, returns 6 bytes after a timeout of 3.0 seconds (n.b. tried to read up to 10)
- octave:7> 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:8>
- octave:8> # 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:8> 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
Advertisement
Add Comment
Please, Sign In to add comment