Continuous tag reading
Opened this issue · 4 comments
To continuously display the value of some tags, I use the following instruction:
tag2.Read(TIMEOUT)
tag3.Read(TIMEOUT)
tag4.Read(TIMEOUT
val2 = tag2.GetInt32(0)
LabelTAG_INT.Text = val2
val3 = tag3.GetFloat32(0)
LabelTAG_REAL.Text = NumberFormat(val3,0,1)
val4 = tag4.GetString(0)
LabelTAG_STRING.Text = val4
instructions that repeat within a loop, it works fine, but is this the correct way?
make constant read calls, affect the performance of the computer?
the language is B4X, and it is a wrapper for this platform, but it is still in testing. Thank you
https://www.b4x.com/
I looked briefly at B4X. Seems nice, but it is commercial. If you are working on a new wrapper, I would suggest wrapping the C library directly.
The way that you are calling each tag with a timeout will serialize the tag access and prevent the library from getting good performance.
For the best performance, you should start reading in asynchronous mode. You do that by calling read, but with a timeout of zero. The C library will start reading in the background. You can either set up a callback function or check the status of the tag to tell when the read is done. The status will be PLCTAG_STATUS_PENDING while the read is happening and will change to PLCTAG_STATUS_OK when it is done. If it changes to anything else, an error occurred. The example program async.c shows how to do this (in C, so hopefully you can translate that to your language).
Something like this?
Private Sub bucle
Do While working
rc=tag4.Read(0)
If Not(rc=tag4.PLCTAG_STATUS_OK) Then
' Log ("Unable to create the tag")
Else
' Log("Tag created")
End If
val4 = tag4.GetString(0)
LabelTAG_STRING.Text = val4
Sleep(50)
Loop
End Sub
it works really well, I was just wondering if reading the status of many tags constantly affects the performance of the device.
Reading status does not impact performance. Only read() and write() go to the PLC. Inside the library these are asynchronous operations. If you have a timeout, then the library waits at least that long for the operation to complete. If you have no timeout then the library will start the operation and you can wait for it to complete by checking the status. Internally, the library will check for a response from the PLC.
The PLC cannot handle a very high rate of network packets. But, it can handle many requests per packet. So the best performance is to use asynchronous mode and trigger many reads/writes at once, then wait for them to complete.
thanks for the explanation