|
#include <sys/ioctl.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <string.h>
#include <sys/types.h>
#include "math.h"
int main(int argc,char* argv)
{
struct termios newTermios,oldTermios;
char* serial_port="/dev/tq2440_serial0";
int fd = open(serial_port,O_RDWR,0);
unsigned char str[6];
memset(str,0,6);
char result[256];
int i = 0;
if(fd <0 )
{
printf("cant't open tq2440_serial0\n");
return -1;
}
tcgetattr(fd,&oldTermios);
tcflush(fd,TCIOFLUSH);
memcpy(&newTermios,&oldTermios,sizeof(struct termios));
cfsetispeed(&newTermios,B9600);
cfsetospeed(&newTermios,B9600);
if(fcntl(fd,F_SETFL,O_NONBLOCK) < 0)
{
printf(" fcntl failed");
}
// memcpy(&newTermios,&oldTermios,sizeof(struct termios));
newTermios.c_cflag |= (CLOCAL|CREAD);
newTermios.c_cflag &=~CSIZE;
newTermios.c_cflag |= CS8;
newTermios.c_cflag &= ~PARENB;
newTermios.c_iflag &= ~INPCK;
newTermios.c_cflag &= ~CSTOPB;
newTermios.c_cc[VTIME] = 0;
newTermios.c_cc[VMIN] = 0;
newTermios.c_iflag |= IGNPAR|ICRNL;
newTermios.c_oflag |= OPOST;
newTermios.c_iflag &= ~(IXON|IXOFF|IXANY);
newTermios.c_lflag &= ~(ICANON | ECHO | ECHOE |ISIG);
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &newTermios);
unsigned int controll;
unsigned int RTS;
RTS = TIOCM_RTS;
unsigned int CTS;
CTS = TIOCM_CTS;
while(1){
if(ioctl(fd,TIOCMBIS,&RTS) == 0 )
{
printf("RTS set success!\n");
}
if(ioctl(fd,TIOCMBIS,&CTS)== 0)
{
printf("CTS set success!\n");
}
ioctl(fd,TIOCMGET,&controll);
printf("%x\n",controll);
}
return 0;
}
用IOCTL函数也能正确返回,但是RTS和CTS引脚测量根本没有变化?这是什么情况 |
|