0

I am trying to talk to a power supply from my mac OS X Yosemite. The code works fine on a linux machine, but when I try it on my mac, it does not work. I am using a usb-serial converter and have downloaded the PL-2303 driver. The driver shows up in my /dev folder as cu.usbserial and tty.usbserial.

The part of my code that fails:

fd = initserial("/dev/cu.usbserial");

int initserial(char port[])
{
  struct termios shimtermios;
  int fd;

  if((fd=open(port,O_RDWR)) < 0)  {
    perror("Opening the RS-232 port failed for initserial\n");
    exit(-1);
  }

  if (tcgetattr(fd, &shimtermios) < 0) { 
    perror("couldn't get terminal attributes\n");
    exit(-2);
  }

  shimtermios.c_iflag=012005;
  shimtermios.c_oflag=014004;
  shimtermios.c_cflag=03206276;
  shimtermios.c_lflag=05060;
  cfsetospeed(&shimtermios,B19200);

  if (tcsetattr(fd, TCSAFLUSH, &shimtermios) < 0) {
    perror("couldn't set terminal attributes\n");
    exit(-3);
  }
  return (fd);
}

I get the following error message

couldn't set terminal attributes
: Invalid argument

Please let me know if you have any experience with this linux/unix issue. Thank you so much!

  • What are those values for the flags supposed to represent? I'm pretty sure the exact values won't match across OSes. –  Sep 02 '15 at 01:46
  • Sorry I actually do not know...the code is pretty old and from somebody else who also does not remember what the flags represent. Now my code executes past the initserial() function, but for some reason is having trouble reading from and writing currents to the power supply. `code` while( *command != '\0' ) write(fd, command++, 1); printf("here1\n"); while(read_data != '\n') { printf("comeon \n"); read(fd,&read_data,1); printf("%s",read_data); } – Patricia Sep 03 '15 at 20:58

1 Answers1

0

See the termios man page for the valid masks that can be used for c_iflag, c_oflag, c_cflag, and c_lflag). You should OR the mask constants together rather than hard-coding the values.

Also from experience, FTDI USB-serial converters tend to work better on OS X than pl2303. OS X has a built-in driver for these (AppleUSBFTDI).

Brendan Shanks
  • 3,141
  • 14
  • 13