[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

serial port DTR RTS direct control failed !!



Hi all,

Please give me some advices on this!!

I tried to directly control the RTS and DTR pins on the ETRAX 100 serial
port. I ran the C programme on a PC with Redhat 7.0, it worked perfect. But
when I ran on the ETRAX board (with latest elinux), they is no response at all.

The PC serial port pins (1,6,8) had a voltage swing of +/- 11V, where as in
the ETRAX the voltage of the same pins remains at +7V all the time.

Many thanks in advance!!

Below is the source code:

**************************************************************************

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <errno.h>

#include <sys/ioctl.h>

#define BAUDRATE B38400            
#define PORT "/dev/ttyS0"

int main(int argc, char **argv)
{
	int fd,c, res;
        struct termios oldtio,newtio;
        char buf[255];

//
int rtsEnable, rtsflags;
	int dtrEnable, dtrflags;
//
int tdEnable, tdflags;

        /* Open modem device for reading and writing and not as controlling tty
           because we don't want to get killed if linenoise sends CTRL-C.*/
        fd = open(PORT, O_RDWR | O_NOCTTY ); 
        if (fd <0) 
	{
		perror(PORT); 
		printf("cannot open serial port");
		exit(-1); 
	}

	sscanf(PORT, "%d", &dtrEnable);
	fprintf(stderr, "dtrEnable are %x.\n", dtrEnable);

	ioctl(fd, TIOCMGET, &dtrflags);
  	fprintf(stderr, "dtrFlags are %x.\n", dtrflags);
	sleep(2);
	dtrflags &= ~TIOCM_DTR;
	ioctl(fd, TIOCMSET, &dtrflags);
  	fprintf(stderr, "Setting %x.\n", dtrflags);
	sleep(2);
	ioctl(fd, TIOCMGET, &dtrflags);
  	fprintf(stderr, "dtrFlags are %x.\n", dtrflags);

	return 1;
}

****************************************************************