How to achieve the fastest data acquisition?


Recommended Posts

Hi, I have DF reading 6 sensors and a bunch of data via Modbus RTU from a PLC and display and store data on the PC.

DF is doing some calculations all the time and reading about 30 points from another modbus device.

To read from the PLC I used a sequence with priority 0 like this:

while(1)

   try
		 Private.Data = Device.ModbusRTU.ReadHoldingRegistersSSI(2,0,76)
   catch("D")

	   Suction_Pressure_range_SP.AddValue(Private.Data[0][0])
	   Differential_PRessure_Range_SP.AddValue(Private.Data[0][1])
	   Speed_Transmitter_Range_SP.AddValue(Private.Data[0][2])

	   etc...

endwhile

Everything works fine, but recently I was asked to monitor the flow and save all values immediately after it exceeds certain points. To do that I created another sequence with priority 5:

while(1)

   if(Flow[0] >= predetermined_Value)
	  Save_Values()
   endif

   delay()

endwhile

This worked ok on my laptop, but as soon as I put it on the slower field PC it became too slow, like the PC was hanging. So I changed the priority of this save sequence to 3 and 0 and it worked better, but it seems to miss some values.

The question is, is there a more efficient way to constantly monitor a value? How do I know how often is the Modbus sequence updating the data?

Thanks.

Link to comment
Share on other sites

I'm assuming those code snippets are missing some important parts:

1) in the first one, the addvalue() functions are not inside the catch(), right? They certainly should not be, and in fact, they should be before the catch(), because if there is a problem with the read, there is no data to add.

2) in the second sequence, do you have a value inside the delay()? If not, it is the same as delay(0) which basically just yields, which will do next to nothing on simple systems. This is probably why the system hangs. The laptop is probably multi-core, so it just spins on one core and the system doesn't hang, but the field computer is probably single-core and so it hangs the whole machine.

That all said, you don't want separate loops in the first place. You should do your evaluation right in the loop that is acquiring the data, right after the flow.addvalue() command. If you don't want save_values() to slow your acquisition, start it in its own thread: beginseq(save_values).

As for the speed of acquisition, that is determined by your loop speed. If you don't have any delay()'s then it will run as fast as it can. At priority 0, however, it will be delayed by any other computer processing, so I'd run it at 5 instead. Just make sure to add a delay() at least inside the catch() so an error doesn't cause an infinite loop.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.