Using the QNX4 qnx_ioctl() to raise and lower RTS and DTR.
Title: Using the QNX4 qnx_ioctl() to raise and lower RTS and DTR.
Keywords: QNX4, qnx_ioctl, RTS, DTR
Date: May 15 1996
Author: KAM
Kdb Number: kdb-103
Distribution: External
/*Below is an example of how to use the QNX4 qnx_ioctl function call to
raise and lower DTR on a serial port. Look at bits defs to see which bit
is for RTS.
Bit defs
========
Bit 0 = DTR power = 1
Bit 1 = RTS power = 2
/************************************************************************** */
#include
#include
#include
#include
#include
/* Function to set/clear dtr */
/* Look in sys/qioctl.h for definitions */
void dropDTR( FILE *fp );
void raiseDTR( FILE *fp );
void main( int argc, char *argv[] ) {
FILE *fpin;
if( argc < 1 ){
printf( "USE: ioctl deviceName\n" );
exit( -1 );
}
fpin = fopen( argv[1], "r" );
if( fpin == NULL ){
printf( "Error opening device %s for input\n", argv[1] );
exit( -1 );
}
setbuf( fpin, NULL );
while( 1 ){
printf("Raising DTR\n");
raiseDTR( fpin );
sleep( 1 );
printf("Dropping DTR\n");
dropDTR( fpin );
sleep( 1 );
printf("Raising RTS\n");
raiseRTS( fpin );
sleep( 1 );
printf("Dropping RTS\n");
dropRTS( fpin );
sleep( 1 );
}
}
void raiseDTR( FILE *fp ) {
unsigned long sendbuf[2];
sendbuf[0] = 1L; /* state to set bit */
sendbuf[1] = 1L; /* power of bit to change */
qnx_ioctl( fileno( fp ), QCTL_DEV_CTL, sendbuf, 8, (void *)0, 0 );
}
void dropDTR( FILE *fp ){
unsigned long sendbuf[2];
sendbuf[0] = 0L; /* state to set bit */
sendbuf[1] = 1L; /* power of bit to change */
qnx_ioctl( fileno( fp ), QCTL_DEV_CTL, sendbuf, 8, (void *)0, 0 );
}
void raiseRTS( FILE *fp ) {
unsigned long sendbuf[2];
sendbuf[0] = 2L; /* state to set bit */
sendbuf[1] = 2L; /* power of bit to change */
qnx_ioctl( fileno( fp ), QCTL_DEV_CTL, sendbuf, 8, (void *)0, 0 );
}
void dropRTS( FILE *fp ) {
unsigned long sendbuf[2];
sendbuf[0] = 0L; /* state to set bit */
sendbuf[1] = 2L; /* power of bit to change */
qnx_ioctl( fileno( fp ), QCTL_DEV_CTL, sendbuf, 8, (void *)0, 0 );
}