//使用open函数打开串口,获得串口设备文件的文件描述符
if((fd=open(\ {
perror(\ return 1; }
tcgetattr(fd, &opt);
cfsetispeed(&opt,B115200 ); // 指定输入波特率,9600bps
cfsetospeed(&opt,B115200); //指定输出波特率,9600bps
opt.c_cflag&=~CSIZE;
//将数据位修改为8bit
opt.c_cflag |=CS8;
opt.c_cflag |=CBAUD;
// 无校验
opt.c_cflag &= ~PARENB;
opt.c_cflag |= IXON|IXOFF|IXANY; // 软件数据流控制 //
opt.c_cflag |= CRTSCTS; // 硬件数据流控制 //
opt.c_cflag &=
~CRTSCTS; // 不使用数据流控制
tcsetattr(fd, TCSANOW , &opt); int status;
ioctl(fd,
TIOCMGET, &status);
printf(\
// status &=
~TIOCM_RTS; // RTS 引脚高电平
status |= TIOCM_RTS; // RTS 引脚低电平
printf(\
ioctl(fd,
TIOCMSET, &status);
ioctl(fd,
TIOCMGET, &status);
printf(\
while(1) {
printf(\ cmd = getchar(); switch(cmd) {
case 'w':
printf(\