Controlling the Serial port

Greg Hormann ghormann at alumni.indiana.edu
Tue Jul 6 19:53:26 PDT 2004


I'm working to develop a communications program to control a piece of
vendor supplied hardware. (They only provide a control program for
Windows.) I think I'm close. The device uses a RS-232 -> RS-485 convert
which I belive is powered by either the RTS or DTR line of the serial
port.  How can I force these two lines to say powered in FreeBSD inside a
C program thus providing power to the converter?  I only need to
write to the device.

Here is what I have so far. This is my first serial port programming task,
so I probably have a few mistakes.

Thanks,
Greg.

   if ((device = open("/dev/cuaa0", O_RDWR | O_NOCTTY |O_NDELAY)) == -1)
   {
      printf("Error opening port");
      exit(1);
   }

   tcgetattr(device, &term); /* get current port settings */
   cfsetspeed(&term, B19200);

   term.c_iflag |= IGNPAR; /* ignore incoming parity */
   term.c_iflag &= ~(IXON|IXOFF); /* turn OFF Xon/Xoff */
   term.c_cflag &= ~CSIZE; /* clear previous character size */
   term.c_cflag |= CS8; /* 8 data bits */
   term.c_cflag &= ~(CSTOPB|PARENB|CLOCAL);
   /* 1 stop bit, no output parity, enable modem ctrl */
   term.c_cflag |= CRTSCTS|CRTS_IFLOW; /* RTS/CTS ctrl on */

   term.c_cc[VMIN]=0; /* no min characters/read */
   term.c_cc[VTIME]=0; /* no read timeout */
   term.c_lflag &= ~ICANON; /* noncanonical mode */

   tcsetattr(device, TCSANOW, &term);



More information about the freebsd-hackers mailing list