以毫秒为单位执行计算和值转换 [英] Perform calculations and conversion of values ​​in milliseconds

查看:134
本文介绍了以毫秒为单位执行计算和值转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



最近我正在开展一个项目,我必须从PLC接收两个输入信号,第一个信号指示我何时开始阅读连接到串行端口的两个传感器的值(传感器1:SerialPort1;传感器2,SerialPort 2)一旦我得到值,我必须将它们转换为我的客户请求的测量单位。



所以我可以说第一个标志是取初始值,当我收到第二个信号时,我再次取两个传感器的值并再次执行单位转换(我得到最终值)。



一旦得到初始值和最终值,我计算最终值和初始值之间的差值,比较结果是否在我的客户指定的参数范围内。如果可以或不行,我给PLC写了一点来说明我的分析结果。



为了避免PLC发送的信号丢失,我执行读取每个200毫秒的条目(我使用System.Threading.Timer和System.Windows.Forms.Timer,知道哪两个控件有更好的结果),在Timer事件中,我执行前面提到的计算。 />


我的问题是两个信号之间的时间差,时间是0.80秒aprox。,获取串口值并回到单位的转换没有完成两个信号的时间间隔,当我的程序可以确定值和结果时,这些值不再正确。例如:



检验点1 ------初始值

经过时间0.80 ms约

检验要点2 ------最终价值

经过时间1.02秒约

点零点



程序必须确定在第一个检查点施加的力和距离以及在第二个检查点施加的力和距离。



当我的程序得到值时在第一个检测点,发送从PLC到第二个点检查的信号,当我取最终值时,就是零位值。



我的问题是:您可以建议我使用哪种方法,技术或文档,以便在这种情况下实施?



I做了几个测试,我做了一个usercontrol,只获取串口的值并返回转换的值,这是一个线程。我尝试使用System.Threading.Timer而不是winforms.timer。



我希望你能给我任何建议。



非常感谢。



Pd。第一个传感器用于测量力(将串行端口值转换为牛顿),第二个用于找到移动以传递力的距离(mm)。

解决方案

< blockquote>不幸的是,Windows不是一个实时操作系统,很难在两个不同的线程上获得相同(或接近相同)的时间。也许你的答案是进行后期处理,而不是在收集数据时尝试获取值。例如,收集数据,将其保存到文件中,然后在收集完成后再计算所需数据。



我使用S7-1200,S7 -1500甚至300的相当多。 1200是便宜的我会说把它放在PLC中会更有利,花时间为PLC提供一个简单的用户界面,而不是试图让PLC脱离等式...或者如果你真的需要一个便宜的PLC你可以使用DL-205。


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.

解决方案

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.


这篇关于以毫秒为单位执行计算和值转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆