Guest User

Untitled

a guest
Aug 16th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. octave:38> sif0 = "/dev/pts/2";
  2. octave:39> sif1 = "/dev/pts/3";
  3. octave:40> s0 = serial(sif0, 115200);
  4. octave:41> s1 = serial(sif1, 115200);
  5. octave:42>
  6. octave:42> # Example 1: blocking read, returns exactly 6 bytes (old behavior)
  7. octave:42> srl_flush(s0); srl_flush(s1); srl_write(s0, "Hello1!"); [data, count] = srl_read(s1, 7); char(data), count
  8. ans = Hello1!
  9. count = 7
  10. octave:43>
  11. octave:43> # 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)
  12. octave:43> srl_timeout(s1, 0); srl_flush(s0); srl_flush(s1); srl_write(s0, "Hello2!"); sleep(1); tic(); [data, count] = srl_read(s1, 10); toc(); char(data), count
  13. Elapsed time is 0.00022 seconds.
  14. ans = Hello2!
  15. count = 7
  16. octave:44>
  17. octave:44> # Example 3: non-blocking read, returns 6 bytes after a timeout of 3.0 seconds (n.b. tried to read up to 10)
  18. octave:44> srl_timeout(s1, 30); srl_flush(s0); srl_flush(s1); srl_write(s0, "Hello3!"); sleep(1); tic(); [data, count] = srl_read(s1, 10); toc(); char(data), count
  19. Elapsed time is 3 seconds.
  20. ans = Hello3!
  21. count = 7
  22. octave:45>
  23. octave:45> # 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)
  24. octave:45> srl_flush(s0); srl_flush(s1); sleep (1); tic(); [data, count] = srl_read(s1, 10); toc(); char(data), count, srl_close(s0); srl_close(s1);
  25. Elapsed time is 3 seconds.
  26. ans =
  27. count = 0
  28. octave:46>
Advertisement
Add Comment
Please, Sign In to add comment