1. Problem description
In the process of serial communication written with MSComm control, when receiving the data sent by the serial port under the message response function OnComm function, in get_ An error reading comm develop error occurs in the input() function. The specific codes are as follows:
void XXXDlg::OnCommMscommLaser()
{
memset(chstrLaser, 0, 1024); //chstrLaseris a global variable.
short i = m_mscomLaser.get_InBufferCount(); // statement 1.
if(m_mscomLaser.get_CommEvent() == 2) // An event value of 2 means there are characters in the receive buffer.
{
/*m_recivedMsg = "";
CString csstr = "";*/
VARIANT InputData = m_mscomLaser.get_Input(); //Statement 2, read buffer.
COleSafeArray csa = InputData; //VARIANT variable is converted to COleSafeArray variable.
//translate to byte class.
DWORD size = csa.GetOneDimSize();
for(long k = 0; k < size; k++)
csa.GetElement(&k, chstrLaser + k);
}
// Further processing of the received data ......
return;
}
Each time the function is triggered, the data length of the receive buffer obtained by statement 1 is 30, which means that the receive buffer has data with a length of 30. However, the above error prompt will appear in statement 2, and the code after statement 2 will not be executed.
2.Method exploration
1. At first, I thought it was a data line problem. By changing the data line and making the data line myself, the problem could not be solved.
2. I suspected that there was a problem with the communication equipment. I also changed the equipment for debugging, but the same problem still occurred.
3. Suspected that the communication protocol was not clear.
4. Wait
3. Solution
After many serial port debugging assistants failed, I found that a serial port debugging assistant can communicate normally. I will provide the debugging assistant later. The current problem may be that the code is written incorrectly, and the data cable and equipment are OK.
Through a large number of searches, I found that one solution was to update the serial driver. After trying, I found that it was really possible. After a whole day, I finally solved this problem. I was very excited.
Here is the solution:
1. Download serial driver
My is a USB to 232 data cable, so I downloaded the prolific USB to serial comm port driver. You can download the corresponding driver according to your actual situation. Here I provide the driver that solves my problem: Click to download the serial port driver.
2. Update driver
After downloading the driver, start updating the driver:
a. Click Manage – > Click device manager -> Locate the serial port configured through the MSComm control
b. Right click the serial driver and click Update Driver Software – > Select browse computer for driver software
c. Click Browse to find the downloaded serial driver
d. Click next to solve the above problems after updating.
Read More:
- Two Way Communication Error: Function two_way_comm_post_message / two_way_comm_post_message_ex faile
- [Solved] Raspberry Pi Error: AttributeError: module ‘serial‘ has no attribute ‘Serial‘
- [Solved] UE4 Error: Serial loading Unknown structure
- [Solved] NO ST-LINK detected/ST-LINK USB communication error
- [Solved] Keil Error: ST-LINK USB communication error
- Audit reported an error: “the device settings could not be applied because of the following error: Mme device internal error“
- [Solved] Android Networking error: CLEARTEXT communication to www.xxxxx.xyz not permitted by network security policy
- TensorFlow-gpu Error: failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
- [Solved] Bringing up interface eth0: Error: No suitable device found: no device found for connection ‘System eth0’.
- [Solved] Job for docker.service failed because the control process exited with error
- [Solved] Vs error: link: fatal error lnk1168: unable to open for writing
- [Solved] Tensorflow/Keras Error reading weights: ValueError: axes don‘t match array
- Angular Error: No value accessor for form control with name ‘xxx’
- [Solved] Go Get Download Dependency Error: is not using a known version control system
- [Solved] Runtimeerror: CUDA error: device side assert triggered
- [Solved] Job for mysqld.service failed because the control process exited with error code.
- [Solved] Failed to allocate graph: MYRIAD device is not opened.
- [Solved] “errmsg” : “Got invalid BSON from external server while reading from cursor
- [Solved] failed (13: Permission denied) while reading upstream
- [Solved] Postgres Start Error: Job for postgresql.service failed because the control process exited with error code.