I'm trying to make a tool where i can poll data from BACnet in a certain interval (e.g. 100ms, 250ms, 500ms, 1s etc.). If I use a while loop with no timer, i get an answer from BACnet every 40-60ms:
import threading
from threading import Timer
from datetime import datetime
import BAC0
ZUL1_T = list()
TIME_T = list()
_rpm = {'address': address,
'objects': {
'analogInput:12':['presentValue'],
'loop:1': ['presentValue'],
}
}
#=============================================================================#
# Main Loop #
#=============================================================================#
if __name__=='__main__':
i = 10
try:
bacnet = BAC0.lite(ip)
except Exception as e:
print(e)
address, device_id = bacnet.whois()[0]
while(i>0):
ZUL1_T.append(bacnet.readMultiple(address, request_dict=_rpm))
TIME_T.append(round(time.time_ns()/1000000))
i-=1
What is the easiest way to make a poll without blocking the entire CPU? The intervals need to be precise (+-10ms) since I need the data for a system identification.