SHOW:
|
|
- or go back to the newest paste.
| 1 | - | octave:2> pkg load serial |
| 1 | + | octave:9> sif = "/dev/ttyUSB0"; |
| 2 | - | octave:3> sif = "/dev/ttyUSB0"; |
| 2 | + | octave:10> s = serial(sif, 115200); |
| 3 | - | octave:4> s = serial(sif, 115200); |
| 3 | + | octave:11> |
| 4 | - | octave:5> |
| 4 | + | octave:11> # Example 1: blocking read, returns exactly 6 bytes (old behavior) |
| 5 | - | octave:5> # 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 | - | octave:5> srl_flush(s) ; srl_write(s, "Hello1!"); [data, count] = srl_read(s, 7); char(data), count |
| 6 | + | |
| 7 | count = 7 | |
| 8 | octave:12> | |
| 9 | - | octave:6> |
| 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: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) |
| 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 | - | 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 |
| 11 | + | Elapsed time is 0.00024 seconds. |
| 12 | - | Elapsed time is 0.00025 seconds. |
| 12 | + | |
| 13 | count = 7 | |
| 14 | octave:13> | |
| 15 | - | octave:7> |
| 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:7> # 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 | - | 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 |
| 17 | + | |
| 18 | ans = Hello3! | |
| 19 | count = 7 | |
| 20 | octave:14> | |
| 21 | - | octave:8> |
| 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: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) |
| 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 | - | 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); |
| 23 | + | |
| 24 | Elapsed time is 3 seconds. | |
| 25 | ans = | |
| 26 | - | count = 0 |
| 26 | + | count = 0 |
| 27 | octave:15> |