Click here to Skip to main content
15,887,421 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Comments
Ron Beyer 13-Oct-13 1:14am    
Why aren't these calculations being done in the PLC? Thats exactly what they are made for... What PLC are you using?
rlarios 13-Oct-13 1:51am    
Thank you for your interest, but my question is not oriented PLC (I apologize for not clarifying my point), my question is oriented as I can do operations when they are conditioned by the time (in my case, milliseconds).

And to answer your question I use a Siemens 1200 normally.Is the PLC is who does the job and my software only get the result.

But, the company is asking me how to do this same project, using other cheaper devices and make program management, calibration, etc. aimed at end users and not technical level personnel.

thank you.
Ron Beyer 13-Oct-13 2:00am    
Unfortunately Windows is not a real-time operating system and its difficult to get the same (or close to the same) time on two different threads. Maybe your answer is doing post-processing instead of trying to get the values while also collecting data. For example, collect the data, save it to a file, then after the collection is complete then compute the data you need.

I work with S7-1200's, S7-1500's and even the 300's quite a bit. The 1200's are cheap and I would say that putting this in the PLC would be more beneficial, spend the time making an easy user interface to the PLC instead of trying to take the PLC out of the equation... Or if you want a really cheap PLC you can use a DL-205.
OriginalGriff 13-Oct-13 3:14am    
I'd suggest this as the solution - there is no good way to do this kind of realtime work on Windows unless you write a device driver, and that's a whole load more work than doing it in the PLC...
rlarios 13-Oct-13 18:21pm    
After several searches and read right through internet I come to that same conclusion, with regard to your comment.

But it leads me to another question, In my company we have a machine that takes "N" number of photographs to PCB cards and the program compares each photograph with a database of images to see if they are correct or not, determines the amount and elevation welding in 3D graphics and returns statistical data with measurements of the last hour of production, all in fractions of seconds.

How this software programmers make it?
What course should I take or what topics I can search the internet to document myself?

Thank you very much for your time, regards.

1 solution

Unfortunately Windows is not a real-time operating system and its difficult to get the same (or close to the same) time on two different threads. Maybe your answer is doing post-processing instead of trying to get the values while also collecting data. For example, collect the data, save it to a file, then after the collection is complete then compute the data you need.

I work with S7-1200's, S7-1500's and even the 300's quite a bit. The 1200's are cheap and I would say that putting this in the PLC would be more beneficial, spend the time making an easy user interface to the PLC instead of trying to take the PLC out of the equation... Or if you want a really cheap PLC you can use a DL-205.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900