BACnet4j readRaw Properties

Hi all,

I am scripting a function to read and write raw to BACnet tags and found the properties have additional hypens in their name which is breaking my use of .forName method to get the property object (IA readRaw doc). I’m trying to avoid storing a conversion list from .getPrettyMap() or scripting to add the hyphen before a capital. Can anyone think of a better way or I am missing something?

# Imports to simplify scripts
from system.bacnet.enumerated import ObjectType
from system.bacnet.enumerated import PropertyIdentifier

def ReadProp(DeviceName, objName='schedule', instance=0, propName='presentValue'):
	"""
		Read unsupported BACnet tag property
		Args:
	   		DeviceName: Ignition gateway device name
	   		objName: BACnet object type (Must match documentation, see IA BACnet docs)
	   		instance: Instance number
	   		propName: Property of instance (Must match property name available, see IA BACnet docs)
	   	Returns:
	   		Property value (Type varies)
	"""
	objTypeId = ObjectType.forName(objName)
	propId = PropertyIdentifier.forName(propName)
	
	return system.bacnet.readRaw(DeviceName, objTypeId, instance, propId)

Here is where this comes unstuck, the import naming doesn’t match the internal object naming for properties because they have multiple words unlike object types.

I.e. to get the Weekly Schedule property of a Schedule object you can either:

PropertyIdentifier.weeklySchedule
PropertyIdentifier.forName('weekly-schedule')

Obviously, calling for PropertyIdentifier.forName('weeklySchedule') doesn’t work.

Any suggestions?

You could pre-process a dictionary (internal to your utility class) that allows lookup by (both) names?

As in:


# Imports to simplify scripts
from system.bacnet.enumerated import ObjectType
from system.bacnet.enumerated import PropertyIdentifier

def __createBiNameMap(bacnetType):
	allNamesToObjects = {}
	
	prettyMap = bacnetType.getPrettyMap()

	for name, obj in bacnetType.getNameMap():
		allNamesToObjects[name] = obj
		prettyName = prettyMap[obj.intValue()]
		allNamesToObjects[prettyName] = obj

	return allNamesToObjects

__objNames = __createBiNameMap(ObjectType)
__piNames = __createBiNameMap(PropertyIdentifier)

def ReadProp(DeviceName, objName='schedule', instance=0, propName='presentValue'):
	"""
		Read unsupported BACnet tag property
		Args:
	   		DeviceName: Ignition gateway device name
	   		objName: BACnet object type (Must match documentation, see IA BACnet docs)
	   		instance: Instance number
	   		propName: Property of instance (Must match property name available, see IA BACnet docs)
	   	Returns:
	   		Property value (Type varies)
	"""
	objTypeId = __objNames[objName]
	if not objTypeId:
		raise ValueError("No such object name %s" % objName)
	propId = __piNames[propName]
	if not propId:
		raise ValueError("No such property name %s" % propName)
	
	return system.bacnet.readRaw(DeviceName, objTypeId, instance, propId)

Thanks Paul, it’s better than my work around. I was using a helper function to add a hyphen between words and then .lower() which isn’t very fault tolerant.

Though unfortunately it still doesn’t seem to find the names as listed in the IA docs. I assume we’ve hit a limitation on the wrapping or similar

Unfortunately I’ve played around a bit and cannot get the import name out (maybe something to do with the Ignition wrapping)

Here’s what PrettyMap and NameMap give you which unfortunately only make use of the underlying names:

PrettyMap (objects):
{"0":"analog-input","1":"analog-output","2":"analog-value","3":"binary-input","4":"binary-output","5":"binary-value","6":"calendar","7":"command","8":"device","9":"event-enrollment","10":"file","11":"group","12":"loop","13":"multi-state-input","14":"multi-state-output","15":"notification-class","16":"program","17":"schedule","18":"averaging","19":"multi-state-value","20":"trend-log","21":"life-safety-point","22":"life-safety-zone","23":"accumulator","24":"pulse-converter","25":"event-log","26":"global-group","27":"trend-log-multiple","28":"load-control","29":"structured-view","30":"access-door","31":"timer","32":"access-credential","33":"access-point","34":"access-rights","35":"access-user","36":"access-zone","37":"credential-data-input","38":"network-security","39":"bitstring-value","40":"characterstring-value","41":"date-pattern-value","42":"date-value","43":"datetime-pattern-value","44":"datetime-value","45":"integer-value","46":"large-analog-value","47":"octetstring-value","48":"positive-integer-value","49":"time-pattern-value","50":"time-value","51":"notification-forwarder","52":"alert-enrollment","53":"channel","54":"lighting-output","55":"binary-lighting-output","56":"network-port","57":"elevator-group","58":"escalator","59":"lift"}

NameMap:
{"load-control":"load-control","notification-forwarder":"notification-forwarder","access-point":"access-point","averaging":"averaging","multi-state-output":"multi-state-output","channel":"channel","large-analog-value":"large-analog-value","program":"program","life-safety-zone":"life-safety-zone","event-enrollment":"event-enrollment","elevator-group":"elevator-group","analog-output":"analog-output","loop":"loop","datetime-value":"datetime-value","group":"group","access-credential":"access-credential","bitstring-value":"bitstring-value","access-user":"access-user","date-pattern-value":"date-pattern-value","notification-class":"notification-class","life-safety-point":"life-safety-point","structured-view":"structured-view","integer-value":"integer-value","network-security":"network-security","binary-lighting-output":"binary-lighting-output","lift":"lift","accumulator":"accumulator","device":"device","access-rights":"access-rights","datetime-pattern-value":"datetime-pattern-value","binary-output":"binary-output","global-group":"global-group","access-zone":"access-zone","positive-integer-value":"positive-integer-value","trend-log-multiple":"trend-log-multiple","timer":"timer","file":"file","network-port":"network-port","analog-value":"analog-value","binary-input":"binary-input","pulse-converter":"pulse-converter","time-pattern-value":"time-pattern-value","lighting-output":"lighting-output","access-door":"access-door","alert-enrollment":"alert-enrollment","characterstring-value":"characterstring-value","event-log":"event-log","calendar":"calendar","multi-state-input":"multi-state-input","date-value":"date-value","escalator":"escalator","multi-state-value":"multi-state-value","credential-data-input":"credential-data-input","octetstring-value":"octetstring-value","command":"command","schedule":"schedule","time-value":"time-value","binary-value":"binary-value","analog-input":"analog-input","trend-log":"trend-log"}

For now I have stuck with my ‘hacky’ work around - a helper function which adds a hyphen before each capital and then .lower() which isn’t very tidy but is functional… until some release in the future.