版主及各位
在下使用下列编程(想透过RTS控制rs486通讯)控制tiny6410 ttySAC1 的 RTS on 或 off 都没有反应!
不知道是否有那位兄台有使用tiny6410 的 rts.
/*
gcc -o setSerialSignal setSerialSignal.c
*/
#include <sys/ioctl.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
/* we need a termios structure to clear the HUPCL bit */
struct termios tio;
int main(int argc, char *argv[])
{
int fd;
int status;
if (argc != 4)
{
printf("Usage: setSerialSignal port RTS\n");
printf("Usage: setSerialSignal /dev/ttySAC1 0|1\n");
exit( 1 );
}
if ((fd = open(argv[1],O_RDWR)) < 0)
{
printf("Couldn't open %s\n",argv[1]);
exit(1);
}
tcgetattr(fd, &tio); /* get the termio information */
tio.c_cflag &= ~HUPCL; /* clear the HUPCL bit */
tcsetattr(fd, TCSANOW, &tio); /* set the termio information */
ioctl(fd, TIOCMGET, &status); /* get the serial port status */
if ( argv[2][0] == '1' ) /* set the RTS line */
status &= ~TIOCM_RTS;
else
status |= TIOCM_RTS;
ioctl(fd, TIOCMSET, &status); /* set the serial port status */
close(fd); /* close the device file */
}