Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import BAC0, time, random
bacnet = BAC0.lite()
address = '12345:2'
object_type = 'analogValue'
object_instance = '302'
priority = 10 #BACnet priority
value = str(random.randint(66, 122))#random number
# create write statement and run
write_vals = f'{address} {object_type} {object_instance} presentValue {value} - {priority}'
print("Excecuting write_vals statement:", write_vals)
write_result = bacnet.write(write_vals)
print('BACnet written to MSTP device')
print('Wait a few seconds....')
#time.sleep(10)
read_vals = f'{address} {object_type} {object_instance} presentValue'
check = bacnet.read(read_vals)
print(check)
# create write release statement and run
write_rel = f'{address} {object_type} {object_instance} presentValue null - {priority}'
print("Excecuting write_vals statement:", write_rel)
write_result = bacnet.write(write_rel)
print('BACnet written to MSTP device')
print('Wait a few seconds....')
#time.sleep(10)
read_vals2 = f'{address} {object_type} {object_instance} presentValue'
check2 = bacnet.read(read_vals2)
print(check2)
bacnet.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment