2

I have a USB to RS232 adapter with which I'm connecting my MacBook Pro (OS X 10.9) to an EVK1100 board from Atmel. The program on the board outputs a lot of information on the serial port and I'd like to be able to inspect it. However, I'm struggling to find a program for that.

Plugging in the adapter makes two devices appear:

  • /dev/cu.usbserial-FTB3VVRF
  • /dev/tty.usbserial-FTB3VVRF

I can't straight-up cat the tty device because it needs a baud rate. I can specify a baud rate with screen but it won't let me pipe and it'll only display a single screen's worth of data.

What can I do?

4

I used to

(stty speed 115200 >/dev/null && cat) </dev/cu.usbserial-FTB3VVRF | tee serial.log

when I wanted to pipe from serial.

1

I found nothing, so I wrote a short program to do just that.

#include <iostream>
#include <string>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>

using namespace std;

int main(int argc, const char * argv[])
{
    if (argc < 2 || argc > 3)
    {
        cerr << "usage: " << argv[0] << " device [bauds]" << endl;
        return 1;
    }

    string device = argv[1];
    unsigned long bauds = 9600;
    if (argc == 3)
    {
        char* result;
        bauds = strtoul(argv[2], &result, 10);
        if (*result != '\0')
        {
            cerr << "usage: " << argv[0] << " device [bauds]" << endl;
            return 1;
        }
    }

    int fd = open(argv[1], O_RDWR | O_NDELAY | O_NOCTTY);
    if (fd == -1)
    {
        perror((string("can't open ") + argv[1]).c_str());
        exit(errno);
    }

    struct termios config;
    if (tcgetattr(fd, &config) < 0)
    {
        perror("can't get serial attributes");
        exit(errno);
    }

    if (cfsetispeed(&config, bauds) < 0 || cfsetospeed(&config, bauds) < 0)
    {
        perror("can't set baud rate");
        exit(errno);
    }

    config.c_iflag &= ~(IGNBRK | BRKINT | ICRNL | INLCR | PARMRK | INPCK | ISTRIP | IXON);
    config.c_oflag = 0;
    config.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
    config.c_cflag &= ~(CSIZE | PARENB);
    config.c_cflag |= CS8;
    config.c_cc[VMIN]  = 1;
    config.c_cc[VTIME] = 0;

    if (tcsetattr(fd, TCSAFLUSH, &config) < 0)
    {
        perror("can't set serial attributes");
        exit(errno);
    }

    char buffer[80];
    while (true)
    {
        size_t n = read(fd, buffer, sizeof buffer);
        write(STDOUT_FILENO, buffer, n);
    }

    close(fd);
    return 0;
}
1

I found out pySerial has a nifty little tool called miniterm that works great. I used it like this:

$ pip install pyserial
$ python -m serial.tools.miniterm /dev/cu.usbserial 9600
...
2
  • Thank you for the suggestion. To install pySerial as a python module (so that in the second command, python can find the mentioned module serial.tools.miniterm), need to install pySerial as a module: python -m pip install pyserial – Pragmatic geek Aug 13 '17 at 13:16
  • And of course the output can be redirected (e.g. to a file): python -m serial.tools.miniterm /dev/cu.usbmodem1421 115200 > sensor_data.txt. /dev/cu.usbmodem1421 is my port name, you need to replace it with your own port. To find the port name with which your device is known, do a ls /dev/ (pardon if this is too obvious, this is for newbies, incl. myself). – Pragmatic geek Aug 13 '17 at 13:21
0

CoolTerm is a Mac terminal app that should be able to connect to your serial device.

Otherwise here is a list of Mac GUI terminal apps. And here is a list of (command line) Mac terminal software.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.