You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am experimenting with the python library asyncua. The program is communicating with an OPC server that is running on the same PC. the main_client() is reading one value, and printing another value. All of this is working as expected. I also added a function called tankFunction. That is just ramping up and down from 0 to 4 and down again (simulating filling and emptying a tank).
My issue is that I have to control the scan time of the function. I need to be able to get the tankFunction to run for example every second with some degree of precision. When I'm running this script it takes about 2 seconds between doing something, and I dont know where or how to manipulate that. If anybody knows where this is explained or could point me in the right direction it would be much appreciated!
Here is the code.
asyncdefmain_client():
print(f"Connecting to {url} ...")
asyncwithClient(url=url) asclient:
#EXAMPLE OF READING VALUE#node = client.get_node("ns=4;s=|var|CODESYS Control Win V3 x64.Application.GVL_Modbus.Mb_Tank01_ManualDensity")#var = await node.get_value()#print(var)node2=client.get_node("ns=4;s=|var|CODESYS Control Win V3 x64.Application.GVL_Simulation.A02_CH0")
awaitnode2.write_value(tankFunction(1,2,3), ua.UInt16)
now=dt.datetime.now()
whileTrue:
asyncio.run(main_client())
tankFunction(123) is just a function that calculates a UInt16 Value.
What is read in the terminal is this:
Connecting to opc.tcp://localhost:4840 ...
0 09:37:54.791759 0.25 Connecting to opc.tcp://localhost:4840 ...
0 09:37:56.913719 0.5 Connecting to opc.tcp://localhost:4840 ...
0 09:37:59.039703 0.75
The time between some of the scans are 2.122s, 2.126s, 2.121s, 2.126s.
I have experimented with asyncio.sleep() and tried reading the documentation in https://github.com/FreeOpcUa/opcua-asyncio/tree/master but I didnt understand how to solve this problem. I believe that my understanding of how asyncio is working is lacking.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am experimenting with the python library asyncua. The program is communicating with an OPC server that is running on the same PC. the main_client() is reading one value, and printing another value. All of this is working as expected. I also added a function called tankFunction. That is just ramping up and down from 0 to 4 and down again (simulating filling and emptying a tank).
My issue is that I have to control the scan time of the function. I need to be able to get the tankFunction to run for example every second with some degree of precision. When I'm running this script it takes about 2 seconds between doing something, and I dont know where or how to manipulate that. If anybody knows where this is explained or could point me in the right direction it would be much appreciated!
Here is the code.
tankFunction(123) is just a function that calculates a UInt16 Value.
What is read in the terminal is this:
Connecting to opc.tcp://localhost:4840 ...
0 09:37:54.791759 0.25 Connecting to opc.tcp://localhost:4840 ...
0 09:37:56.913719 0.5 Connecting to opc.tcp://localhost:4840 ...
0 09:37:59.039703 0.75
The time between some of the scans are 2.122s, 2.126s, 2.121s, 2.126s.
I have experimented with asyncio.sleep() and tried reading the documentation in https://github.com/FreeOpcUa/opcua-asyncio/tree/master but I didnt understand how to solve this problem. I believe that my understanding of how asyncio is working is lacking.
Beta Was this translation helpful? Give feedback.
All reactions