Closed kryskool closed 3 years ago
I had the same issue. Not sure why it is like this. What i did is just putting the read/write into a separte thread. Maybe it's not the best solution but worked out for my case.
Something like this:
def write():
plc.write_by_name('.CC_CODE_VAL', 'OK', pyads.PLCTYPE_STRING)
plc.write_by_name('.CC_TRIG_UP', True, pyads.PLCTYPE_BOOL)
@plc.notification(pyads.PLCTYPE_BOOL)
def callback(handle, name, timestamp, value):
print(
'{1}: received new notification for variable "{0}", value: {2}'
.format(name, timestamp, value)
)
t = Thread(target=write)
t.start()
@kryskool is this still an issue?
Hi @stlehmann
I use a similar hack as @wyda proposal with Thread + Queue module, but with the decorator @plc.notification we cannot use the same connection to write value until we leave the function
I don't know if it's a bug, but with parallel processing it works
Regards
OK so the connection seems to be blocking while a notification callback is processed. I'm not sure what the reason is, though. It could be the ADS DLL blocking or it could be the Python implementation. I think this needs further investigation.
Just had a look at the ADS documentation:
Efficient Usage
- Don't use time intensive executions in callbacks.
- Remind to sync your callback and your mainthread, if you access each other (e.g. critical sections, mutex, events).
It is a bit confusing, though. First point suggests that the calls are blocking. The second points suggests that it is threaded.
@pbruenn do you maybe have any insights how notifications are handled internally by the ADS library?
Do you use TcAdsDll.dll provided by TwinCAT? Or do you use the open source AdsLib? I have no insight into TwinCATs TcAdsDll.dll and the open source library should handle this asynchronously: https://github.com/Beckhoff/ADS/blob/b21b93b79346627adcc99d37163cad709087ed3f/AdsLib/NotificationDispatcher.cpp#L58
I just confirmed this behaviour for a Windows machine which uses the TcAdsDLL.dll provided by TwinCAT. I'll give it a try with the AdsLib also.
@kryskool This issue should be fixed with version 3.2.2. So I'm closing this issue by now. Specifically a bug in adslib led to the timeout. If there are still any troubles feel free to reopen.
@stlehmann
Thanks, can point me the commit that fix this issue ?
Regards,
Yes, it should be this one: 45859d6e9038b55d319efdbda95d3d6eeadd45e3
HI
I try to update variable on a notification, but i received an " ADSError: timeout elapsed (1861)." each time i receive one.
my sample code
With this code
i receive this error code on start
when i put True on CC_ACK_UP
can we change variable value directly on notification callback ?
Regards