Guest User

Untitled

a guest
Aug 16th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. octave:2> pkg load serial
  2. octave:3> sif = "/dev/ttyUSB0";
  3. octave:4> s = serial(sif, 115200);
  4. octave:5>
  5. octave:5> # Example 1: blocking read, returns exactly 6 bytes (old behavior)
  6. octave:5> srl_flush(s) ; srl_write(s, "Hello1!"); [data, count] = srl_read(s, 7); char(data), count
  7. ans = Hello1!
  8. count = 7
  9. octave:6>
  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)
  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
  12. Elapsed time is 0.00025 seconds.
  13. ans = Hello2!
  14. count = 7
  15. octave:7>
  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)
  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
  18. Elapsed time is 3 seconds.
  19. ans = Hello3!
  20. count = 7
  21. octave:8>
  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)
  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);
  24. Elapsed time is 3 seconds.
  25. ans =
  26. count = 0
Advertisement
Add Comment
Please, Sign In to add comment