Linux からシリアル RS232 で Windows にデータ バイトを送信していますが、すべて問題ありません。Linux からの 0xa 送信を処理する必要があるだけです。Windows は 0xd + 0xa として読み取るためです。しかし、WindowsからLinuxにデータバイトを送信しているとき、いくつかのバイトが次のように置き換えられます-Windows送信-0xd Linux受信0xa Windows送信-0x11 Linux受信ガベージタイテ値を整数で8200
Windows から Linux にデータを送信するときに何が問題になるかを説明してください。前もって感謝します
Windows シリアル ポートの初期化
char *pcCommPort = "COM1";
hCom = CreateFile( TEXT("COM1"),
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);
fSuccess = GetCommState(hCom, &dcb);
FillMemory(&dcb, sizeof(dcb),0);
dcb.DCBlength = sizeof(dcb);
dcb.BaudRate = CBR_115200; // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit
dcb.fOutxCtsFlow = false;
fSuccess = SetCommState(hCom, &dcb);
buff_success = SetupComm(hCom, 1024, 1024);
COMMTIMEOUTS cmt;
// ReadIntervalTimeout in ms
cmt.ReadIntervalTimeout = 1000;
cmt.ReadTotalTimeoutMultiplier = 1000;
cmt.ReadTotalTimeoutConstant=1000;
timeout_flag = SetCommTimeouts(hCom, &cmt);
Windows書き込みシリアル-
WriteFile(hCom, buffer, len, &write, NULL);
Linux シリアル初期化 -
_fd_port_no = open("//dev//ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
tcgetattr(_fd_port_no, &options);
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
options.c_cflag |= (CS8);
options.c_cflag|=(CLOCAL|CREAD);
options.c_cflag &=~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_iflag |= (IXON | IXOFF | IXANY);
options.c_cflag &= ~ CRTSCTS;
tcsetattr(_fd_port_no, TCSANOW, &options);
シリアルLinuxを読む-
while(read(_fd_port_no,buffer+_buffer_len,sizeof(buffer))>0)
{
_buffer_len = _buffer_len+sizeof(buffer);
}
はい、Linux から Windows に伝えたように、NL/CR の問題のみが検出されましたが、バイト置換で解決しましたが、Windows から Linux に送信される serila データについて何か考えがありますか (バイト置換ポリシー)。実際には、200 KB のファイルを 200 バイトのブロックでシリアル経由で送信する必要があるため、Windows から Linux に送信する場合にどのバイトを置き換えることができるか