在网上修改了串口通信的代码,编译正确,打开串口和参数设置都是正确的,但是就是在发送数据的时候出现问题,板子发送的数据PC收不到,PC发送的数据板子也收不到,不知道是什么原因,详情各位大哥看看~~~
附上我的主要代码:
/***@brief 设置串口通信速率 *@param fd 类型 int 打开串口的文件句柄 *@param speed 类型 int 串口速度 *@return void*/ int speed_arr[] = { B38400, B19200, B9600, B4800, B2400, B1200, B300, B38400, B19200, B9600, B4800, B2400, B1200, B300, }; int name_arr[] = {38400, 19200, 9600, 4800, 2400, 1200, 300, 38400, 19200, 9600, 4800, 2400, 1200, 300, }; void set_speed(int fd, int speed) { int i; int status; struct termios Opt; tcgetattr(fd, &Opt); for(i= 0;i<sizeof(speed_arr)/sizeof(int);i++) { if(speed == name_arr[i]) { tcflush(fd, TCIOFLUSH); cfsetispeed(&Opt, speed_arr[i]); cfsetospeed(&Opt, speed_arr[i]); status = tcsetattr(fd, TCSANOW, &Opt); if(status != 0) perror("tcsetattr fd1"); return; } &n
[1] [2] [3] [4] [5] [6] [7] [8] [9] 下一页