Home > Back-end >  Windows pulled out in the process of serial port receiving recognition and processing (C/C)
Windows pulled out in the process of serial port receiving recognition and processing (C/C)

Time:10-23

Receive the serial data under Windows, the process of serial port is pulled,
By this time need to attempt reconnection,

Serial port, please disconnect the matter whether can pass ClearCommError GetLastError such API is available?

CodePudding user response:

The landlord may have a look this reply,
https://bbs.csdn.net/topics/392297287
reference snail lay sleeping reply: 3/f
write I have a practice

A serial port 10 ms read data at a time,

If the data is read failure and GetLastError () returns a value to ERROR_SUCCESS and ERROR_IO_PENDING, error count + 1,
When the error count for more than 20, set up a serial port for the off state,
If the error count is less than 20 and read data success, eliminate error count,


If it is a usb related, can consider to handle WM_DEVICECHANGE

CodePudding user response:

reference 1st floor light bamboo hat reply:
the building may have a look this reply,
https://bbs.csdn.net/topics/392297287
Quote: refer to the third floor lay sleeping snail reply:

Write down I have a practice

A serial port 10 ms read data at a time,

If the data is read failure and GetLastError () returns a value to ERROR_SUCCESS and ERROR_IO_PENDING, error count + 1,
When the error count for more than 20, set up a serial port for the off state,
If the error count is less than 20 and read data success, eliminate error count,


If it is a usb related, can consider to handle WM_DEVICECHANGE


Thank you, but it seems to be the default does not exist it took a long time to receive a data? If only after more than ten minutes to a data, actual did not break line, also as the disconnect?

CodePudding user response:

refer to the second floor scitachi response:
Quote: refer to 1st floor light bamboo hat reply:

The landlord may have a look this reply,
https://bbs.csdn.net/topics/392297287
Quote: refer to the third floor lay sleeping snail reply:

Write down I have a practice

A serial port 10 ms read data at a time,

If the data is read failure and GetLastError () returns a value to ERROR_SUCCESS and ERROR_IO_PENDING, error count + 1,
When the error count for more than 20, set up a serial port for the off state,
If the error count is less than 20 and read data success, eliminate error count,


If it is a usb related, can consider to handle WM_DEVICECHANGE


Thank you, but it seems to be the default does not exist it took a long time to receive a data? If only after more than ten minutes to a data, actual did not break line, also as the disconnect?


Sorry, seems a little bit misunderstanding, if disconnected, the data in the input buffer is normal? With ClearCommError how many data can't attend it?
  • Related