Serial Communication in OSX Terminal

knew it had to be possible to view serial data in the OSX terminal window, but I’m not enough of a unix geek to figure it out. Finally, a little googling told me what I needed to know. Here’s how to read and send serial data from the terminal in OSX.

Technorati Tags: , , ,



First, open Terminal. If you’ve never used it before, it’s under Applications/Utilities/Terminal. Next, type

ls /dev/tty.*

to get a list of all of your serial ports. Pick the one that you want to open. For example, my list looks like this:

/dev/tty.BTRS232                        /dev/tty.Tigoe6630-AppleAgent-1
/dev/tty.Bluetooth-Modem                /dev/tty.Tigoe6630-Dial-UpNetwor-2
/dev/tty.KeySerial1                     /dev/tty.modem

And I know from previous experience that /dev/tty.Keyserial1 is my Keyspan USB-to-serial adaptor. It’s connected to a PIC at the moment. The PIC’s programmed to read one byte of serial data at 9600 bits per second, then send back three bytes, “A”, “B” and “C”.
Knowing the serial port, you can just type screen portname datarate to show the serial data on the screen. In my case, it was:

screen /dev/tty.Keyserial1 9600

Then I started typing bytes at the PIC, and it sent bytes back to me. Whee! No need for zTerm! To quit the screen app, tyoe control-A, then control-\.