Как исправить потерю данных при последовательной связи?
Hi, everyone. I have a serious problem in my VC++ code of Serial Communcations between PCs. Two PCs are connected 2 serial ports, A PC is sending data via 2 serial ports, B PC is receiving data from A. A PC run sendData.exe with 2 sending threads as sending_thread1, sending_thread2. B PC run recvData.exe with 2 receiving threads as receiving_thread1, receiving_thread2. If sending_thread1 send data to serial port1 then receiving_thread1 receive each data, as do thread2. Under 9600 bps, everything is ok. Each sending and receing data by threads has no problem. But under 115200 bps, almost everytime, there are very confused problem like as follows. 1. Sending threads send data to serial ports at the almost same time, receiving_thread1 has data with no problem. But when receiving_thread2 cannot receive whole body of data from serial port 2 as if some data missing. 2. For example: sending_thread2 send data like STX + Type(char[2]) + Sequence(interger) + Length_of_Data[char[6]) + Data(char[N]) + ETX Data format of receiving_thread2 shows STX + Type(char[1]) + Length_of_data[char[3]) + Data(char[?])..... 3. In receive code, I use polling type style code (read one byte and accumlating) or use EventMask of EV_RXCHAR and WaitCommEvent(), but the results are same. 4. In sending code, I have interval 1 seconds between sending data function of sending_thread, but no effect. 5. The main point of my testings is that under 115200 bps, one of receiving_thread receive loss data packet. In addition, sometimes, the serial commnication using only 1 port show same problem of data loss. Please let me know the cause of this and solutions.... Thank you in advance.
Что я уже пробовал:
1 неделя потрачена впустую на эту проблему.
Patrice T
И у вас есть какой-то код ?
Member 12330615
Я хотел бы знать последний параметр из следующего
Функцию ReadFile(hComm, &ампер;приемник 1, dwBytesTransferred, х); // &ЛТ;--- х
Я предполагаю, что "X = null" означает ожидание данных от последовательного порта.
Но я не знаю значения "X != null" и использования примеров.
Пожалуйста, дайте мне знать цель этого и посоветуйте мне полное использование примера как " X != null"