Guest User

Untitled

a guest
Aug 15th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.34 KB | None | 0 0
  1. octave:1> pkg load serial
  2. octave:2> sif = "/dev/ttyUSB1";
  3. octave:3> s = serial(sif, 115200);
  4. octave:4>
  5. octave:4> # Example 1: blocking read, returns exactly 6 bytes (old behavior)
  6. octave:4> srl_flush(s) ; srl_write(s, "Hello1!"); [data, count] = srl_read(s, 7); char(data), count
  7. ans = Hello1!
  8. count =  7
  9. octave:5>
  10. octave:5> # 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:5> 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.00022 seconds.
  13. ans = Hello2!
  14. count =  7
  15. octave:6>
  16. octave:6> # 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:6> 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:7>
  22. octave:7> # 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:7> 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
  27. octave:8>
Advertisement
Add Comment
Please, Sign In to add comment