I'm trying to create a tool, where you can log data from a specific BACnet object, by using BAC0: https://bac0.readthedocs.io/en/latest/
https://buildmedia.readthedocs.org/media/pdf/bac0/latest/bac0.pdf
I'm currently failing to implement a precise timer, to log the data in the wanted time intervals(e.g. 100ms, 200ms, 500ms, 1000ms). When running the following code:
#=============================================================================#
# Main Loop #
#=============================================================================#
if __name__=='__main__':
i = 16
try:
bacnet = BAC0.lite(ip)
except Exception as e:
print(e)
try:
address, device_id = bacnet.whois('103061 103061')[0]
except Exception as e:
print(e)
while(i>0):
ZUL1_T.append(bacnet.readMultiple(ip, request_dict=_rpm))
TIME_T.append(time.time_ns())
i-=1
with open('zzz.csv', 'w') as file:
writer = csv.writer(file)
zeilen = []
writer.writerow(ZUL1_T)
writer.writerow(TIME_T)
I get the answers to the requests in the following time intervals:
65ms 58ms 63ms 65ms 64ms 60ms 69ms 58ms 62ms 65ms 47ms 67ms 63ms 61ms 61ms
So I added time.sleep(0.1) at the end of the while loop and expected the time intervals all to be around 160ms. But when i started the programm, I got the following time intervalls between to requests:
774ms 362ms 838ms 1015ms 299ms 281ms 160ms 1052ms 167ms 499ms 628ms 200ms 249ms 392ms 652ms
For me, these time intervalls appear to be completely arbitrary. Has anyone an idea why that is or how I could implement a better solution?
I now found out that it works perfectly fine on a Linux computer, so the problem seems to be my Windows os. Is there a way to still run it on Windows, e.g giving more CPU capacity to Visual Studio Code or similar?