
复制/* rs232_send.c*/ #include #include #include #include #include #include #include #include #include #defineBAUDRATEB115200//38400 #defineMODEMDEVICE"/dev/ttyS1" int main() { int fd,关于
c=0,res; struct termios oldtio,newtio; intch; static char s1[20],buf[19]; printf("start ...\n"); /*打开PC的COM1口*/ fd = open(MODEMDEVICE,O_RDWR|O_NOCTTY); if (fd { perror(MODEMDEVICE); exit(1); } printf("open...\n"); /*将旧的
高防服务器通讯参数存入oldtio结构*/ tcgetattr(fd,&oldtio); /*初始化新的
亿华云newtio */ bzero(&newtio,sizeof(newtio)); /*8N1*/ newtio.c_cflag = BAUDRATE|CS8|CLOCAL|CREAD; newtio.c_iflag = IGNPAR; newtio.c_oflag = 0; /*正常模式*/ /*newtio.c_lflag = ICANON;*/ /*非正常模式*/ newtio.c_lflag = 0; newtio.c_cc[VTIME] = 0; newtio.c_cc[VMIN] = 10; tcflush(fd,TCIFLUSH); /*新的
香港云服务器temios作为通讯端口参数*/ tcsetattr(fd,TCSANOW,&newtio); printf("writing...\n"); while(1) { res = read(fd,buf,10); res = write(fd,buf,7); if(buf[0]==9) break; } printf("close...\n"); close(fd); /*还原旧参数*/ tcsetattr(fd,TCSANOW,&oldtio); return 0; } 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.