Search code examples
macosserial-portusbttysocat

USB Serial Port on Mac using socat


I have a piece of hardware that is connected over a Prolific Serial to USB cable and I need to use socat to send/receive traffic to/from this and a TCP port. So far it's installed and works fine with minicom using:

minicom -D /dev/tty.usbserial -b 9600

Socat works in one direction to a TCP port using:

socat /dev/tty.usbserial,clocal=1,nonblock=1,cread=1,cs8,ixon=1,ixoff=1 TCP4:localhost:8080

How do I get it working two way? I often see repeated characters or double lines which suggests an incorrect serial setup right?

Thanks! Chris

Edit: Some example code (that doesn't actually work in a bidirectional way).

Chris-MacBookAir:~ chrisbridges$ socat -d -d - /dev/tty.usbserial,clocal=1,nonblock=1,cs8,ixon=1,ixoff=1,ispeed=9600,ospeed=9600,icanon=1
2013/01/09 13:13:34 socat[8501] N reading from and writing to stdio
2013/01/09 13:13:34 socat[8501] N opening character device "/dev/tty.usbserial" for reading and writing
2013/01/09 13:13:34 socat[8501] N starting data transfer loop with FDs [0,1] and [3,3]

Solution

  • Thanks for the help. I've now resolved it and can communicate fine. Socat is indeed a complex tool. Here are my final settings:

    sudo socat -U -d -d -d /dev/tty.usbserial,clocal=1,cs8,nonblock=1,ixoff=0,ixon=0,ispeed=9600,ospeed=9600,raw,echo=0,crtscts=0 FILE:tnc-start.hex
    

    Where 'ixon' is enable XON/XOFF flow control, 'ixoff' is enable sending of start/stop characters, and rather interestingly 'echo' doesn't print to console but echo's whatever is transmitted back at the sender... odd!