def main(): # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) # add an argument for interval parser.add_argument( 'interval', type=int, help='repeat rate in seconds', ) # now parse the 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 dog this_application = PrairieDog(args.interval, this_device, args.ini.address) if _debug: _log.debug(" - this_application: %r", this_application) _log.debug("running") run() _log.debug("fini")
def main(): global args, this_application # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) # add an option to override the interval time parser.add_argument( '--interval', type=float, help="amount of time between intervals", default=INTERVAL, ) # 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 simple application this_application = ReadPointListApplication(this_device, args.ini.address) _log.debug("running") run() _log.debug("fini")
def getData(collection): global this_application, device_address, object_identifier, property_list # 清空数组 global result, tag_list, tag_keys, count print collection result = [] tag_list = [] tag_keys = {} count = 0 parser = ConfigArgumentParser(description=__doc__) args = parser.parse_args() tag_list = collection["bacnet_items"] try: this_device = LocalDeviceObject(ini=args.ini) this_application = ReadPropertyApplication(this_device, args.ini.address) deferred(this_application.requests) run() this_application.close_socket() except Exception as e: print str(e) return {"data": "采集失败", "success": "false"} import datetime dt = datetime.datetime.now() timestamp = dt.strftime("%Y-%m-%d %H:%M:%S") for item in tag_keys: result.append({ "timestamp": timestamp, "value": None, "item": tag_keys[item]['tag'], "quality": "Error" }) return {"data": result, "success": "true"}
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 main(): global args # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) # add an option to override the sleep time parser.add_argument( '--sleep', type=float, help="sleep before returning the value", default=SLEEP_TIME, ) # 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( objectName=args.ini.objectname, objectIdentifier=('device', int(args.ini.objectidentifier)), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # get the services supported services_supported = this_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know this_device.protocolServicesSupported = services_supported.value # make some random input objects for i in range(1, RANDOM_OBJECT_COUNT + 1): ravo = RandomAnalogValueObject( objectIdentifier=('analogValue', i), objectName='Random-%d' % (i, ), ) _log.debug(" - ravo: %r", ravo) this_application.add_object(ravo) # make sure they are all there _log.debug(" - object list: %r", this_device.objectList) _log.debug("running") run() _log.debug("fini")
def main(): global args, schedule_objects # parse the command line arguments 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) # set up testing setup_module() # reset the time machine reset_time_machine(start_time="1970-01-01") # # Simple daily schedule (actually a weekly schedule with every day # being identical. # so = LocalScheduleObject( objectIdentifier=('schedule', 1), objectName='Schedule 1', presentValue=Integer(5), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), weeklySchedule=ArrayOf(DailySchedule)([ DailySchedule(daySchedule=[ TimeValue(time=(8, 0, 0, 0), value=Integer(8)), TimeValue(time=(14, 0, 0, 0), value=Null()), TimeValue(time=(17, 0, 0, 0), value=Integer(42)), # TimeValue(time=(0,0,0,0), value=Null()), ]), ] * 7), scheduleDefault=Integer(0), ) _log.debug(" - so: %r", so) schedule_objects.append(so) print("{} @ {}".format(so.presentValue.value, Time().now())) for i in range(1, 25): hr = "{}:00:01".format(i) # let it run until just after midnight run_time_machine(stop_time=hr) print("{} @ {}".format(so.presentValue.value, Time().now())) # done testing teardown_module()
def main(): global this_application, context # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) parser.add_argument( "address", help="address of server", ) parser.add_argument( "objtype", help="object type", ) parser.add_argument( "objinst", type=int, help="object instance", ) args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # set the context, the collection of the above parameters context = args.address, args.objtype, args.objinst if _debug: _log.debug(" - context: %r", context) # make a device object this_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 simple application this_application = BIPSimpleApplication(this_device, args.ini.address) # get the services supported services_supported = this_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know this_device.protocolServicesSupported = services_supported.value # make a console this_console = ReadWritePropertyConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): global this_application, device_address, object_identifier, property_list # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) parser.add_argument( "address", help="device address", ) parser.add_argument( "objtype", help="object types, e.g., analogInput", ) parser.add_argument( "objinstance", type=int, help="object instance", ) args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # interpret the address device_address = Address(args.address) if _debug: _log.debug(" - device_address: %r", device_address) # build an identifier object_identifier = (args.objtype, args.objinstance) if _debug: _log.debug(" - object_identifier: %r", object_identifier) # get the object class object_class = get_object_class(args.objtype) if _debug: _log.debug(" - object_class: %r", object_class) # make a queue of the properties property_list = deque(prop.identifier for prop in object_class.properties) if _debug: _log.debug(" - property_list: %r", property_list) # make a device object this_device = LocalDeviceObject(ini=args.ini) if _debug: _log.debug(" - this_device: %r", this_device) # make a simple application this_application = ReadPropertyApplication(this_device, args.ini.address) # fire off a request when the core has a chance deferred(this_application.next_request) _log.debug("running") run() _log.debug("fini")
def main(): global this_application # parse the command line arguments args = ConfigArgumentParser(description=__doc__).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 simple application this_application = ReadPointListApplication(point_list, this_device, args.ini.address) # fire off a request when the core has a chance deferred(this_application.next_request) _log.debug("running") run() # dump out the results for request, response in zip(point_list, this_application.response_values): print(request, response) _log.debug("fini")
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 main(): # parse the command line arguments and initialize loggers args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_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), vendorName="B612", ) # make a sample application this_application = SampleApplication(this_device, args.ini.address) if _debug: _log.debug(" - this_application: %r", this_application) # get the services supported services_supported = this_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know this_device.protocolServicesSupported = services_supported.value _log.debug("running") run() _log.debug("fini")
def main(): global this_device, this_application, saved_recipent_list # parse the command line arguments args = ConfigArgumentParser(description=__doc__).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 simple application this_application = EventNotificationApplication( this_device, args.ini.address, ) if _debug: _log.debug(" - this_application: %r", this_application) # make a console this_console = EventNotificationConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): global this_application # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_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 simple application this_application = ReadPointListApplication(point_list, this_device, args.ini.address) # fire off a request when the core has a chance deferred(this_application.next_request) _log.debug("running") run() # dump out the results for request, response in zip(point_list, this_application.response_values): print(request, response) _log.debug("fini")
def main(): global this_device global this_application # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_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 simple application this_application = WhoIsIAmApplication(this_device, args.ini.address) this_application.i_am() _log.debug("running") run() stop() _log.debug("fini")
def main(): global this_application # check the version if (sys.version_info[:2] != (2, 5)): sys.stderr.write("Python 2.5 only\n") sys.exit(1) # parse the command line arguments args = ConfigArgumentParser(description=__doc__).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 simple application this_application = BIPSimpleApplication(this_device, args.ini.address) # make a console this_console = ReadPropertyConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_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 this_application = WhoIsIAmApplication(this_device, args.ini.address) _log.debug("running") run() _log.debug("fini") print("----- Who Is -----") for (src, lowlim, hilim), count in sorted(who_is_counter.items()): print("%-20s %8s %8s %4d" % (src, lowlim, hilim, count)) print("") print("----- I Am -----") for (src, devid), count in sorted(i_am_counter.items()): print("%-20s %8d %4d" % (src, devid, count)) print("")
def main(): global this_application # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a simple application this_application = WhoIsRouterApplication(args.ini.address, bbmdAddress=Address( args.ini.foreignbbmd), bbmdTTL=int(args.ini.foreignttl)) if _debug: _log.debug(" - this_application: %r", this_application) # make a console this_console = WhoIsRouterConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): global this_application # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object mstp_args = { '_address': int(args.ini.address), '_interface': str(args.ini.interface), '_max_masters': int(args.ini.max_masters), '_baudrate': int(args.ini.baudrate), '_maxinfo': int(args.ini.maxinfo), } this_device = LocalDeviceObject(ini=args.ini, **mstp_args) if _debug: _log.debug(" - this_device: %r", this_device) # make a simple application this_application = MSTPSimpleApplication(this_device, args.ini.address) # make a console this_console = ReadPropertyMultipleConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): # parse the command line arguments args = ConfigArgumentParser(description=__doc__).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 this_application = BIPSimpleApplication(this_device, args.ini.address) # make a multistate value object msvo = MultiStateValueObject( objectIdentifier=('multiStateValue', 1), objectName='My Special Object', presentValue=1, numberOfStates=3, stateText=['red', 'green', 'blue'], ) _log.debug(" - msvo: %r", msvo) # add it to the device this_application.add_object(msvo) _log.debug(" - object list: %r", this_device.objectList) _log.debug("running") run() _log.debug("fini")
def main(): global this_application # parse the command line arguments args = ConfigArgumentParser(description=__doc__).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 simple application this_application = SubscribeCOVApplication(this_device, args.ini.address) # make a subscription context context = SubscriptionContext(Address("10.0.1.31"), ('analogValue', 1), False, 60) # send the subscription when the stack is ready deferred(this_application.send_subscription, context) _log.debug("running") run() _log.debug("fini")
def main(): global this_application # parse the command line arguments args = ConfigArgumentParser(description=__doc__).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 simple application this_application = BIPSimpleApplication(this_device, args.ini.address) # make a console this_console = ReadWritePropertyConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): global this_application # parse the command line arguments args = ConfigArgumentParser(description=__doc__).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 simple application this_application = BIPSimpleApplication(this_device, args.ini.address) # create a thread and read_thread = ReadPointListThread(point_list) if _debug: _log.debug(" - read_thread: %r", read_thread) # start it running when the core is running deferred(read_thread.start) _log.debug("running") run() # dump out the results for request, response in zip(point_list, read_thread.response_values): print(request, response) _log.debug("fini")
def main(): global vendor_id # parse the command line arguments args = ConfigArgumentParser(description=__doc__).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 this_application = BIPSimpleApplication(this_device, args.ini.address) # make some objects ravo1 = VendorAVObject(objectIdentifier=(513, 1), objectName='Random1') if _debug: _log.debug(" - ravo1: %r", ravo1) ravo2 = VendorAVObject(objectIdentifier=(513, 2), objectName='Random2') if _debug: _log.debug(" - ravo2: %r", ravo2) # add it to the device this_application.add_object(ravo1) this_application.add_object(ravo2) if _debug: _log.debug(" - object list: %r", this_device.objectList) if _debug: _log.debug("running") run() if _debug: _log.debug("fini")
def main(): global vendor_id # parse the command line arguments args = ConfigArgumentParser(description=__doc__).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 this_application = BIPSimpleApplication(this_device, args.ini.address) # create the objects and add them to the application create_objects(this_application) # run this update when the stack is ready deferred(update_weather_data) if _debug: _log.debug("running") run() if _debug: _log.debug("fini")
def main(): global this_device, this_application # parse the command line arguments args = ConfigArgumentParser(description=__doc__).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 simple application this_application = WhoIsIAmApplication( this_device, args.ini.address, Address(args.ini.foreignbbmd), int(args.ini.foreignttl), ) if _debug: _log.debug(" - this_application: %r", this_application) # make a console this_console = WhoIsIAmConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def Init(pAddress): global this_application, this_ServerAdress this_ServerAdress = pAddress # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_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 simple application this_application = BIPSimpleApplication(this_device, args.ini.address) # get the services supported services_supported = this_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know this_device.protocolServicesSupported = services_supported.value
def main(): global this_application # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_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 simple application this_application = BIPSimpleApplication(this_device, args.ini.address) # make a console this_console = DCCConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): global this_application # parse the command line arguments args = ConfigArgumentParser(description=__doc__).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) # provide max segments accepted if any kind of segmentation supported if args.ini.segmentationsupported != 'noSegmentation': this_device.maxSegmentsAccepted = int(args.ini.maxsegmentsaccepted) # make a simple application this_application = BIPSimpleApplication(this_device, args.ini.address) if _debug: _log.debug(" - this_application: %r", this_application) # make a console this_console = ReadPropertyAnyConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): global this_device, this_application # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_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), ) if _debug: _log.debug(" - this_device: %r", this_device) # build a bit string that knows about the bit names pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 # set the property value to be just the bits this_device.protocolServicesSupported = pss.value # make a simple application this_application = WhoIsIAmApplication( this_device, args.ini.address, Address(args.ini.foreignbbmd), int(args.ini.foreignttl), ) if _debug: _log.debug(" - this_application: %r", this_application) # get the services supported services_supported = this_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know this_device.protocolServicesSupported = services_supported.value # make a console this_console = WhoIsIAmConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): global args, this_application # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) # add an option to override the interval time parser.add_argument( '--interval', type=float, help="amount of time between intervals", default=INTERVAL, ) # 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( 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 simple application this_application = ReadPointListApplication(this_device, args.ini.address) # get the services supported services_supported = this_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know this_device.protocolServicesSupported = services_supported.value _log.debug("running") run() _log.debug("fini")
request.deviceInstanceRangeHighLimit = int(args[1]) if _debug: WhoIsIAmConsoleCmd._debug(" - request: %r", request) # give it to the application this_application.request(request) except Exception, e: WhoIsIAmConsoleCmd._exception("exception: %r", e) # # __main__ # try: # parse the command line arguments arg_parser = ConfigArgumentParser(description=__doc__) arg_parser.add_argument("--address", help="Target only device(s) at <address> for request" ) arg_parser.add_argument("--range", type=int, nargs=2, metavar=('LOW', 'HIGH'), help="Lower and upper limit on device ID in results" ) arg_parser.add_argument("--timeout", type=int, metavar=('SECONDS'), help="Time, in seconds, to wait for responses. Default: %(default)s", default = 5) args = arg_parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args)
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")
value = apdu.propertyValue.cast_out(datatype) if _debug: PrairieDog._debug(" - value: %r", value) # save the value self.response_values.append(value) # fire off another request deferred(self.next_request) # # __main__ # try: # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) # add an argument for interval parser.add_argument('interval', type=int, help='repeat rate in seconds', ) # now parse the arguments args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname,
def main(): # parse the command line arguments arg_parser = ConfigArgumentParser(description=__doc__) arg_parser.add_argument("device_id", type=int, help="Device ID of the target device" ) arg_parser.add_argument("--address", help="Address of target device, may be needed to help route initial request to device." ) arg_parser.add_argument("--registry-out-file", type=argparse.FileType('wb'), help="Output registry to CSV file", default=sys.stdout ) arg_parser.add_argument("--driver-out-file", type=argparse.FileType('wb'), help="Output driver configuration to JSON file.", default=sys.stdout) arg_parser.add_argument("--max-range-report", nargs='?', type=float, help='Affects how very large numbers are reported in the "Unit Details" column of the output. ' 'Does not affect driver behavior.', default=1.0e+20 ) args = arg_parser.parse_args() _log.debug("initialization") _log.debug(" - args: %r", args) # make a device object this_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 simple application this_application = SynchronousApplication(this_device, args.ini.address) _log.debug("starting build") result = get_iam(this_application, args.device_id, args.address) # request = WhoIsRequest() # request.pduDestination = target_address # result = this_application.make_request(request, expect_confirmation = False) # if not isinstance(result, IAmRequest): # result.debug_contents() # raise TypeError("Error making WhoIs request, try running again.") # device_type, device_instance = result.iAmDeviceIdentifier # if device_type != 'device': # raise DecodingError("invalid object type") target_address = result.pduSource device_id = result.iAmDeviceIdentifier[1] _log.debug('pduSource = ' + repr(result.pduSource)) _log.debug('iAmDeviceIdentifier = ' + str(result.iAmDeviceIdentifier)) _log.debug('maxAPDULengthAccepted = ' + str(result.maxAPDULengthAccepted)) _log.debug('segmentationSupported = ' + str(result.segmentationSupported)) _log.debug('vendorID = ' + str(result.vendorID)) config_file_name = basename(args.registry_out_file.name) config = { "driver_config":{"device_address":str(target_address), "device_id": device_id}, "driver_type":"bacnet", "registry_config":"config://registry_configs/{}".format(config_file_name) } json.dump(config, args.driver_out_file,indent=4) try: device_name = read_prop(this_application, target_address, "device", device_id, "objectName") _log.debug('device_name = ' + str(device_name)) except TypeError: _log.debug('device missing objectName') try: device_description = read_prop(this_application, target_address, "device", device_id, "description") _log.debug('description = ' + str(device_description)) except TypeError: _log.debug('device missing description') config_writer = DictWriter(args.registry_out_file, ('Reference Point Name', 'Volttron Point Name', 'Units', 'Unit Details', 'BACnet Object Type', 'Property', 'Writable', 'Index', 'Write Priority', 'Notes')) config_writer.writeheader() try: objectCount = read_prop(this_application, target_address, "device", device_id, "objectList", index=0) list_property = "objectList" except TypeError: objectCount = read_prop(this_application, target_address, "device", device_id, "structuredObjectList", index=0) list_property = "structuredObjectList" _log.debug('objectCount = ' + str(objectCount)) for object_index in xrange(1,objectCount+1): _log.debug('object_device_index = ' + repr(object_index)) bac_object = read_prop(this_application, target_address, "device", device_id, list_property, index=object_index) obj_type, index = bac_object try: process_object(this_application, target_address, obj_type, index, args.max_range_report, config_writer) except: _log.debug("Unexpected error processing object: {} {}".format(obj_type, index)) _log.debug(traceback.format_exc())
propertyIdentifier=prop_id) request.pduDestination = address result = this_application.make_request(request) if not isinstance(result, ReadPropertyACK): result.debug_contents(file=sys.stderr) raise TypeError("Error reading property") # find the datatype datatype = get_datatype(obj_type, prop_id) return result.propertyValue.cast_out(datatype) try: # parse the command line arguments arg_parser = ConfigArgumentParser(description=__doc__) arg_parser.add_argument("address", help="Address of target device" ) arg_parser.add_argument("out_file", nargs='?', type=argparse.FileType('wb'), help="Optional output file for configuration", default=sys.stdout ) arg_parser.add_argument("--max_range_report", nargs='?', type=float, help='Affects how very large numbers are reported in the "Unit Details" column of the output. ' 'Does not affect sMap driver behavior.', default=1.0e+20 ) args = arg_parser.parse_args() _log.debug("initialization")
# install it self.install_task() def process_task(self): if _debug: PrairieDog._debug("process_task") sys.stdout.write("%d woof!\n" % (self.dog_number,)) # # __main__ # try: # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) # add an argument for seconds per dog parser.add_argument('seconds', metavar='N', type=int, nargs='+', help='number of seconds for each dog', ) # now parse the arguments args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make some dogs for i, sec in enumerate(args.seconds): dog = PrairieDog(i, sec * 1000)