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.