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

Read Tag Optimization #304

Open
Kelton622 opened this issue Nov 7, 2023 · 1 comment
Open

Read Tag Optimization #304

Kelton622 opened this issue Nov 7, 2023 · 1 comment
Labels
question Further information is requested

Comments

@Kelton622
Copy link

Hello,

I'm working on an application that requires a tag value to be updated very frequently. Currently I'm using the following to read the tag, but it still takes about 250 [ms] to read the tag. Are there any ways to improve the read time? Ideally it would be < 50 [ms].

Thanks!

from pycomm3 import LogixDriver
import time

def read_single():
with LogixDriver('192.168.0.20') as plc:
return plc.read('ZoneCount')

st = time.time()
ZoneCount = read_single()
et = time.time()

get the execution time

elapsed_time = et - st
print('Execution time:', elapsed_time, 'seconds')
print(ZoneCount)

@Kelton622 Kelton622 added the question Further information is requested label Nov 7, 2023
@ottowayi
Copy link
Owner

ottowayi commented Nov 8, 2023

In your read_single method, you're creating a new driver every time which has a lot of overhead. When the driver first connects, it uploads the tag list and all of the data types from the controller. This is so that it can optimize the reads based on tag size and allows reading full structures (like UDTs, AOIs, and builtins). You should try creating a single driver instance and reusing it each time, it will probably be much faster that way.

Another optimization would be to read multiple tags at once, since it will be able to use fewer messages by packing them together in a single request. Or if you're reading from an array or UDT/AOI, it can read the whole array/structure at once instead of individual attributes across multiple requests.

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