def __init__(self, **kwargs): if _debug: RandomAnalogValueObject._debug("__init__ %r", kwargs) AnalogValueObject.__init__(self, **kwargs) # if a value hasn't already been provided, initialize with a random one if 'presentValue' not in kwargs: self.presentValue = random.random() * 100.0
def __init__(self, **kwargs): if _debug: SampleAnalogValueObject._debug("__init__ %r", kwargs) AnalogValueObject.__init__(self, **kwargs) # add a callback when the object name has changed self._property_monitors["objectName"].append(self.object_name_changed)
def __init__(self, index: int, name: str, value: float = 0): kwargs = dict( objectIdentifier=("analogValue", index), objectName=name, presentValue=value, statusFlags=[0, 0, 0, 0], ) if _debug: _AnalogValueObject._debug("__init__ %r", kwargs) AnalogValueObject.__init__(self, **kwargs)
def test_8_10_3(self): """Canceling a Subscription""" if _debug: TestAnalogValue._debug("test_8_10_3") # create a network anet = ApplicationNetwork("test_8_10_3") # add the ability to accept COV notifications to the TD anet.td.add_capability(COVTestClientServices) # tell the TD how to respond to confirmed notifications anet.td.test_ack = True anet.td.test_reject = None anet.td.test_abort = None # add the service capability to the IUT anet.iut.add_capability(ChangeOfValueServices) # make an analog value object test_av = AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='av', presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=10.0, ) # add it to the implementation anet.iut.add_object(test_av) # wait for the subscription, then for the cancelation anet.iut.start_state.doc("8.10.3-1-0") \ .receive(SubscribeCOVRequest).doc("8.10.3-1-1") \ .receive(SubscribeCOVRequest).doc("8.10.3-1-2") \ .success() # send the subscription, wait for the ack, then send the cancelation # and wait for the ack. Ignore the notification that is sent when # after the subscription anet.td.start_state.doc("8.10.3-2-0") \ .send(SubscribeCOVRequest( destination=anet.iut.address, subscriberProcessIdentifier=1, monitoredObjectIdentifier=('analogValue', 1), issueConfirmedNotifications=False, lifetime=30, )).doc("8.10.3-2-1") \ .ignore(UnconfirmedCOVNotificationRequest) \ .receive(SimpleAckPDU).doc("8.10.3-2-2") \ .send(SubscribeCOVRequest( destination=anet.iut.address, subscriberProcessIdentifier=1, monitoredObjectIdentifier=('analogValue', 1), )).doc("8.10.3-2-1") \ .ignore(UnconfirmedCOVNotificationRequest) \ .receive(SimpleAckPDU).doc("8.10.3-2-2") \ .success() # run the group anet.run()
def test_simple_transition_unconfirmed(self): if _debug: TestAnalogValue._debug("test_simple_transition_unconfirmed") # create a network anet = ApplicationNetwork("test_simple_transition_unconfirmed") # add the ability to accept COV notifications to the TD anet.td.add_capability(COVTestClientServices) # tell the TD how to respond to confirmed notifications anet.td.test_ack = True anet.td.test_reject = None anet.td.test_abort = None # add the service capability to the IUT anet.iut.add_capability(ChangeOfValueServices) # make an analog value object test_av = AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='av', presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=10.0, ) # an easy way to change the present value write_test_av = lambda v: setattr(test_av, 'presentValue', v) # add it to the implementation anet.iut.add_object(test_av) # receive the subscription request, wait until the client has # received the ack and the 'instant' notification. Then change the # value, no ack coming back anet.iut.start_state.doc("3-1-0") \ .receive(SubscribeCOVRequest).doc("3-1-1") \ .wait_event("e1").doc("3-1-2") \ .call(write_test_av, 100.0).doc("3-1-3") \ .timeout(10).doc("3-2-4") \ .success() # test device is quiet anet.td.start_state.doc("3-2-0") \ .send(SubscribeCOVRequest( destination=anet.iut.address, subscriberProcessIdentifier=1, monitoredObjectIdentifier=('analogValue', 1), issueConfirmedNotifications=False, lifetime=30, )).doc("3-2-1") \ .receive(SimpleAckPDU).doc("3-2-2") \ .receive(UnconfirmedCOVNotificationRequest).doc("3-2-3") \ .set_event("e1").doc("3-2-4") \ .receive(UnconfirmedCOVNotificationRequest).doc("3-2-5") \ .timeout(10).doc("3-2-6") \ .success() # run the group anet.run()
def create_AV(oid=1, pv=0, name='AV', units=None): avo = AnalogValueObject( objectIdentifier=('analogValue', oid), objectName=name, presentValue=pv, units=units, ) return avo
def main(): global test_av, test_bv, test_application # make a parser parser = ConfigArgumentParser(description=__doc__) # parse the command line arguments args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject(ini=args.ini) if _debug: _log.debug(" - this_device: %r", this_device) # make a sample application test_application = SampleApplication(this_device, args.ini.address) # make an analog value object test_av = AnalogValueObject( objectIdentifier=("analogValue", 1), objectName="av", presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=1.0, ) _log.debug(" - test_av: %r", test_av) # add it to the device test_application.add_object(test_av) _log.debug(" - object list: %r", this_device.objectList) # make a binary value object test_bv = BinaryValueObject( objectIdentifier=("binaryValue", 1), objectName="bv", presentValue="inactive", statusFlags=[0, 0, 0, 0], ) _log.debug(" - test_bv: %r", test_bv) # add it to the device test_application.add_object(test_bv) # binary value task do_something_task = DoSomething(INTERVAL) do_something_task.install_task() _log.debug("running") run() _log.debug("fini")
def create_AV(oid=1, pv=0, name="AV", units=None, pv_writable=False): avo = AnalogValueObject( objectIdentifier=("analogValue", oid), objectName=name, presentValue=pv, units=units, relinquishDefault=0, ) avo = _make_mutable(avo, mutable=pv_writable) avo = _make_mutable(avo, identifier="relinquishDefault", mutable=pv_writable) return avo
def create_AV(oid=1, pv=0, name="AV", units=None, pv_writable=False): avo = AnalogValueObject( objectIdentifier=("analogValue", oid), objectName=name, presentValue=pv, units=units, relinquishDefault=0, priorityArray=PriorityArray(), statusFlags=StatusFlags(), ) avo = _make_mutable(avo, mutable=pv_writable) avo = _make_mutable(avo, identifier="relinquishDefault", mutable=pv_writable) deprecate_msg() return avo
def test_no_traffic(self): """Test basic configuration of a network.""" if _debug: TestAnalogValue._debug("test_no_traffic") # create a network anet = ApplicationNetwork("test_no_traffic") # add the service capability to the IUT anet.iut.add_capability(ChangeOfValueServices) # make an analog value object test_av = AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='av', presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=10.0, ) # an easy way to change the present value write_test_av = lambda v: setattr(test_av, 'presentValue', v) # add it to the implementation anet.iut.add_object(test_av) # make some transitions anet.iut.start_state.doc("1-1-0") \ .call(write_test_av, 100.0).doc("1-1-1") \ .timeout(1).doc("1-1-2") \ .call(write_test_av, 0.0).doc("1-1-3") \ .timeout(1).doc("1-1-4") \ .success() # test device is quiet anet.td.start_state.timeout(5).success() # run the group anet.run()
def main(): global test_application # make a parser parser = ConfigArgumentParser(description=__doc__) parser.add_argument( "--console", action="store_true", default=False, help="create a console", ) # parse the command line arguments args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object test_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=int(args.ini.objectidentifier), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # make a sample application test_application = SubscribeCOVApplication(test_device, args.ini.address) # make a binary value object test_bv = BinaryValueObject( objectIdentifier=('binaryValue', 1), objectName='bv', presentValue='inactive', statusFlags=[0, 0, 0, 0], ) _log.debug(" - test_bv: %r", test_bv) # add it to the device test_application.add_object(test_bv) # make an analog value object test_av = AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='av', presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=1.0, ) _log.debug(" - test_av: %r", test_av) # add it to the device test_application.add_object(test_av) _log.debug(" - object list: %r", test_device.objectList) # get the services supported services_supported = test_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know test_device.protocolServicesSupported = services_supported.value # make a console if args.console: test_console = COVConsoleCmd() _log.debug(" - test_console: %r", test_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def run_application() -> str: ''' Simulate and query the device. :return: Object query result. ''' from bacpypes.object import AnalogInputObject, AnalogOutputObject, AnalogValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject from bacnet.local_device_applications import SimulateAndQueryDeviceApplication import bacpypes.basetypes analog_input_objects = [ AnalogInputObject(objectName='Built-In Temperature Sensor', objectIdentifier=('analogInput', 1), objectType='analogInput', presentValue=21, eventState='normal', outOfService=False, units='degreesCelsius'), AnalogInputObject(objectName='External Temperature Sensor', objectIdentifier=('analogInput', 2), objectType='analogInput', presentValue=87, eventState='normal', outOfService=False, units='degreesCelsius'), AnalogInputObject(objectName='Calculated Setpoint', objectIdentifier=('analogInput', 3), objectType='analogInput', presentValue=87, eventState='normal', outOfService=False, units='degreesCelsius') ] analog_output_objets = [ AnalogOutputObject(objectIdentifier=('analogOutput', 1), objectName='Y1', objectType='analogOutput', presentValue=12, eventState='normal', outOfService=False, units='percent'), AnalogOutputObject(objectIdentifier=('analogOutput', 2), objectName='Y2', objectType='analogOutput', presentValue=88, eventState='normal', outOfService=False, units='percent'), AnalogOutputObject(objectIdentifier=('analogOutput', 3), objectName='Y3', objectType='analogOutput', presentValue=62, eventState='normal', outOfService=False, units='percent'), AnalogOutputObject(objectIdentifier=('analogOutput', 4), objectName='Thermic1_Position', objectType='analogOutput', presentValue=10, eventState='normal', outOfService=False, units='percent'), AnalogOutputObject(objectIdentifier=('analogOutput', 5), objectName='Thermic2_Position', objectType='analogOutput', presentValue=97, eventState='normal', outOfService=False, units='percent'), AnalogOutputObject(objectIdentifier=('analogOutput', 6), objectName='ThreePoint_Position', objectType='analogOutput', presentValue=62, eventState='normal', outOfService=False, units='percent') ] analog_value_objects = [ AnalogValueObject(objectIdentifier=('analogValue', 0), objectName='Temperature Setpoint', objectType='analogValue', presentValue=18, eventState='normal', outOfService=False, units='degreesCelsius', relinquishDefault=20), AnalogValueObject(objectIdentifier=('analogValue', 1), objectName='LCD Brightness', objectType='analogValue', presentValue=3.5, eventState='normal', outOfService=False, units='percent', relinquishDefault=50) ] binary_input_objects = [ BinaryInputObject(objectIdentifier=('binaryInput', 0), objectName='DI1', objectType='binaryInput', presentValue=0, eventState='normal', outOfService=False, polarity='normal', activeText='on', inactiveText='off') ] binary_output_objects = [ BinaryOutputObject(objectIdentifier=('binaryOutput', 0), objectName='DO1', objectType='binaryOutput', presentValue=0, eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 1), objectName='DO2', objectType='binaryOutput', presentValue=0, eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 2), objectName='Night_Mode_Override', objectType='binaryOutput', presentValue=0, eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 3), objectName='Summer_Winter_Changeover', objectType='binaryOutput', presentValue=0, eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 4), objectName='Cooling_Disable', objectType='binaryOutput', presentValue=0, eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off') ] objects = analog_output_objets + analog_input_objects + analog_value_objects + binary_input_objects + binary_output_objects return SimulateAndQueryDeviceApplication.run_application( objectIdentifier=651000, objectName="SRC100_001", objectType='device', systemStatus='operational', vendorName='SyxthSense', vendorIdentifier=651, modelName='URD', protocolVersion=1, protocolRevision=10, maxapdulength=480, segmentationSupported="noSegmentation", apduTimeout=3000, numberOfApduRetries=3, maxMaster=127, maxInfoFrames=1, databaseRevision=0, objects=objects)
def run_application() -> str: ''' Simulate and query the device. :return: Object query result. ''' from bacpypes.object import AnalogInputObject, AnalogValueObject, BinaryValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject from bacnet.local_device_applications import SimulateAndQueryDeviceApplication import bacpypes.basetypes analog_input_objects =\ [ AnalogInputObject( objectIdentifier=('analogInput', 1), objectName='Temperature', objectType='analogInput', presentValue=19, description='Temperature', deviceType='Temperature Sensor', statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, units='degreesCelsius' ), AnalogInputObject( objectIdentifier=('analogInput', 2), objectName='Relative Humidity', objectType='analogInput', presentValue=60, description='Relative Humidity', deviceType='RH Sensor', statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, units='percentRelativeHumidity' ), AnalogInputObject( objectIdentifier=('analogInput', 3), objectName='Dewpoint Temperature', objectType='analogInput', presentValue=8, description='Dewpoint Temperature', deviceType='Dewpoint Temperature Sensor', statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, units='degreesCelsius' ), AnalogInputObject( objectIdentifier=('analogInput', 4), objectName='Wet Bulb Temperature', objectType='analogInput', presentValue=19, description='Wet Bulb Temperature', deviceType='Wet Bulb Temperature Sensor', statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, units='degreesCelsius' ), AnalogInputObject( objectIdentifier=('analogInput', 5), objectName='Enthalpy', objectType='analogInput', presentValue=19, description='Enthalpy', deviceType='Enthalpy Sensor', statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, units='kilojoulesPerKilogramDryAir' )] analog_value_objects = [ AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Temperature Offset', objectType='analogValue', presentValue=0, description='Temperature Offset', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='deltaDegreesFahrenheit'), AnalogValueObject( objectIdentifier=('analogValue', 2), objectName='RH Offset', objectType='analogValue', presentValue=0, description='RH Offset', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='percentRelativeHumidity'), AnalogValueObject( objectIdentifier=('analogValue', 3), objectName='Atmospheric Pressure', objectType='analogValue', presentValue=1013, description='Atmospheric Pressure', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='hectopascals'), AnalogValueObject( objectIdentifier=('analogValue', 4), objectName='Altitude', objectType='analogValue', presentValue=0, description='Altitude', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='feet'), AnalogValueObject( objectIdentifier=('analogValue', 5), objectName='Display Mode', objectType='analogValue', presentValue=0, description='Display Mode', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='noUnits') ] binary_value_objects = [ BinaryValueObject( objectIdentifier=('binaryValue', 1), objectName='Temperature Units', objectType='binaryValue', presentValue=0, description='Celsius (0) or Fahrenheit (1)', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False), BinaryValueObject( objectIdentifier=('binaryValue', 2), objectName='Enthalpy Units', objectType='binaryValue', presentValue=0, description='kJ/kg (0) or BTU/lb (1)', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False) ] objects = analog_input_objects + analog_value_objects + binary_value_objects return SimulateAndQueryDeviceApplication.run_application( objectIdentifier=381001, objectName="DP_001", objectType=8, systemStatus='operational', vendorName='Greystone Energy Systems', vendorIdentifier=381, modelName='DP', firmwareRevision='1.2', applicationSoftwareVersion='1.0', description='Greystone Dewpoint Systems', protocolVersion=1, protocolRevision=14, protocolObjectTypesSupported=[ 'analogInput', 'analogValue', 'binaryValue', 'device' ], maxapdulength=128, segmentationSupported="noSegmentation", apduTimeout=6000, numberOfApduRetries=3, maxMaster=127, maxInfoFrames=1, objects=objects)
def test_changing_status_flags(self): """This test changes the status flags of binary value point to verify that the detection picks up other changes, most tests just change the present value.""" if _debug: TestAnalogValue._debug("test_changing_status_flags") # create a network anet = ApplicationNetwork("test_changing_status_flags") # add the ability to accept COV notifications to the TD anet.td.add_capability(COVTestClientServices) # tell the TD how to respond to confirmed notifications anet.td.test_ack = True anet.td.test_reject = None anet.td.test_abort = None # add the service capability to the IUT anet.iut.add_capability(ChangeOfValueServices) # make an analog value object test_av = AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='av', presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=10.0, ) # an easy way to change the present value def test_av_fault(): if _debug: TestAnalogValue._debug("test_av_fault") test_av.statusFlags = [0, 1, 0, 0] # add it to the implementation anet.iut.add_object(test_av) # receive the subscription request, wait until the client has # received the ack and the 'instant' notification. Then change the # value, no ack coming back anet.iut.start_state.doc("4-1-0") \ .receive(SubscribeCOVRequest).doc("4-1-1") \ .wait_event("e1").doc("4-1-2") \ .call(test_av_fault).doc("4-1-3") \ .timeout(10).doc("4-2-4") \ .success() # test device is quiet anet.td.start_state.doc("4-2-0") \ .send(SubscribeCOVRequest( destination=anet.iut.address, subscriberProcessIdentifier=1, monitoredObjectIdentifier=('analogValue', 1), issueConfirmedNotifications=False, lifetime=30, )).doc("4-2-1") \ .receive(SimpleAckPDU).doc("4-2-2") \ .receive(UnconfirmedCOVNotificationRequest).doc("4-2-3") \ .set_event("e1").doc("4-2-4") \ .receive(UnconfirmedCOVNotificationRequest).doc("4-2-5") \ .timeout(10).doc("4-2-6") \ .success() # run the group anet.run()
bacpypes_debugging(SampleEventDetection) # # # # parse the command line arguments parser = ArgumentParser(usage=__doc__) args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # analog value 1 av1 = AnalogValueObject( objectIdentifier=('analogValue', 1), presentValue=75.3, ) if _debug: _log.debug(" - av1: %r", av1) # add a very simple monitor av1._property_monitors['presentValue'].append( partial(something_changed, "av1"), ) # test it av1.presentValue = 45.6 # analog value 2 av2 = AnalogValueObject( objectIdentifier=('analogValue', 2), presentValue=75.3, )
def __init__(self, **kwargs): if _debug: RandomAnalogValueObject._debug("__init__ %r", kwargs) AnalogValueObject.__init__(self, **kwargs)
def run_application() -> str: ''' Simulate and query the device. :return: Object query result. ''' from bacpypes.object import AnalogInputObject, AnalogValueObject, BinaryValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject from bacnet.local_device_applications import SimulateAndQueryDeviceApplication import bacpypes.basetypes analog_input_objects =\ [ AnalogInputObject( objectIdentifier=('analogInput', 1), objectName='Pressure_Sensor_Value', objectType='analogInput', presentValue=101325, description='Pressure Value in Pa or wc', deviceType='Room Pressure Sensor', statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, units='pascals' )] analog_value_objects = [ AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Pressure_Averaging_Time', objectType='analogValue', presentValue=5, description='Pressure Averaging Time', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='seconds'), AnalogValueObject( objectIdentifier=('analogValue', 2), objectName='Alarm_High_Limit', objectType='analogValue', presentValue=0.5, description='Alarm High Limit in Pa or wc', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='pascals'), AnalogValueObject( objectIdentifier=('analogValue', 3), objectName='Alarm_Low_Limit', objectType='analogValue', presentValue=-0.5, description='Alarm Low Limit in Pa or wc', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='pascals'), AnalogValueObject( objectIdentifier=('analogValue', 4), objectName='Alarm_On_Delay', objectType='analogValue', presentValue=5, description='Alarm On Delay', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='minutes'), AnalogValueObject( objectIdentifier=('analogValue', 5), objectName='Alarm_Off_Delay', objectType='analogValue', presentValue=5, description='Alarm Off Delay', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='minutes'), AnalogValueObject( objectIdentifier=('analogValue', 6), objectName='Alarm_Silence_Time', objectType='analogValue', presentValue=30, description='Alarm Silence Time', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='minutes'), AnalogValueObject( objectIdentifier=('analogValue', 7), objectName='Buzzer_Volume', objectType='analogValue', presentValue=2, description='CO2 LCD Display Modes', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='noUnits') ] binary_value_objects = [ BinaryValueObject( objectIdentifier=('binaryValue', 1), objectName='Alarm_Enable', objectType='binaryValue', presentValue=1, description='0 = Alarm Disable, 1 = Alarm Enable', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False), BinaryValueObject( objectIdentifier=('binaryValue', 2), objectName='Alarm_Test', objectType='binaryValue', presentValue=0, description='0 = Normal Operation, 1 = Alarm Test', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False), BinaryValueObject( objectIdentifier=('binaryValue', 3), objectName='Backlight_Enable', objectType='binaryValue', presentValue=1, description='0 = Backlight Disable, 1 = Backlight Enable', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False), BinaryValueObject( objectIdentifier=('binaryValue', 4), objectName='Pressure_Units', objectType='binaryValue', presentValue=0, description='0 = wc, 1 = Pa ', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False), BinaryValueObject( objectIdentifier=('binaryValue', 5), objectName='Pressure_Range', objectType='binaryValue', presentValue=1, description='0 = Low Pressure Range, 1 = High Pressure Range', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False) ] binary_input_objects = [ BinaryInputObject( objectIdentifier=('binaryInput', 1), objectName='Alarm_Status', objectType='binaryInput', presentValue=0, description='Alarm Status', deviceType='0 = No Alarm, 1 = Pressure Alarm', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', ), BinaryInputObject( objectIdentifier=('binaryInput', 2), objectName='Low_Alarm_Status', objectType='binaryInput', presentValue=0, description='Low Alarm Status', deviceType='0 = No Low Alarm, 1 = Low Pressure Alarm', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', ), BinaryInputObject( objectIdentifier=('binaryInput', 3), objectName='High_Alarm_Status', objectType='binaryInput', presentValue=0, description='High Alarm Status', deviceType='0 = No High Alarm, 1 = High Pressure Alarm', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', ) ] objects = analog_input_objects + analog_value_objects + binary_value_objects + binary_input_objects return SimulateAndQueryDeviceApplication.run_application( objectIdentifier=381003, objectName="Room Pressure Monitor 003", objectType=8, systemStatus='operational', vendorName='Greystone Energy Systems', vendorIdentifier=381, modelName='RPC', firmwareRevision='1.4', applicationSoftwareVersion='1.0', description='Greystone RP Monitor', protocolVersion=1, protocolRevision=7, protocolObjectTypesSupported=[ 'analogInput', 'analogValue', 'binaryInput', 'binaryValue', 'device' ], maxapdulength=128, segmentationSupported="noSegmentation", apduTimeout=10000, numberOfApduRetries=3, maxMaster=127, maxInfoFrames=1, objects=objects)
bacpypes_debugging(SampleEventDetection) # # # # parse the command line arguments parser = ArgumentParser(usage=__doc__) args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # analog value 1 av1 = AnalogValueObject( objectIdentifier=('analogValue', 1), presentValue=75.3, ) if _debug: _log.debug(" - av1: %r", av1) # add a very simple monitor av1._property_monitors['presentValue'].append( partial(something_changed, "av1"), ) # test it av1.presentValue = 45.6 # analog value 2 av2 = AnalogValueObject( objectIdentifier=('analogValue', 2), presentValue=75.3,
def run_application() -> str: ''' Simulate and query the device. :return: Object query result. ''' from bacpypes.object import AnalogInputObject, AnalogOutputObject, AnalogValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject from bacnet.local_device_applications import SimulateAndQueryDeviceApplication binary_input_objects = \ [BinaryInputObject( objectIdentifier=('binaryInput',1), objectType='binaryInput', objectName='Momentary01', presentValue=0, deviceType='Momentary Contact', eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', activeText='on', inactiveText='off' ), BinaryInputObject( objectIdentifier=('binaryInput',2), objectType='binaryInput', objectName='Momentary02', presentValue=0, deviceType='Momentary Contact', eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', activeText='on', inactiveText='off' ), BinaryInputObject( objectIdentifier=('binaryInput',3), objectType='binaryInput', objectName='Momentary03', presentValue=0, deviceType='Momentary Contact', eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', activeText='on', inactiveText='off' ), BinaryInputObject( objectIdentifier=('binaryInput',4), objectType='binaryInput', objectName='Momentary04', presentValue=0, deviceType='Momentary Contact', eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', activeText='on', inactiveText='off' ), BinaryInputObject( objectIdentifier=('binaryInput',5), objectType='binaryInput', objectName='Momentary05', presentValue=0, deviceType='Momentary Contact', eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', activeText='on', inactiveText='off' ), BinaryInputObject( objectIdentifier=('binaryInput',6), objectType='binaryInput', objectName='Momentary06', presentValue=0, deviceType='Momentary Contact', eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', activeText='on', inactiveText='off' ), BinaryInputObject( objectIdentifier=('binaryInput',101), objectType='binaryInput', objectName='Maintained01', presentValue=0, deviceType='Maintain Contact', eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', activeText='on', inactiveText='off' ), BinaryInputObject( objectIdentifier=('binaryInput',102), objectType='binaryInput', objectName='Maintained02', presentValue=0, deviceType='Maintain Contact', eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', activeText='on', inactiveText='off' ), BinaryInputObject( objectIdentifier=('binaryInput',103), objectType='binaryInput', objectName='Maintained03', presentValue=0, deviceType='Maintain Contact', eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', activeText='on', inactiveText='off' ), BinaryInputObject( objectIdentifier=('binaryInput',104), objectType='binaryInput', objectName='Maintained04', presentValue=0, deviceType='Maintain Contact', eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', activeText='on', inactiveText='off' ), BinaryInputObject( objectIdentifier=('binaryInput',105), objectType='binaryInput', objectName='Maintained05', presentValue=0, deviceType='MomeMaintainntary Contact', eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', activeText='on', inactiveText='off' ), BinaryInputObject( objectIdentifier=('binaryInput',106), objectType='binaryInput', objectName='Maintained06', presentValue=0, deviceType='Maintain Contact', eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', activeText='on', inactiveText='off' )] analog_value_objects = [ AnalogValueObject( objectIdentifier=('analogValue', 1), objectType='analogValue', objectName='Pilot01', presentValue=0x0110101, eventState='normal', outOfService=False, ), AnalogValueObject( objectIdentifier=('analogValue', 2), objectType='analogValue', objectName='Pilot02', presentValue=0x0101101, eventState='normal', outOfService=False, ), AnalogValueObject( objectIdentifier=('analogValue', 3), objectType='analogValue', objectName='Pilot03', presentValue=0x111001, eventState='normal', outOfService=False, ), AnalogValueObject( objectIdentifier=('analogValue', 4), objectType='analogValue', objectName='Pilot04', presentValue=0x0110110, eventState='normal', outOfService=False, ), AnalogValueObject( objectIdentifier=('analogValue', 5), objectType='analogValue', objectName='Pilot05', presentValue=0x0000101, eventState='normal', outOfService=False, ), AnalogValueObject( objectIdentifier=('analogValue', 6), objectType='analogValue', objectName='Pilot06', presentValue=0x0000001, eventState='normal', outOfService=False, ), AnalogValueObject( objectIdentifier=('analogValue', 100), objectType='analogValue', objectName='Device Options', presentValue=0, eventState='normal', outOfService=False, ), AnalogValueObject( objectIdentifier=('analogValue', 1001), objectType='analogValue', objectName='Input Change Buffer', presentValue=0, eventState='normal', outOfService=False, ), AnalogValueObject( objectIdentifier=('analogValue', 1003), objectType='analogValue', objectName='Device Instance', presentValue=0, eventState='normal', outOfService=False, ) ] objects = analog_value_objects + binary_input_objects return SimulateAndQueryDeviceApplication.run_application( objectIdentifier=68501, objectName="BAC10142XXXXXXXX", objectType=8, systemStatus='operational', vendorName='Touch-Plate Lighting Controls', vendorIdentifier=68, modelName='Ultra BACnet Smart Control Station', firmwareRevision='2.48', applicationSoftwareVersion='1.5h', protocolVersion=1, protocolRevision=7, protocolObjectTypesSupported=[ 'analogValue', 'binaryInput', 'binaryOutput', 'device' ], maxapdulength=480, segmentationSupported="noSegmentation", apduTimeout=3000, numberOfApduRetries=0, maxMaster=127, databaseRevision=1, objects=objects)
def test_8_10_2(self): """Unconfirmed Notifications Subscription""" if _debug: TestAnalogValue._debug("test_8_10_2") # create a network anet = ApplicationNetwork("test_8_10_2") # add the ability to accept COV notifications to the TD anet.td.add_capability(COVTestClientServices) # tell the TD how to respond to confirmed notifications anet.td.test_ack = True anet.td.test_reject = None anet.td.test_abort = None # add the service capability to the IUT anet.iut.add_capability(ChangeOfValueServices) # make an analog value object test_av = AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='av', presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=10.0, ) # add it to the implementation anet.iut.add_object(test_av) # wait for the subscription anet.iut.start_state.doc("8.10.2-1-0") \ .receive(SubscribeCOVRequest).doc("8.10.2-1-1") \ .success() # send the subscription, wait for the ack anet.td.start_state.doc("8.10.2-2-0") \ .send(SubscribeCOVRequest( destination=anet.iut.address, subscriberProcessIdentifier=1, monitoredObjectIdentifier=('analogValue', 1), issueConfirmedNotifications=False, lifetime=30, )).doc("8.10.2-2-1") \ .receive(SimpleAckPDU).doc("8.10.2-2-2") \ .success() # run the group, cut the time limit short anet.run(time_limit=5.0) # check that the IUT still has the detection if _debug: TestAnalogValue._debug(" - detections: %r", anet.iut.cov_detections) assert len(anet.iut.cov_detections) == 1 # pop out the subscription list and criteria obj_ref, criteria = anet.iut.cov_detections.popitem() if _debug: TestAnalogValue._debug(" - criteria: %r", criteria) # get the list of subscriptions from the criteria subscriptions = criteria.cov_subscriptions.cov_subscriptions if _debug: TestAnalogValue._debug(" - subscriptions: %r", subscriptions) assert len(subscriptions) == 1
def test_multiple_subscribers(self): """This has more than one subscriber for the object.""" if _debug: TestAnalogValue._debug("test_multiple_subscribers") # create a network anet = ApplicationNetwork("test_multiple_subscribers") # add the ability to accept COV notifications to the TD anet.td.add_capability(COVTestClientServices) # tell the TD how to respond to confirmed notifications anet.td.test_ack = True anet.td.test_reject = None anet.td.test_abort = None # add the service capability to the IUT anet.iut.add_capability(ChangeOfValueServices) # make an analog value object test_av = AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='av', presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=10.0, ) # an easy way to change both the present value and status flags # which should trigger only one notification def test_av_fault(): if _debug: TestAnalogValue._debug("test_av_fault") test_av.presentValue = 100.0 test_av.statusFlags = [0, 0, 1, 0] # add it to the implementation anet.iut.add_object(test_av) # add another test device object anet.td2_device_object = LocalDeviceObject( objectName="td2", objectIdentifier=('device', 30), maxApduLengthAccepted=1024, segmentationSupported='noSegmentation', vendorIdentifier=999, ) # another test device anet.td2 = ApplicationStateMachine(anet.td2_device_object, anet.vlan) anet.td2.add_capability(COVTestClientServices) anet.append(anet.td2) # receive the subscription requests, wait until both clients have # received the ack and the 'instant' notification. Then change the # value, no ack coming back anet.iut.start_state.doc("6-1-0") \ .receive(SubscribeCOVRequest, pduSource=anet.td.address).doc("6-1-1") \ .receive(SubscribeCOVRequest, pduSource=anet.td2.address).doc("6-1-2") \ .wait_event("e2").doc("6-1-3") \ .call(test_av_fault).doc("6-1-4") \ .timeout(10).doc("6-2-5") \ .success() # first test device; send the subscription request, get an ack # followed by the 'instant' notification anet.td.start_state.doc("6-2-0") \ .send(SubscribeCOVRequest( destination=anet.iut.address, subscriberProcessIdentifier=1, monitoredObjectIdentifier=('analogValue', 1), issueConfirmedNotifications=False, lifetime=30, )).doc("6-2-1") \ .receive(SimpleAckPDU).doc("6-2-2") \ .receive(UnconfirmedCOVNotificationRequest).doc("6-2-3") \ .set_event("e1").doc("6-2-4") \ .receive(UnconfirmedCOVNotificationRequest).doc("6-2-5") \ .timeout(10).doc("6-2-6") \ .success() # same pattern for the other test device anet.td2.start_state.doc("6-3-0") \ .wait_event("e1").doc("6-3-1") \ .send(SubscribeCOVRequest( destination=anet.iut.address, subscriberProcessIdentifier=1, monitoredObjectIdentifier=('analogValue', 1), issueConfirmedNotifications=False, lifetime=30, )).doc("6-3-2") \ .receive(SimpleAckPDU).doc("6-3-3") \ .receive(UnconfirmedCOVNotificationRequest).doc("6-3-4") \ .set_event("e2").doc("6-3-5") \ .receive(UnconfirmedCOVNotificationRequest).doc("6-3-6") \ .timeout(10).doc("6-3-7") \ .success() # run the group anet.run()
def test_9_10_1_1(self): if _debug: TestAnalogValue._debug("test_9_10_1_1") notification_fail_time = 0.5 # create a network anet = ApplicationNetwork("test_9_10_1_1") # add the ability to accept COV notifications to the TD anet.td.add_capability(COVTestClientServices) # tell the TD how to respond to confirmed notifications anet.td.test_ack = True anet.td.test_reject = None anet.td.test_abort = None # add the service capability to the IUT anet.iut.add_capability(ChangeOfValueServices) # make an analog value object test_av = AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='av', presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=10.0, ) # add it to the implementation anet.iut.add_object(test_av) # wait for the subscription, wait for the notification ack anet.iut.start_state.doc("9.10.1.1-1-0") \ .receive(SubscribeCOVRequest).doc("9.10.1.1-1-1") \ .receive(SimpleAckPDU).doc("9.10.1.1-1-2") \ .timeout(10).doc("9.10.1.1-1-3") \ .success() # test device is quiet wait_for_notification = \ anet.td.start_state.doc("9.10.1.1-2-0") \ .send(SubscribeCOVRequest( destination=anet.iut.address, subscriberProcessIdentifier=1, monitoredObjectIdentifier=('analogValue', 1), issueConfirmedNotifications=True, lifetime=30, )).doc("9.10.1.1-2-1") \ .receive(SimpleAckPDU).doc("9.10.1.1-2-2") # after the ack, don't wait too long for the notification wait_for_notification \ .timeout(notification_fail_time).doc("9.10.1.1-2-3").fail() # if the notification is received, success wait_for_notification \ .receive(ConfirmedCOVNotificationRequest).doc("9.10.1.1-2-4") \ .timeout(10).doc("9.10.1.1-2-5") \ .success() # run the group anet.run()
def run_application() -> str: ''' Simulate and query the device. :return: Object query result. ''' from bacpypes.object import AnalogInputObject, AnalogOutputObject, AnalogValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject from bacnet.local_device_applications import SimulateAndQueryDeviceApplication import bacpypes.basetypes analog_input_objects =\ [ AnalogInputObject( objectName='Temperature Sensor', objectIdentifier=('analogInput', 0), objectType='analogInput', presentValue=21, #statusFlags='inAlarm', eventState='normal', outOfService=False, units='degreesCelsius' ), AnalogInputObject( objectName='Setpoint Adjust', objectIdentifier=('analogInput', 1), objectType='analogInput', presentValue=259, #statusFlags='inAlarm', eventState='normal', outOfService=False, units='degreesCelsius' ), AnalogInputObject( objectName='Humidity Sensor', objectIdentifier=('analogInput', 2), objectType='analogInput', presentValue=27, #statusFlags='inAlarm', eventState='normal', outOfService=False, units='percent' ), AnalogInputObject( objectName='RI1', objectIdentifier=('analogInput', 3), objectType='analogInput', presentValue=20981, #statusFlags='inAlarm', eventState='normal', outOfService=False, units='ohms' ), AnalogInputObject( objectName='RI2', objectIdentifier=('analogInput', 4), objectType='analogInput', presentValue=12841, #statusFlags='inAlarm', eventState='normal', outOfService=False, units='ohms' ), AnalogInputObject( objectName='CO2 Sensor', objectIdentifier=('analogInput', 5), objectType='analogInput', presentValue=738, #statusFlags='inAlarm', eventState='normal', outOfService=False, units='partsPerMillion' ), AnalogInputObject( objectName='LUX Sensor', objectIdentifier=('analogInput', 6), objectType='analogInput', presentValue=1974, #statusFlags='inAlarm', eventState='normal', outOfService=False, units='luxes' )] analog_output_objets = [ AnalogOutputObject(objectIdentifier=('analogOutput', 0), objectName='Y1', objectType='analogOutput', presentValue=72, eventState='normal', outOfService=False, units='percent'), AnalogOutputObject(objectIdentifier=('analogOutput', 1), objectName='Y2', objectType='analogOutput', presentValue=21, eventState='normal', outOfService=False, units='percent'), AnalogOutputObject(objectIdentifier=('analogOutput', 2), objectName='Y3', objectType='analogOutput', presentValue=82, eventState='normal', outOfService=False, units='percent') ] analog_value_objects = [ AnalogValueObject(objectIdentifier=('analogValue', 0), objectName='Temperature Setpoint', objectType='analogValue', presentValue=27, eventState='normal', outOfService=False, units='degreesCelsius', relinquishDefault=20), AnalogValueObject(objectIdentifier=('analogValue', 1), objectName='Humidity Setpoint', objectType='analogValue', presentValue=12, eventState='normal', outOfService=False, units='percent', relinquishDefault=50), AnalogValueObject(objectIdentifier=('analogValue', 2), objectName='CO2 Setpoint', objectType='analogValue', presentValue=502, eventState='normal', outOfService=False, units='partsPerMillion', relinquishDefault=500), AnalogValueObject(objectIdentifier=('analogValue', 3), objectName='LUX Setpoint', objectType='analogValue', presentValue=1129, eventState='normal', outOfService=False, units='luxes', relinquishDefault=1500), AnalogValueObject(objectIdentifier=('analogValue', 4), objectName='DI1 Pulse Count', objectType='analogValue', presentValue=8276491, eventState='normal', outOfService=False, units='noUnits', relinquishDefault=0), AnalogValueObject(objectIdentifier=('analogValue', 5), objectName='DI2 Pulse Count', objectType='analogValue', presentValue=292384, eventState='normal', outOfService=False, units='noUnits', relinquishDefault=0), AnalogValueObject(objectIdentifier=('analogValue', 6), objectName='LCD Backlight Brightness', objectType='analogValue', presentValue=7, eventState='normal', outOfService=False, units='noUnits', relinquishDefault=0), ] binary_input_objects = [ BinaryInputObject(objectIdentifier=('binaryInput', 0), objectName='DI1', objectType='binaryInput', presentValue=0, eventState='normal', outOfService=False, polarity='normal', activeText='on', inactiveText='off'), BinaryInputObject(objectIdentifier=('binaryInput', 1), objectName='DI2', objectType='binaryInput', presentValue=1, eventState='normal', outOfService=False, polarity='normal', activeText='on', inactiveText='off'), BinaryInputObject(objectIdentifier=('binaryInput', 2), objectName='Occupancy', objectType='binaryInput', presentValue=1, eventState='normal', outOfService=False, polarity='normal', activeText='on', inactiveText='off'), BinaryInputObject(objectIdentifier=('binaryInput', 3), objectName='Push Button 1', objectType='binaryInput', presentValue=0, eventState='normal', outOfService=False, polarity='normal', activeText='on', inactiveText='off'), BinaryInputObject(objectIdentifier=('binaryInput', 4), objectName='Push Button 2', objectType='binaryInput', presentValue=0, eventState='normal', outOfService=False, polarity='normal', activeText='on', inactiveText='off') ] binary_output_objects = [ BinaryOutputObject(objectIdentifier=('binaryOutput', 0), objectName='DO1', objectType='binaryOutput', presentValue=0, eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 1), objectName='DO2', objectType='binaryOutput', presentValue=0, eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 2), objectName='SPA Reset', objectType='binaryOutput', presentValue=0, eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off') ] multistate_input_objects = [ MultiStateInputObject(objectIdentifier=('multiStateInput', 0), objectName='Alarm Level', objectType='multiStateInput', presentValue=1, eventState='normal', outOfService=False, numberOfStates=3) ] objects = analog_output_objets + analog_input_objects + analog_value_objects + binary_input_objects + binary_output_objects + multistate_input_objects return SimulateAndQueryDeviceApplication.run_application( objectIdentifier=651000, objectName="CDR_001", objectType=8, systemStatus='operational', vendorName='SyxthSense', vendorIdentifier=651, modelName='CDR', protocolVersion=1, protocolRevision=10, maxapdulength=480, segmentationSupported="noSegmentation", apduTimeout=3000, numberOfApduRetries=3, maxMaster=127, maxInfoFrames=1, databaseRevision=0, objects=objects)
def main(): global test_av, test_bv, test_application # make a parser parser = ConfigArgumentParser(description=__doc__) parser.add_argument( "--console", action="store_true", default=False, help="create a console", ) # analog value task and thread parser.add_argument( "--avtask", type=float, help="analog value recurring task", ) parser.add_argument( "--avthread", type=float, help="analog value thread", ) # analog value task and thread parser.add_argument( "--bvtask", type=float, help="binary value recurring task", ) parser.add_argument( "--bvthread", type=float, help="binary value thread", ) # provide a different spin value parser.add_argument( "--spin", type=float, help="spin time", default=1.0, ) # parse the command line arguments args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject(ini=args.ini) if _debug: _log.debug(" - this_device: %r", this_device) # make a sample application test_application = SubscribeCOVApplication(this_device, args.ini.address) # make an analog value object test_av = AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='av', presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=1.0, ) _log.debug(" - test_av: %r", test_av) # add it to the device test_application.add_object(test_av) _log.debug(" - object list: %r", this_device.objectList) # make a binary value object test_bv = BinaryValueObject( objectIdentifier=('binaryValue', 1), objectName='bv', presentValue='inactive', statusFlags=[0, 0, 0, 0], ) _log.debug(" - test_bv: %r", test_bv) # add it to the device test_application.add_object(test_bv) # make a console if args.console: test_console = COVConsoleCmd() _log.debug(" - test_console: %r", test_console) # enable sleeping will help with threads enable_sleeping() # analog value task if args.avtask: test_av_task = TestAnalogValueTask(args.avtask) test_av_task.install_task() # analog value thread if args.avthread: test_av_thread = TestAnalogValueThread(args.avthread) deferred(test_av_thread.start) # binary value task if args.bvtask: test_bv_task = TestBinaryValueTask(args.bvtask) test_bv_task.install_task() # binary value thread if args.bvthread: test_bv_thread = TestBinaryValueThread(args.bvthread) deferred(test_bv_thread.start) _log.debug("running") run(args.spin) _log.debug("fini")
def run_application() -> str: ''' Simulate and query the device. :return: Object query result. ''' from bacpypes.object import AnalogInputObject, AnalogOutputObject, AnalogValueObject, BinaryValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject from bacnet.local_device_applications import SimulateAndQueryDeviceApplication from random import randint analog_input_objects = [ AnalogInputObject(objectIdentifier=('analogInput', 0), objectName='Sensor_Temperature', objectType='analogInput', presentValue=randint(0, 150), eventState='normal', outOfService=False, units='degreesCelsius'), AnalogInputObject(objectIdentifier=('analogInput', 1), objectName='Setpoint_Adjust', objectType='analogInput', presentValue=randint(0, 150), eventState='normal', outOfService=False, units='degreesCelsius'), AnalogInputObject(objectIdentifier=('analogInput', 2), objectName='Sensor_Humidity', objectType='analogInput', presentValue=randint(0, 100), eventState='normal', outOfService=False, units='percent'), AnalogInputObject(objectIdentifier=('analogInput', 3), objectName='RI1', objectType='analogInput', presentValue=randint(0, 50000), eventState='normal', outOfService=False, units='ohms'), AnalogInputObject(objectIdentifier=('analogInput', 4), objectName='User_Fan_Speed', objectType='analogInput', presentValue=randint(0, 100), eventState='normal', outOfService=False, units='noUnits') ] analog_output_objects = [ AnalogOutputObject(objectIdentifier=('analogOutput', 0), objectName='Y1', objectType='analogOutput', presentValue=randint(0, 100), eventState='normal', outOfService=False, units='percent') ] analog_value_objects = [ AnalogValueObject( objectIdentifier=('analogValue', 0), objectName='Setpoint_Temperature', objectType='analogValue', presentValue=randint(0, 100), eventState='normal', outOfService=False, units='degreesCelsius', ), AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Fan_Speed', objectType='analogValue', presentValue=randint(0, 10), eventState='normal', outOfService=False, units='noUnits', ), AnalogValueObject( objectIdentifier=('analogValue', 2), objectName='Alarm_Code', objectType='analogValue', presentValue=randint(0, 100), eventState='normal', outOfService=False, units='noUnits', ) ] binary_input_objects = [ BinaryInputObject(objectIdentifier=('binaryInput', 0), objectName='DI1', objectType='binaryInput', presentValue=randint(0, 1), eventState='normal', outOfService=False, polarity='normal', activeText='on', inactiveText='off'), BinaryInputObject(objectIdentifier=('binaryInput', 1), objectName='Operating_Mode', objectType='binaryInput', presentValue=randint(0, 1), eventState='normal', outOfService=False, polarity='normal', activeText='on', inactiveText='off') ] binary_output_ojects = [ BinaryOutputObject(objectIdentifier=('binaryOutput', 0), objectName='DO1', objectType='binaryOutput', presentValue=randint(0, 1), eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 1), objectName='DO2', objectType='binaryOutput', presentValue=randint(0, 1), eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 2), objectName='Heating Symbol', objectType='binaryOutput', presentValue=randint(0, 1), eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 3), objectName='Cooling Symbol', objectType='binaryOutput', presentValue=randint(0, 1), eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 4), objectName='Open Arrow Symbol', objectType='binaryOutput', presentValue=randint(0, 1), eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 5), objectName='Close Arrow Symbol', objectType='binaryOutput', presentValue=randint(0, 1), eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 6), objectName='Day/Night Model', objectType='binaryOutput', presentValue=randint(0, 1), eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off'), BinaryOutputObject(objectIdentifier=('binaryOutput', 7), objectName='SPA Reset', objectType='binaryOutput', presentValue=randint(0, 1), eventState='normal', outOfService=False, polarity='normal', relinquishDefault=0, activeText='on', inactiveText='off') ] objects = analog_input_objects + analog_output_objects + analog_value_objects + binary_input_objects + binary_output_ojects return SimulateAndQueryDeviceApplication.run_application( objectIdentifier=651000, objectName="RIU_001", objectType=8, systemStatus='operational', vendorName='SyxthSense', vendorIdentifier=651, modelName='RI', protocolVersion=1, protocolRevision=10, maxapdulength=480, segmentationSupported="noSegmentation", apduTimeout=3000, numberOfApduRetries=3, maxMaster=127, maxInfoFrames=1, objects=objects)
def test_8_2_1(self): """To verify that the IUT can initiate ConfirmedCOVNotification service requests conveying a change of the Present_Value property of Analog Input, Analog Output, and Analog Value objects.""" if _debug: TestAnalogValue._debug("test_8_2_1") # create a network anet = ApplicationNetwork("test_8_2_1") # add the ability to accept COV notifications to the TD anet.td.add_capability(COVTestClientServices) # tell the TD how to respond to confirmed notifications anet.td.test_ack = True anet.td.test_reject = None anet.td.test_abort = None # add the service capability to the IUT anet.iut.add_capability(ChangeOfValueServices) # make an analog value object test_av = AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='av', presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=10.0, ) # an easy way to change the present value write_test_av = lambda v: setattr(test_av, 'presentValue', v) # add it to the implementation anet.iut.add_object(test_av) # receive the subscription request, wait until the client has # received the ack and the 'instant' notification. Then change the # value a little bit and nothing should be sent. Change it some more # and wait for the notification ack. anet.iut.start_state.doc("2-1-0") \ .receive(SubscribeCOVRequest).doc("2-1-1") \ .receive(SimpleAckPDU).doc("2-1-2") \ .wait_event("e1").doc("2-1-3") \ .call(write_test_av, 5.0).doc("2-1-4") \ .timeout(5).doc("2-2-5") \ .call(write_test_av, 10.0).doc("2-1-6") \ .receive(SimpleAckPDU).doc("2-1-7") \ .timeout(10).doc("2-2-8") \ .success() # send the subscription request, wait for the ack and the 'instant' # notification, set the event so the IUT can continue, then wait # for the next notification anet.td.start_state.doc("2-2-0") \ .send(SubscribeCOVRequest( destination=anet.iut.address, subscriberProcessIdentifier=1, monitoredObjectIdentifier=('analogValue', 1), issueConfirmedNotifications=True, lifetime=30, )).doc("2-2-1") \ .receive(SimpleAckPDU).doc("2-2-2") \ .receive(ConfirmedCOVNotificationRequest).doc("2-2-4") \ .set_event("e1").doc("2-2-3") \ .receive(ConfirmedCOVNotificationRequest).doc("2-2-4") \ .timeout(10).doc("2-2-5") \ .success() # run the group anet.run()
def run_application() -> str: ''' Simulate and query the device. :return: Object query result. ''' from bacpypes.object import AnalogInputObject, AnalogValueObject, BinaryValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject from bacnet.local_device_applications import SimulateAndQueryDeviceApplication import bacpypes.basetypes analog_input_objects =\ [ AnalogInputObject( objectIdentifier=('analogInput', 1), objectName='CO2_Level', objectType='analogInput', presentValue=21, description='CO2 Level', deviceType='0-2000 ppm CO2 Sensor', statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, units='partsPerMillion' ), AnalogInputObject( objectIdentifier=('analogInput', 2), objectName='Relative_Humidity', objectType='analogInput', presentValue=60, description='Relative Humidity', deviceType='0-100 %RH Sensor', statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, units='percentRelativeHumidity' ), AnalogInputObject( objectIdentifier=('analogInput', 3), objectName='Temperature', objectType='analogInput', presentValue=19, description='Temperature', deviceType='0-35 C Temperature Sensor or 32-95 F Temperature Sensor', statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, units='degreesCelsius' ), AnalogInputObject( objectIdentifier=('analogInput', 4), objectName='Setpoint_Control', objectType='analogInput', presentValue=67, description='Setpoint Value', deviceType='0-100 % Setpoint', statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, units='percent' )] analog_value_objects = [ AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Relay_Setpoint', objectType='analogValue', presentValue=1000, description='Relay Setpoint', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='partsPerMillion'), AnalogValueObject( objectIdentifier=('analogValue', 2), objectName='Relay_Hysteresis', objectType='analogValue', presentValue=50, description='Relay Hysteresis', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='partsPerMillion'), AnalogValueObject( objectIdentifier=('analogValue', 3), objectName='Temperature_Offset', objectType='analogValue', presentValue=50, description='Temperature Offset Calibration', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='deltaDegreesFahrenheit'), AnalogValueObject( objectIdentifier=('analogValue', 4), objectName='Relative_Humidity_Offset', objectType='analogValue', presentValue=0, description='RH Offset Calibration', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='percentRelativeHumidity'), AnalogValueObject( objectIdentifier=('analogValue', 5), objectName='Sensor_Altitude', objectType='analogValue', presentValue=50, description='CO2 Sensor Altitude', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='feet'), AnalogValueObject( objectIdentifier=('analogValue', 6), objectName='Display_Modes', objectType='analogValue', presentValue=50, description='CO2 LCD Display Modes', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', outOfService=False, units='noUnits') ] binary_value_objects = [ BinaryValueObject( objectIdentifier=('binaryValue', 1), objectName='Override_Switch', objectType='binaryValue', presentValue=0, description='Override Switch', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False), BinaryValueObject( objectIdentifier=('binaryValue', 2), objectName='Auto_Cal_Enable', objectType='binaryValue', presentValue=1, description='Auto Calibration Enable', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False), BinaryValueObject( objectIdentifier=('binaryValue', 3), objectName='Fahrenheit', objectType='binaryValue', presentValue=1, description='Fahrenheit (1) or Celsius (0)', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False) ] binary_input_objects = [ BinaryInputObject( objectIdentifier=('binaryInput', 1), objectName='Relay_On', objectType='binaryInput', presentValue=0, description='Relay Status', deviceType='Indicates On/Off Status of Relay', statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'], eventState='normal', reliability='noFaultDetected', outOfService=False, polarity='normal', ) ] objects = analog_input_objects + analog_value_objects + binary_value_objects + binary_input_objects return SimulateAndQueryDeviceApplication.run_application( objectIdentifier=381003, objectName="CDD_CO2_Detector_003", objectType=8, systemStatus='operational', vendorName='Greystone Energy Systems', vendorIdentifier=381, modelName='CDD2A', firmwareRevision='1.4', applicationSoftwareVersion='1.0', description='Greystone CO2 Detector', protocolVersion=1, protocolRevision=7, protocolObjectTypesSupported=[ 'analogInput', 'analogValue', 'binaryInput', 'binaryValue', 'device' ], maxapdulength=128, segmentationSupported="noSegmentation", apduTimeout=10000, numberOfApduRetries=3, maxMaster=127, maxInfoFrames=1, objects=objects)
def __init__(self, **kwargs): AnalogValueObject.__init__(self, **kwargs)
# create an array of property identifiers datatype ArrayOfPropertyIdentifier = ArrayOf(PropertyIdentifier) aopi = ArrayOfPropertyIdentifier() aopi.append('objectName') aopi.append('objectType') aopi.append('description') aopi.debug_contents() aopi.remove('objectType') aopi.debug_contents() print("Create an Analog Value Object") av = AnalogValueObject( objectName='av-sample', objectIdentifier=('analogValue', 1), description="sample", ) av.debug_contents() print("") print("Change the description") av.description = "something else" av.debug_contents() print("") # get the description property by the attribute name description_property = av._attr_to_property('description') print("description_property = %r" % (description_property, )) print("")