Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Wixel RTS/DTR Pin Toggle Not Working In OS X


#1

Hey all,

I have been trying for a while to get the RTS pin to toggle in OS X. The DTR works fine and both work fine if I do it in Windows.

I am using CoolTerm to toggle the pins.

Does anybody have an idea of what may be the problem? It’s driving me crazy.

Thanks in advance!

Jay


#2

Hello, Jay.

I tested this here on Mac OS X 10.10.4. It looks like Mac OS X does not let you control either DTR or RTS: they will just be high whenever the port is open, and they will go low again when the port is closed. If I try to set them using TIOCMSET, I get an error. Here is the code I used to test this:

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>

int main()
{
  printf("DTR: 0x%x\n", TIOCM_DTR);
  printf("RTS: 0x%x\n", TIOCM_RTS);

  const char * device = "/dev/cu.usbmodemfd121";
  int fd = open(device, O_RDWR | O_NOCTTY);
  if (fd == -1)
  {
    perror(device);
    return 1;
  }

  struct termios options;
  if (tcgetattr(fd, &options) != 0)
  {
    perror("tcgetattr failed");
    return 1;
  }
  options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
  options.c_oflag &= ~(ONLCR | OCRNL);
  options.c_cflag &= ~(CRTSCTS);
  if (tcsetattr(fd, TCSANOW, &options) != 0)
  {
    perror("tcsetattr failed");
    return 1;
  }

  while(1)
  {
    int status = 0xFF;
    if (ioctl(fd, TIOCMGET, &status) != 0)
    {
      perror("Failed to get control line status");
      return 1;
    }

    printf("status: 0x%x\n", status);
    status ^= TIOCM_RTS;

    if (ioctl(fd, TIOCMSET, status) != 0)
    {
      perror("Failed to set control line status");
    }

    usleep(500000);
  }

  close(fd);
  return 0;
}

Here is the output I got on Mac OS X:

DTR: 0x2
RTS: 0x4
status: 0x26
Failed to set control line status: Bad address
status: 0x26
Failed to set control line status: Bad address

Maybe there is some other way to control those pins on Mac OS X. The code above turns off CTS and RTS flow control, but there is some code from Apple that appears to turn on flow control and set the value of the DTR pin.

–David


#3

David,

There doesn’t seem to be much difference between what you’re doing and what they’re doing.

I’ll keep playing and try to work something out.

Thanks for your help! Greatly appreciated.

Jay