Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous tag reading #17

Open
InofensivoJimmy opened this issue Dec 31, 2021 · 4 comments
Open

Continuous tag reading #17

InofensivoJimmy opened this issue Dec 31, 2021 · 4 comments
Labels
question Further information is requested

Comments

@InofensivoJimmy
Copy link

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/

@kyle-github kyle-github added the question Further information is requested label Dec 31, 2021
@kyle-github
Copy link
Member

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).

@InofensivoJimmy
Copy link
Author

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.

@kyle-github
Copy link
Member

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.

@InofensivoJimmy
Copy link
Author

thanks for the explanation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants