Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
读取连续0xFF数据时Linux termios函数数据损坏_Linux_Serial Port_Termios_Data Corruption - Fatal编程技术网

读取连续0xFF数据时Linux termios函数数据损坏

读取连续0xFF数据时Linux termios函数数据损坏,linux,serial-port,termios,data-corruption,Linux,Serial Port,Termios,Data Corruption,我为串行端口ttyS4编写了一个程序,它使用termios函数。 该程序使用非规范模式。 我可以发送十六进制数据,也可以读取十六进制数据。 我的问题是,当我读取数据时,收到了多个0xFF字节,此时我的串行端口缓冲区以垃圾形式填充了0xFF字节。 例子 我的传输数据是 01 23 73 00 03 7b 29 00 03 86 9c 00 03 61 73 00 00 03 5b 00 00 03 63 00 00 02 d6 00 00 00 00 00 00 c3 70 00 00 03 e8

我为串行端口ttyS4编写了一个程序,它使用termios函数。 该程序使用非规范模式。 我可以发送十六进制数据,也可以读取十六进制数据。 我的问题是,当我读取数据时,收到了多个0xFF字节,此时我的串行端口缓冲区以垃圾形式填充了0xFF字节。 例子 我的传输数据是

01 23 73 00 03 7b 29 00 03 86 9c 00 03 61 73 00 00 03 5b 00 00 03 63 00 00 02 d6 00 00 00 00 00 00 c3 70 00 00 03 e8 00 00 03 e8 00 00 03 e8 00 00 03 e8 00 00 02 2c ff ff ff fc 00 00 02 2c 00 00 72 89 00 00 00 00 00 00 00 93 00 00 72 9d 0b 35 33 0d 06 11 00 05 00 08 00 00 2a d9 00 00 28 22 00 16 00 01 00 05 00 ab 82 40 00 ab a9 50 01 01 01 00 00 00 1f 9b 71
但我收到的实际数据如下

01 23 73 00 03 7b 29 00 03 86 9c 00 03 61 73 00 00 03 5b 00 00 03 63 00 00 02 d6 00 00 00 00 00 00 c3 70 00 00 03 e8 00 00 03 e8 00 00 03 e8 00 00 03 e8 00 00 02 2c ff ff ff ff ff ff fc 00 00 02 2c 00 00 72 89 00 00 00 00 00 00 00 93 00 00 72 9d 0b 35 33 0d 06 11 00 05 00 08 00 00 2a d9 00 00 28 22 00 16 00 01 00 05 00 ab 82 40 00 ab a9 50 01 01 01 00 00 00 1f 9b 71
收到额外的3个0xFF(垃圾)。 当接收到多字节
0xFF
时,会出现此问题

进行以下配置以配置端口

///////////////////////////////////////////////////////
fd = open("/dev/ttyS4",O_RDWR | O_NOCTTY| O_SYNC);

struct termios SerialPortSettings;

cfsetispeed(&SerialPortSettings,B9600);  // 9600 baud rate

SerialPortSettings.c_cflag &= ~PARENB;   // No Parity}

SerialPortSettings.c_cflag &= ~CSTOPB; //Stop bits = 1 

SerialPortSettings.c_cflag &= ~CSIZE; /* Clears the Mask*/

SerialPortSettings.c_cflag |=  CS8;   /* Set the data bits = 8 */

SerialPortSettings.c_cflag &= ~CRTSCTS; //Turn off hardware based flow control

SerialPortSettings.c_cflag |= CREAD | CLOCAL;//Turn on the receiver of the serial port (CREAD)

SerialPortSettings.c_iflag &= ~IGNBRK;

SerialPortSettings.c_iflag |=  BRKINT;

SerialPortSettings.c_iflag &= ~ISTRIP;

SerialPortSettings.c_iflag &= ~(IXON | IXOFF | IXANY); //Turn off software based flow control (XON/XOFF).

SerialPortSettings.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG );//Setting the mode of operation,the default mode of operation of serial port in Linux is the Non - Cannonical mode

SerialPortSettings.c_iflag &= ~(INLCR | ICRNL );

SerialPortSettings.c_cc[VMIN]  = 0;

SerialPortSettings.c_cc[VTIME] = 100;

tcflush(fd, TCIOFLUSH);

tcsetattr(fd,TCSANOW,&SerialPortSettings);

///////////////////////////////////////////////////////////////

请任何人建议如何解决此问题。

寻求调试帮助的问题必须包括在问题本身中重现该问题所需的最短代码(即写和读代码)。您如何验证传输的数据是否正确?您是否尝试过使用已知的工作程序读取该数据?您的初始化代码已损坏。termios结构未正确初始化;没有调用tcgetattr()。您的标题严重夸大了症状。“数据损坏”看起来更像是重复或重复。“连续0xFF数据”仅由三个字符变为六个字符。