Hello everyone !
Recently I was working on a project where I had to receive two input signals from a PLC , the first signal indicating when I start reading the values of two sensors that were connected to serial ports ( Sensor 1: SerialPort1 ; Sensor 2 , SerialPort 2 ) once I get the values, I have to convert them to units of measure requested by my client.
So I can say that first sign , is taking Initial values , and when I receive the second signal, I take again the values of both sensors and again performed the conversion of units ( I get the final values ).
Once I get the initial and final values , I calculate the difference between the final value and the initial value and compare if the result is within the parameters specified by my client. If is OK or NOT OK, I wrote a bit to PLC indicating the result of my analysis.
To avoid the loss of a signal sent by the PLC , I perform a reading of each 200miliseconds entries ( I use System.Threading.Timer and System.Windows.Forms.Timer, to know which of the two controls had better results ) and within the Timer event , I perform the calculations I mentioned earlier .
My problem is the time difference between the two signals , the time is 0.80 seconds aprox., getting the serial port values and make back to the conversion of units were not completed in the time interval of the two signals, when my program can determine the values and results, these values are no longer correct. Example:
Inspection point 1 ------ Initial value
elapsed time 0.80 ms Approx
Inspection Point 2 ------ final value
elapsed time 1.02 sec Approx
Point Zero
The program must determine that applied force and distance in the first inspection point and applied force and distance in the second inspection point.
For when my program gets the values of the first inspection point, the signal from the PLC to the second point inspection was sent and when I take the final values are the values of the Position Zero.
My question is: What method, technique or documentation you can suggest me so that I can implement in this situation?
I made several tests, I made a usercontrol that only obtaining the values of the serial ports and returning the value of the conversion, this by a thread. I try to use System.Threading.Timer instead of winforms.timer.
I hope you can give me any suggestions.
Thank you very much.
Pd. The first sensor is to measure the force (conver serial port values to Newtons) and the second is to find the distance (mm) that was shifted to carry the force.