Information About the Loss of Received Data During Serial Communication

Asked 2 years ago, Updated 2 years ago, 108 views

Currently, the serial communication between PC and PLC is causing a loss of received data.
When I checked the received data in the log on the software, I found that the first 16 Byte was received.
As a countermeasure, we increased the interrupt priority to move the data in the FIFO buffer to the main memory (with a new DWORD 32-bit value added in the registry PriorityControl, setting the target COM port priority to "2").

Reference Site:
Windows RS-232C serial communication is missing received data

Although we have made significant improvements in the above correspondence, we can see that the data received is still missing.
So I have a question.

  • Is there any possibility of problems if the priority is raised to "3" in the above settings?
  • Could you please let me know if there are any other countermeasures?

Thank you for your cooperation.

I will add the following.Thank you for your cooperation.

  • Language C#
  • baurate115200
  • Timeout value 1 second
  • I didn't know the PLC Omron model right away

 //' bubble clear
            try
            {
                Obj.DiscardOutBuffer();// Clearing the Transmit Buffer
                Obj.DiscardInBuffer(); // 'Incoming Buffer Clear
            }
            catch (Exception exp)
            {
                return-1; // '[NG] Transmit/receive buffer clear
            }

             myComStatusParams.Serial.PLC.ReceiveData=";//'ReceiveDataClear

            /// Send FINS commands
             rtn = SerialDataSend (refObj, strCommand);
                 if(rtn==false)
                return-2;

            myComStatusParams.Serial.PLC.TickCount=0;//'Timeout Monitoring Cantor Initialization
            return1;

# receiving program
 ①private voidSerialPortStage_DataReceived (object sender, System.IO.Ports.SerialDataReceivedEventArgse)
        {
            Serial.myComStatusParamsStage.Serial.PLC.ReceiveData+=SerialPortPLC.ReadExisting();
        }
 ②  private voidSerialPortStage_DataReceived (object sender, System.IO.Ports.SerialDataReceivedEventArgse)
        {
            do
            {
                US>//#string StrLDReceiveData=";
                US>string Delimiter="\r\n";

                do
                {
                    // Receive 1 byte at a time (character at a time)
                    StrLDReceiveData+=((char)(SerialPortPLC.ReadChar())).ToString();
                } while(StrLDReceiveData[StrLDReceiveData.Length-1]!=Delimiter[Delimiter.Length-1]);
            } while (SerialPortPLC.BytesToRead!=0);
        }

We checked the occurrence status of the data loss using the method of receiving 、 and の, but the occurrence status did not change in ② and に
(However, the verification of measures to increase interruption priority is not carried out under the method of 2)

[Additional note]
GUI application.
The transmission is running on a dedicated thread.
The event handler received above is on the main thread.

serial-communication

2022-09-30 21:39

1 Answers

There will be no load to cause data loss in the program of the part presented.
This is because the DataReceived handler does not change the situation either way.

If I have to say anything, I am concerned about the following points.

  • Is the "timeout value 1 second" a well-founded number listed in the PLC equipment specification?
  • After clearing the input/output buffer?It seems that you are sending commands, but will this delete the data?In other words, is it guaranteed that there will be no data from the PLC unless the command is sent?
  • Have you sent the following commands before data reception for the previous commands is complete?
  • Is the .NET receive buffer SerialPort.ReadBufferSize Property sufficiently sized, as described in your introduction article?(Is the size greater than or equal to the maximum length of incoming data that may occur?)
  • Is ErrorReceived implemented or not called?
  • If you take the method of の, read the BytesToRead size in one Read rather than ReadChar letter by letter

In addition, please check other parts of the application that are not mentioned in the questionnaire for the following actions:If so, take action to ensure that they do not affect data reception.

  • DataReceived Handler Outputs Data to Screen/File/Database/Server etc.
  • Same as DataReceived handler that handles complex statistics
  • Same DataReceived handler is doing some time-consuming processing in an exclusive state such as Lock
  • The associated heavy load processing is performed by triggering some data accumulation in the same application or other processes on the same PC.

By the way, if possible, it would be better to use the development environment/library/tools provided by the manufacturer than to create a program with C# scratch.
Performance and functionality have been verified, and they should be able to deal with any problems.

Maybe these are related software.
Software-Product Category|Omron Controller

FA Integration Tool Package CX-One
Sysmac Library
Daikanyama 32 (Simple Data Collection Software)


2022-09-30 21:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.