def test_unsigned_int(self): if _debug: TestUnsigned._debug("test_unsigned_int") obj = Unsigned(1) assert obj.value == 1 assert str(obj) == "Unsigned(1)" with self.assertRaises(ValueError): Unsigned(-1)
def test_unsigned(self): if _debug: TestUnsigned._debug("test_unsigned") obj = Unsigned() assert obj.value == 0 with self.assertRaises(TypeError): Unsigned("some string") with self.assertRaises(TypeError): Unsigned(1.0)
def __init__(self, ini_file, overriding_port: int = None): self.args = ConfigArgumentParser().parse_args(["--ini", ini_file]) #addr = Address(self.args.ini.address) #if overriding_port: # addr.addrPort = overriding_port #print('Address: {0}'.format(addr.addrPort)) if overriding_port: ip, port = self.args.ini['address'].split(':') self.args.ini['address'] = ip + ':' + str(overriding_port) self.this_device = LocalDeviceObject(ini=self.args.ini) BIPSimpleApplication.__init__(self, self.this_device, self.args.ini['address']) self.taskman = TaskManager() self.datatype_map = { 'b': Boolean, 'u': lambda x: Unsigned(int(x)), 'i': lambda x: Integer(int(x)), 'r': lambda x: Real(float(x)), 'd': lambda x: Double(float(x)), 'o': OctetString, 'c': CharacterString, 'bs': BitString, 'date': Date, 'time': Time, 'id': ObjectIdentifier, } thread_handle = threading.Thread(target=self.run_thread) thread_handle.daemon = True thread_handle.start()
def __init__(self, arg=None): Unsigned.__init__(self, arg) self.value = 0 if arg is None: pass elif isinstance(arg, Tag): self.decode(arg) elif isinstance(arg, int): if not self.is_valid(arg): raise ValueError("unsigned integer less than 65536 required") self.value = arg elif isinstance(arg, Unsigned16): self.value = arg.value else: raise TypeError("invalid constructor datatype")
def unsigned_decode(tag): """Decode an unsigned application tag into an unsigned.""" if _debug: unsigned_decode._debug("unsigned_decode %r", tag) obj = Unsigned(tag) if _debug: unsigned_decode._debug(" - obj: %r", obj) return obj
def writeValue(self,addr,obj_id,prop_id,value,indx=None,priority=None): if isinstance(obj_id,str): obj_id=obj_id.split(':') obj_id[1]=int(obj_id[1]) addr=RemoteStation(addr[0],bytearray(addr[1])) datatype = get_datatype(obj_id[0],prop_id) if datatype is None:return if (value == 'null'): value = Null() elif issubclass(datatype, AnyAtomic): dtype, dvalue = value.split(':', 1) datatype = { 'b': Boolean, 'u': lambda x: Unsigned(int(x)), 'i': lambda x: Integer(int(x)), 'r': lambda x: Real(float(x)), 'd': lambda x: Double(float(x)), 'o': OctetString, 'c': CharacterString, 'bs': BitString, 'date': Date, 'time': Time, 'id': ObjectIdentifier, }[dtype] value = datatype(dvalue) elif issubclass(datatype, Atomic): if datatype is Integer: value = int(value) elif datatype is Real: value = float(value) elif datatype is Unsigned: value = int(value) value = datatype(value) elif issubclass(datatype, Array) and (indx is not None): if indx == 0: value = Integer(value) elif issubclass(datatype.subtype, Atomic): value = datatype.subtype(value) elif not isinstance(value, datatype.subtype): raise TypeError("invalid result datatype, expecting %s" % (datatype.subtype.__name__,)) elif not isinstance(value, datatype): raise TypeError("invalid result datatype, expecting %s" % (datatype.__name__,)) # build a request request = WritePropertyRequest( objectIdentifier=tuple(obj_id), propertyIdentifier=prop_id, destination=addr ) # save the value request.propertyValue = Any() request.propertyValue.cast_in(value) if indx is not None: request.propertyArrayIndex = indx if priority is not None: request.priority = priority iocb = IOCB(request) self.request_io(iocb)
def test_unsigned_tag(self): if _debug: TestUnsigned._debug("test_unsigned_tag") tag = Tag(Tag.applicationTagClass, Tag.unsignedAppTag, 1, xtob('01')) obj = Unsigned(tag) assert obj.value == 1 tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob('')) with self.assertRaises(InvalidTag): Unsigned(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(InvalidTag): Unsigned(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(InvalidTag): Unsigned(tag)
def test_unsigned(self): if _debug: TestUnsigned._debug("test_unsigned") obj = Unsigned() assert obj.value == 0 assert Unsigned.is_valid(1) assert not Unsigned.is_valid(-1) if sys.version[0] == 2: assert Unsigned.is_valid(long(1)) assert not Unsigned.is_valid(long(-1)) assert not Unsigned.is_valid(True) assert not Unsigned.is_valid(-1) assert not Unsigned.is_valid(1.0) with self.assertRaises(TypeError): Unsigned("some string") with self.assertRaises(TypeError): Unsigned(1.0)
def unsigned_endec(v, x): """Pass the value to Unsigned, construct a tag from the hex string, and compare results of encode and decoding each other.""" if _debug: unsigned_endec._debug("unsigned_endec %r %r", v, x) tag = unsigned_tag(x) if _debug: unsigned_endec._debug(" - tag: %r, %r", tag, tag.tagData) obj = Unsigned(v) if _debug: unsigned_endec._debug(" - obj: %r, %r", obj, obj.value) assert unsigned_encode(obj) == tag assert unsigned_decode(tag) == obj
def ReadPropertyToAny(obj, propertyIdentifier, propertyArrayIndex=None): """Read the specified property of the object, with the optional array index, and cast the result into an Any object.""" if _debug: ReadPropertyToAny._debug("ReadPropertyToAny %s %r %r", obj, propertyIdentifier, propertyArrayIndex) # get the datatype datatype = obj.get_datatype(propertyIdentifier) if _debug: ReadPropertyToAny._debug(" - datatype: %r", datatype) if datatype is None: raise ExecutionError(errorClass='property', errorCode='datatypeNotSupported') # get the value value = obj.ReadProperty(propertyIdentifier, propertyArrayIndex) if _debug: ReadPropertyToAny._debug(" - value: %r", value) if value is None: raise ExecutionError(errorClass='property', errorCode='unknownProperty') # change atomic values into something encodeable if issubclass(datatype, Atomic): value = datatype(value) elif issubclass(datatype, Array) and (propertyArrayIndex is not None): if propertyArrayIndex == 0: value = Unsigned(value) elif issubclass(datatype.subtype, Atomic): value = datatype.subtype(value) elif not isinstance(value, datatype.subtype): raise TypeError("invalid result datatype, expecting %s and got %s" \ % (datatype.subtype.__name__, type(value).__name__)) elif not isinstance(value, datatype): raise TypeError("invalid result datatype, expecting %s and got %s" \ % (datatype.__name__, type(value).__name__)) if _debug: ReadPropertyToAny._debug(" - encodeable value: %r", value) # encode the value result = Any() result.cast_in(value) if _debug: ReadPropertyToAny._debug(" - result: %r", result) # return the object return result
def test_unsigned_endec(self): if _debug: TestUnsigned._debug("test_unsigned_endec") with self.assertRaises(InvalidTag): obj = Unsigned(unsigned_tag('')) unsigned_endec(0, '00') unsigned_endec(1, '01') unsigned_endec(127, '7f') unsigned_endec(128, '80') unsigned_endec(255, 'ff') unsigned_endec(32767, '7fff') unsigned_endec(32768, '8000') unsigned_endec(8388607, '7fffff') unsigned_endec(8388608, '800000') unsigned_endec(2147483647, '7fffffff') unsigned_endec(2147483648, '80000000')
def unsigned_statement(value): if _debug: unsigned_statement._debug("unsigned_statement %r", value) return Unsigned(int(value))
if "deviceType" in info: ai_obj._values["deviceType"] = CharacterString( info["deviceType"]) ai_obj._values["units"] = EngineeringUnits("noUnits") if "updateInterval" in info: try: updateInterval = int(info["updateInterval"]) if updateInterval < 0: raise ValueError("Invalid negative value :" + info["updateInterval"]) except ValueError as e: print( "Value of updateInterval in section {}: {}".format( metersection, e)) exit(1) ai_obj._values["updateInterval"] = Unsigned(updateInterval) if "resolution" in info: try: resolution = float(info["resolution"]) except ValueError as e: print( "Value of updateInterval in section {}: {}".format( metersection, e)) exit(1) ai_obj._values["resolution"] = Real(resolution) this_application.add_object(ai_obj) ai_objs.append(ai_obj) idx += 1 for m in meters_active:
def is_valid(cls, arg): """Return True if arg is valid value for the class.""" return Unsigned.is_valid(arg) and (0 <= arg <= 65535)
def test_unsigned_copy(self): if _debug: TestUnsigned._debug("test_unsigned_copy") obj1 = Unsigned(12) obj2 = Unsigned(obj1) assert obj2.value == 12
def run(self): if _debug: WritePointListThread._debug("run") global this_application prop_id = "presentValue" # loop through the points print("points in thread :", self.point_list) for obj_type, obj_inst, value in self.point_list: datatype = get_datatype(obj_type, prop_id) if not datatype: raise ValueError("invalid property for object type") # build a request # change atomic values into something encodeable, null is a special case if (value == 'null'): value = Null() elif issubclass(datatype, AnyAtomic): dtype, dvalue = value.split(':') if _debug: ReadWritePropertyConsoleCmd._debug( " - dtype, dvalue: %r, %r", dtype, dvalue) datatype = { 'b': Boolean, 'u': lambda x: Unsigned(int(x)), 'i': lambda x: Integer(int(x)), 'r': lambda x: Real(float(x)), 'd': lambda x: Double(float(x)), 'o': OctetString, 'c': CharacterString, 'bs': BitString, 'date': Date, 'time': Time, }[dtype] if _debug: ReadWritePropertyConsoleCmd._debug(" - datatype: %r", datatype) value = datatype(dvalue) if _debug: ReadWritePropertyConsoleCmd._debug(" - value: %r", value) elif issubclass(datatype, Atomic): if datatype is Integer: value = int(value) elif datatype is Real: value = float(value) elif datatype is Unsigned: value = int(value) value = datatype(value) elif issubclass(datatype, Array) and (indx is not None): if indx == 0: value = Integer(value) elif issubclass(datatype.subtype, Atomic): value = datatype.subtype(value) elif not isinstance(value, datatype.subtype): raise TypeError("invalid result datatype, expecting %s" % (datatype.subtype.__name__, )) elif not isinstance(value, datatype): raise TypeError("invalid result datatype, expecting %s" % (datatype.__name__, )) if _debug: ReadWritePropertyConsoleCmd._debug( " - encodeable value: %r %s", value, type(value)) # build a request request = WritePropertyRequest(destination=self.device_address, objectIdentifier=(obj_type, obj_inst), propertyIdentifier=prop_id) #request.pduDestination = Address(addr) # save the value request.propertyValue = Any() try: request.propertyValue.cast_in(value) except Exception as error: ReadWritePropertyConsoleCmd._exception( "WriteProperty cast error: %r", error) # optional array index if _debug: ReadWritePropertyConsoleCmd._debug(" - request: %r", request) # make an IOCB iocb = IOCB(request) if _debug: ReadWritePropertyConsoleCmd._debug(" - iocb: %r", iocb) # give it to the application this_application.request_io(iocb) # wait for it to complete iocb.wait() # do something for success if iocb.ioResponse: # should be an ack if not isinstance(iocb.ioResponse, SimpleAckPDU): if _debug: ReadWritePropertyConsoleCmd._debug(" - not an ack") return print(obj_inst, "ack\n") # do something for error/reject/abort if iocb.ioError: print(obj_inst, str(iocb.ioError)) if _debug: ReadPointListThread._debug(" - fini")
def test_unsigned_statement(self): if _debug: TestExtendedTagStatements._debug("test_unsigned_statement") assert statement_to_tag("unsigned 0") == tag_encode(Unsigned(0)) assert statement_to_tag("unsigned 1") == tag_encode(Unsigned(1)) assert statement_to_tag("unsigned 1 context 3") == tag_encode(Unsigned(1), context=3)
def do_write(self, args): """ write <indx> <value> write 0 <len> write [ <value> ]... """ args = args.split() ReadWritePropertyConsoleCmd._debug("do_write %r", args) try: addr, obj_type, obj_inst = context prop_id = 'eventMessageTexts' indx = None if args and args[0].isdigit(): indx = int(args[0]) if indx == 0: value = Unsigned(int(args[1])) else: value = CharacterString(args[1]) else: value = ArrayOf(CharacterString)(args[0:]) # build a request request = WritePropertyRequest(objectIdentifier=(obj_type, obj_inst), propertyIdentifier=prop_id) request.pduDestination = Address(addr) # save the value request.propertyValue = Any() try: request.propertyValue.cast_in(value) except Exception as error: ReadWritePropertyConsoleCmd._exception( "WriteProperty cast error: %r", error) # optional array index if indx is not None: request.propertyArrayIndex = indx if _debug: ReadWritePropertyConsoleCmd._debug(" - request: %r", request) # make an IOCB iocb = IOCB(request) if _debug: ReadWritePropertyConsoleCmd._debug(" - iocb: %r", iocb) # give it to the application this_application.request_io(iocb) # wait for it to complete iocb.wait() # do something for success if iocb.ioResponse: # should be an ack if not isinstance(iocb.ioResponse, SimpleAckPDU): if _debug: ReadWritePropertyConsoleCmd._debug(" - not an ack") return sys.stdout.write("ack\n") # do something for error/reject/abort if iocb.ioError: sys.stdout.write(str(iocb.ioError) + '\n') except Exception as error: ReadWritePropertyConsoleCmd._exception("exception: %r", error)
def do_write(self, args): """write <addr> <type>:<inst> <prop> <value> [ <indx> ] [ <priority> ]""" args = args.split() BacnetClientConsoleCmd._debug("do_write %r", args) try: addr, obj_id, prop_id = args[:3] obj_id = ObjectIdentifier(obj_id).value value = args[3] indx = None if len(args) >= 5: if args[4] != "-": indx = int(args[4]) if _debug: BacnetClientConsoleCmd._debug(" - indx: %r", indx) priority = None if len(args) >= 6: priority = int(args[5]) if _debug: BacnetClientConsoleCmd._debug(" - priority: %r", priority) # get the datatype datatype = get_datatype(obj_id[0], prop_id) if _debug: BacnetClientConsoleCmd._debug(" - datatype: %r", datatype) # change atomic values into something encodeable, null is a special case if (value == 'null'): value = Null() elif issubclass(datatype, AnyAtomic): dtype, dvalue = value.split(':', 1) if _debug: BacnetClientConsoleCmd._debug( " - dtype, dvalue: %r, %r", dtype, dvalue) datatype = { 'b': Boolean, 'u': lambda x: Unsigned(int(x)), 'i': lambda x: Integer(int(x)), 'r': lambda x: Real(float(x)), 'd': lambda x: Double(float(x)), 'o': OctetString, 'c': CharacterString, 'bs': BitString, 'date': Date, 'time': Time, 'id': ObjectIdentifier, }[dtype] if _debug: BacnetClientConsoleCmd._debug(" - datatype: %r", datatype) value = datatype(dvalue) if _debug: BacnetClientConsoleCmd._debug(" - value: %r", value) elif issubclass(datatype, Atomic): if datatype is Integer: value = int(value) elif datatype is Real: value = float(value) elif datatype is Unsigned: value = int(value) value = datatype(value) elif issubclass(datatype, Array) and (indx is not None): if indx == 0: value = Integer(value) elif issubclass(datatype.subtype, Atomic): value = datatype.subtype(value) elif not isinstance(value, datatype.subtype): raise TypeError("invalid result datatype, expecting %s" % (datatype.subtype.__name__, )) elif not isinstance(value, datatype): raise TypeError("invalid result datatype, expecting %s" % (datatype.__name__, )) if _debug: BacnetClientConsoleCmd._debug(" - encodeable value: %r %s", value, type(value)) # build a request request = WritePropertyRequest(objectIdentifier=obj_id, propertyIdentifier=prop_id) request.pduDestination = Address(addr) # save the value request.propertyValue = Any() try: request.propertyValue.cast_in(value) except Exception as error: BacnetClientConsoleCmd._exception( "WriteProperty cast error: %r", error) # optional array index if indx is not None: request.propertyArrayIndex = indx # optional priority if priority is not None: request.priority = priority if _debug: BacnetClientConsoleCmd._debug(" - request: %r", request) # make an IOCB iocb = IOCB(request) if _debug: BacnetClientConsoleCmd._debug(" - iocb: %r", iocb) # give it to the application this_application.request_io(iocb) # wait for it to complete iocb.wait() # do something for success if iocb.ioResponse: # should be an ack if not isinstance(iocb.ioResponse, SimpleAckPDU): if _debug: BacnetClientConsoleCmd._debug(" - not an ack") return sys.stdout.write("ack\n") # do something for error/reject/abort if iocb.ioError: sys.stdout.write(str(iocb.ioError) + '\n') except Exception as error: BacnetClientConsoleCmd._exception("exception: %r", error)
def test_boolean_application_to_object(self): if _debug: TestApplicationTag._debug("test_boolean_application_to_object") # null obj_endec(Null(), '00') # boolean obj_endec(Boolean(True), '11') obj_endec(Boolean(False), '10') # unsigned obj_endec(Unsigned(0), '2100') obj_endec(Unsigned(1), '2101') obj_endec(Unsigned(127), '217F') obj_endec(Unsigned(128), '2180') # integer obj_endec(Integer(0), '3100') obj_endec(Integer(1), '3101') obj_endec(Integer(-1), '31FF') obj_endec(Integer(128), '320080') obj_endec(Integer(-128), '3180') # real obj_endec(Real(0), '4400000000') obj_endec(Real(1), '443F800000') obj_endec(Real(-1), '44BF800000') obj_endec(Real(73.5), '4442930000') # double obj_endec(Double(0), '55080000000000000000') obj_endec(Double(1), '55083FF0000000000000') obj_endec(Double(-1), '5508BFF0000000000000') obj_endec(Double(73.5), '55084052600000000000') # octet string obj_endec(OctetString(xtob('')), '60') obj_endec(OctetString(xtob('01')), '6101') obj_endec(OctetString(xtob('0102')), '620102') obj_endec(OctetString(xtob('010203040506')), '6506010203040506') # character string obj_endec(CharacterString(''), '7100') obj_endec(CharacterString('a'), '720061') obj_endec(CharacterString('abcde'), '7506006162636465') # bit string obj_endec(BitString([]), '8100') obj_endec(BitString([0]), '820700') obj_endec(BitString([1]), '820780') obj_endec(BitString([1, 1, 1, 1, 1]), '8203F8') obj_endec(BitString([1] * 10), '8306FFC0') # enumerated obj_endec(Enumerated(0), '9100') obj_endec(Enumerated(1), '9101') obj_endec(Enumerated(127), '917F') obj_endec(Enumerated(128), '9180') # date obj_endec(Date((1, 2, 3, 4)), 'A401020304') obj_endec(Date((255, 2, 3, 4)), 'A4FF020304') obj_endec(Date((1, 255, 3, 4)), 'A401FF0304') obj_endec(Date((1, 2, 255, 4)), 'A40102FF04') obj_endec(Date((1, 2, 3, 255)), 'A4010203FF') # time obj_endec(Time((1, 2, 3, 4)), 'B401020304') obj_endec(Time((255, 2, 3, 4)), 'B4FF020304') obj_endec(Time((1, 255, 3, 4)), 'B401FF0304') obj_endec(Time((1, 2, 255, 4)), 'B40102FF04') obj_endec(Time((1, 2, 3, 255)), 'B4010203FF') # object identifier obj_endec(ObjectIdentifier(0, 0), 'C400000000') obj_endec(ObjectIdentifier(1, 0), 'C400400000') obj_endec(ObjectIdentifier(0, 2), 'C400000002') obj_endec(ObjectIdentifier(3, 4), 'C400C00004')
def main(): if not path.exists("server.cfg"): logger.error("Error: File server.cfg not found.") exit(1) cparser = configparser.ConfigParser() cparser.read("server.cfg") if not "server" in cparser: logger.error("Invalid config: No server section") exit(1) required_keys = { "ip", "port", "objectname", "vendoridentifier", "location", "vendorname", "modelname", "description" } missing_keys = required_keys - set(cparser["server"].keys()) if len(missing_keys) != 0: logger.error("Missing config keys in server section: " + (" ".join(missing_keys))) exit(1) device_info = { 'ip': cparser["server"]["ip"], 'netmask': 23, 'port': cparser["server"]["port"], 'objectName': cparser["server"]["objectName"], 'objectIdentifier': 522020, 'vendorIdentifier': int(cparser["server"]["vendorIdentifier"]), 'location': cparser["server"]["location"], 'vendorName': cparser["server"]["vendorName"], 'modelName': cparser["server"]["modelName"], 'softwareVersion': "bacpypes_{}_python{}.{}.{}".format(bacpypes_version, version_info[0], version_info[1], version_info[2]), 'description': cparser["server"]["description"] } logger.info("=== INIT ===") logger.info(device_info) this_device = LocalDeviceObject( objectName=device_info["objectName"], objectIdentifier=device_info["objectIdentifier"], vendorIdentifier=device_info["vendorIdentifier"]) this_device._values['location'] = CharacterString(device_info['location']) this_device._values['vendorName'] = CharacterString( device_info['vendorName']) this_device._values['modelName'] = CharacterString( device_info['modelName']) this_device._values['applicationSoftwareVersion'] = CharacterString( device_info['softwareVersion']) this_device._values['description'] = CharacterString( device_info['description']) this_addr = str(device_info['ip'] + '/' + str(device_info['netmask']) + ':' + str(device_info['port'])) logger.info("bacnet server will listen at {}".format(this_addr)) this_application = BIPSimpleApplication(this_device, this_addr) this_application.add_capability(ReadWritePropertyMultipleServices) this_device.protocolServicesSupported = this_application.get_services_supported( ).value meters_active = [] ai_objs = [] idx = 1 logger.info("Initializing meters...") for key, metermodule in METERS.items(): if not key in cparser["server"]: logger.warning( "No key '{}' in config server section. Skipping".format(key)) continue metersections = cparser["server"][key].split() missing_metersections = set(metersections) - set(cparser.keys()) if len(missing_metersections) != 0: logger.error("Missing config sections for meters: " + "".join(missing_metersections)) exit(1) for metersection in metersections: info = cparser[metersection] ms = metermodule.getMeters(info) logger.info("Got {} meter(s) from {}".format( len(ms), metersection)) meters_active.extend(ms) for m in ms: m.name = "{}_{}".format(metersection, m.name) ai_obj = AnalogInputObject(objectIdentifier=("analogInput", idx), objectName=m.name) if "description" in info: ai_obj._values["description"] = CharacterString( info["description"]) if "deviceType" in info: ai_obj._values["deviceType"] = CharacterString( info["deviceType"]) ai_obj._values["units"] = EngineeringUnits("noUnits") if "updateInterval" in info: try: updateInterval = int(info["updateInterval"]) if updateInterval < 0: raise ValueError("Invalid negative value :" + info["updateInterval"]) except ValueError as e: logger.error( "Value of updateInterval in section {}: {}".format( metersection, e)) exit(1) ai_obj._values["updateInterval"] = Unsigned(updateInterval) if "resolution" in info: try: resolution = float(info["resolution"]) except ValueError as e: logger.error( "Value of updateInterval in section {}: {}".format( metersection, e)) exit(1) ai_obj._values["resolution"] = Real(resolution) this_application.add_object(ai_obj) ai_objs.append(ai_obj) idx += 1 fname = m.name output_csv = os.path.join(str('/var/www/html'), fname + u".csv") mode = 'a' if sys.version_info.major < 3: mode += 'b' with open(output_csv, mode) as f: header = OrderedDict([('# time', None), (m.name, None)]) writer = csv.DictWriter(f, fieldnames=header, extrasaction=u"ignore") writer.writeheader() f.close() for m in meters_active: m.start() datathread = DataThread(meters_active, ai_objs) datathread.start() bacpypesrun() datathread.stop() datathread.join() for m in meters_active: m.stop() m.join()
def main(): device_info = { 'ip': '10.169.204.200', 'netmask': 23, 'port': 47809, 'objectName': 'FHL-DAF-DUSTMETER', 'objectIdentifier': 522020, 'vendorIdentifier': 15, 'location': 'FHL-DAF-CLEAN-ROOM', 'vendorName': 'DESY-ATLAS', 'modelName': 'DUST-METERS', 'softwareVersion': 'bacpypes_v0.16.2_py27', 'description': 'FHL-DAF clean room dustmeter server' } print device_info this_device = LocalDeviceObject( objectName=device_info['objectName'], objectIdentifier=device_info['objectIdentifier'], vendorIdentifier=device_info['vendorIdentifier']) this_device._values['location'] = CharacterString(device_info['location']) this_device._values['vendorName'] = CharacterString( device_info['vendorName']) this_device._values['modelName'] = CharacterString( device_info['modelName']) this_device._values['applicationSoftwareVersion'] = CharacterString( device_info['softwareVersion']) this_device._values['description'] = CharacterString( device_info['description']) this_addr = str(device_info['ip'] + '/' + str(device_info['netmask']) + ':' + str(device_info['port'])) print 'bacnet server will listen at', this_addr this_application = BIPSimpleApplication(this_device, this_addr) this_application.add_capability(ReadWritePropertyMultipleServices) this_device.protocolServicesSupported = this_application.get_services_supported( ).value meter_info = [ { 'name': 'dustmeter_a19', 'index': 1, 'host': 'fhlrs232_a19.desy.de', 'description': 'dustmeter on RS232-Ethernet bridge at somewhere', }, { 'name': 'dustmeter_a27', 'index': 2, 'host': 'fhlrs232_a27.desy.de', 'description': 'dustmeter on RS232-Ethernet bridge at somewhere', }, { 'name': 'dustmeter_a40', 'index': 3, 'host': 'fhlrs232_a40.desy.de', 'description': 'dustmeter on RS232-Ethernet bridge at somewhere', }, { 'name': 'dustmeter_a43', 'index': 4, 'host': 'fhlrs232_a43.desy.de', 'description': 'dustmeter on RS232-Ethernet bridge at somewhere', }, { 'name': 'dustmeter_a49', 'index': 5, 'host': 'fhlrs232_a49.desy.de', 'description': 'dustmeter on RS232-Ethernet bridge at somewhere', }, { 'name': 'dustmeter_a56', 'index': 6, 'host': 'fhlrs232_a56.desy.de', 'description': 'dustmeter on RS232-Ethernet bridge at somewhere', }, ] meters = [] for info in meter_info: m = dustmeter.DustMeter(name=info['name'], host=info['host']) m.start() meters.append(m) objs = [] for info in meter_info: ai_obj = AnalogInputObject(objectIdentifier=('analogInput', info['index']), \ objectName=info['name']) ai_obj._values['description'] = CharacterString(info['description']) ai_obj._values['deviceType'] = CharacterString( 'Particles(>0.5um) PerCubicFoot') ai_obj._values['units'] = EngineeringUnits('noUnits') ai_obj._values['updateInterval'] = Unsigned(60) ai_obj._values['resolution'] = Real(100) this_application.add_object(ai_obj) objs.append(ai_obj) mythread = dataThread(meters, objs) mythread.start() run() mythread.stop() mythread.join() for m in meters: m.stop() m.join() print "end of join"