Closed trapperl closed 4 months ago
So I've made this ultimate bapypes3 tester script via the bacpypes console:
https://gist.github.com/bbartling/24d4fa106281a63e7b6a77a2f40fe183
And have played around with some scripts outside of the bacpypes3 console. At least in the console I think you want something like a > write 32:18 analog-output,2 present-value null 10
In a script form you just want pass in a string like "null"
...
Hopefully these code snips help but the important part is the:
if priority is None:
raise ValueError(" null only for overrides")
value = Null(())
That is inside the write method:
from bacpypes3.primitivedata import Null
async def do_write_property_task(
self,
device_address,
object_identifier,
property_identifier,
value,
priority=BACNET_WRITE_PRIORITY,
):
if _debug:
logging.info(" device_address: %r", device_address)
logging.info(" object_identifier: %r", object_identifier)
# Use the parse_property_identifier method to split the property identifier and its index
property_identifier, property_array_index = self.parse_property_identifier(
property_identifier
)
if _debug:
logging.info(" property_array_index: %r", property_array_index)
# Check the priority
if priority:
priority = int(priority)
if (priority < 1) or (priority > 16):
raise ValueError(f"priority: {priority}")
if _debug:
logging.info(" priority: %r", priority)
if _debug:
logging.info(" value: %r", value)
if _debug:
logging.debug(
"do_write %r %r %r %r %r",
device_address,
object_identifier,
property_identifier,
value,
priority,
)
if value == "null":
if priority is None:
raise ValueError(" null only for overrides")
value = Null(())
try:
response = await self.app.write_property(
device_address,
object_identifier,
property_identifier,
value,
property_array_index,
priority,
)
if _debug:
logging.info(" response: %r", response)
if _debug:
logging.info(" Write property successful")
except ErrorRejectAbortNack as err:
if _debug:
logging.info(" - exception: %r", err)
else:
logging.error(" Write property failed: ", err)
async def do_release_all_hvac(self):
logging.info(" Releasing all HVAC!")
write_requests = [
(
TRANE_ADDRESS,
TRANE_TEMP_SETPOINT_READ_WRITE_POINT,
BACNET_PRESENT_VALUE_PROP_IDENTIFIER,
"null",
),
(
TRANE_ADDRESS,
TRANE_AIR_FLOW_STP_WRITE_POINT,
BACNET_PRESENT_VALUE_PROP_IDENTIFIER,
"null",
),
(
TRANE_ADDRESS,
TRANE_COOL_VALVE_WRITE_POINT,
BACNET_PRESENT_VALUE_PROP_IDENTIFIER,
"null",
),
]
for request in write_requests:
try:
# Destructure the request into its components
address, object_id, prop_id, value = request
# Perform the BACnet write property operation
await self.do_write_property_task(address, object_id, prop_id, value)
logging.info(f" Write successful for {object_id}")
except Exception as e:
logging.error(f" An unexpected error occurred on WRITE REQUEST: {e}")
Thanks for your help.
I can't believe I just needed to change Null() into Null(())
I've been working on a BACnet project and have had a lot of luck reading a writing.
However I've hit a roadblock trying to write 'null' so that the values are cleared out of the priority array.
To simplify things, I went back to the write-property-console.py
https://github.com/JoelBender/BACpypes3/blob/main/samples/write-property-console.py
It can't pass a string as a float when I do this, which makes sense:
write 10.102.14.100 analogOutput:0 presentValue null 8
When I see if the value is null and try to pass Null()
if value.lower() == 'null': value = Null()
I get a type error.
write error: | Error type : <class 'TypeError'>
I assume the problem is something I don't know and am having trouble finding.
Any help would be appreciated.