Serial Ports using C - Help

Serial Ports using C - Help

Post by xno.. » Tue, 20 Sep 1994 16:33:23



I have never used this before so this should prove interesting.

I am trying to write a C program which opens a /dev/tty serial port.
I have no problems setting the baud rate, stop bits, parity etc using
ioctl(fileDescriptor, TCGETA, &ioctlStructure);
and
ioctl(fileDescriptor, TCSETA, &ioctlStructure);

The code is being tested on DEC/ULTRIX but will end up running under IBM/AIX.

However, I do have problems with the following.

------------------------
How do I tell if the other end has dropped its CD or DSR such that I
can have the program reset appropriately.

What commands do I need to have such that I support the modem lines fully
and correctly.
------------------------

I already use the following code :-

open(portName, O_RDRW | O_NDELAY | O_BLKINUSE | O_BLKANDSET | O_NSHARE)
ioctl(fileDescriptor, TCGETA, &ioctlStructure);
/* setup structure appropriately */

ioctl(fileDescriptor, TCSETA, &ioctlStructure);
ioctl(fileDescriptor, TIOCCAR, &aZero);
ioctl(fileDescriptor, TIOCHPCL);
ioctl(fileDescriptor, TIOCSDTR);

I then use read(), write() and select().

Code samples or a direction in which to go to find these samples would
be greatly appreciated.

This is actually being used to communicate with a PC running SYMBOL Technologies
Serial Access Bridge software, for those of you who are interested.

                                ...Lyall Pearce