Advertisement
opexxx

Serial Port Tricks

May 5th, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.15 KB | None | 0 0
  1. Serial Port Tricks
  2. from: http://www.aeronetworks.ca/2013/10/serial-port-tricks.html
  3. Bidirectional
  4. The Netcat program can shovel data bidirectionally to/from a serial port and over a network, which is very handy indeed.
  5.  
  6. Set the serial port in raw mode and configure it:
  7. # stty -F /dev/ttyUSB0 raw
  8. # stty -F /dev/ttyUSB1 raw
  9. # stty -F /dev/ttyUSB0 19200
  10. # stty -F /dev/ttyUSB1 19200
  11.  
  12. Set up a netcat listener that will send data to/from the one serial device:
  13. # nc -l 1234 < /dev/ttyUSB1 >/dev/ttyUSB1
  14.  
  15. Set up a netcat client that will send data to/from the other serial device:
  16. # nc listeneripaddress 1234 < /dev/ttyUSB0 >/dev/ttyUSB0
  17. Unidirectional
  18. For debugging and scripting, you can also use ordinary cat, echo, head or even data definition to access the serial ports:
  19.  
  20. Send data one way only using the common kitty:
  21. # cat /dev/ttyUSB0 > /dev/ttyUSB1
  22.  
  23. Send a message out a port using echo:
  24. # echo Hello > /dev/ttyUSB0
  25.  
  26. Send data denoted as hexadecimal values and suppress the LF at the end of the line:
  27. # echo -en "\x12\x23\x45" > /dev/ttyUSB0
  28.  
  29. Read one character from a serial port using head:
  30. # $CHAR = head -c 1 /dev/ttyUSB0
  31. # echo $CHAR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement