Reading DTR on Linux Connect ME 9210

I’m working on an embedded system in which the serial port of the CME9210 must be configurable as either DTE or DCE. In the easy way (DTE), the device asserts DTR when the port is opened, letting the other end know it’s ready. No problem there.

The other way (DCE) is not so easy. I need to read DTR and do something when it gets asserted. I can use ioctl() to read the DTR pin, sure enough, but the value is whatever I last set it to be. In short, this pin is an output, but I need to float this pin so I can use it as an input, to be set by whatever the serial port gets plugged into. This seems to be a surprisingly uncommon thing to want to do.

Any ideas?

I used to read DTR as mentioned below.

int stats;

if( ioctl(hndl,TIOCMGET,&stats) < 0 )
perror("DTR GET Failed
");

/SET DTR bit/
stats &= TIOCM_DTR;
if( ioctl(hndl,TIOCMSET,&stats) < 0 )
perror("DTR SET Failed
");

/CLEAR DTR bit/
stats |= TIOCM_DTR;
if( ioctl(hndl,TIOCMSET,&stats) < 0 )
printf("DTR CLEAR Failed : %d
",errno);

Well my serial programming reference was
http://www.easysw.com/~mike/serial/serial.html#4_2_1