def start(self, xbee_ddo_cfg): """ Start up our channel and configure it to our initial parameters. .. note: This function will take the passed in 'xbee_ddo_cfg' variable, and add parameters to it as needed to configure the channel into the proper mode. Returns bool. """ self.__dia_device_obj.add_property( ChannelSourceDeviceProperty(name = "channel%d_value" % (self.__channel + 1), type = float, initial = Sample(timestamp = 0, unit = "V", value = 0.0), perms_mask = DPROP_PERM_GET|DPROP_PERM_REFRESH, options = DPROP_OPT_AUTOTIMESTAMP, refresh_cb = self.__parent.refresh)) if self.__mode == self.LOCAL_AIO_MODE_CURRENTLOOP: digihw.configure_channel(self.__channel, AIO_HW_MODE_CURRENTLOOP) elif self.__mode == self.LOCAL_AIO_MODE_TENV: digihw.configure_channel(self.__channel, AIO_HW_MODE_TENV) xbee_ddo_cfg.add_parameter(self.LOCAL_AIO_CONTROL_LINES[self.__channel], XBEE_SERIES2_AIO_MODE) return True
def set_output(self, sample, io_pin): """\ This callback function sets whether our output mode is High (True), or Low (False). """ new_val = False # Attempt to convert the give sample to a bool. # If we take an Exception, simply don't change anything, # and leave. try: new_val = bool(sample.value) except: return # Decide upon our output mode. High = True, Low = False. if new_val == True: hw_val = DIO_HW_MODE_OUTPUT_HIGH ddo_val = XBEE_SERIES2_DIGITAL_OUTPUT_HIGH_MODE else: hw_val = DIO_HW_MODE_OUTPUT_LOW ddo_val = XBEE_SERIES2_DIGITAL_OUTPUT_LOW_MODE # Attempt the mode change now. try: digihw.configure_channel(self.__channel, hw_val) self.__xbee_manager.xbee_device_ddo_set_param( None, self.LOCAL_DIO_CONTROL_LINES[self.__channel], ddo_val, apply=True ) except: self.__tracer.error("Exception setting output '%s'", str(e)) property = "channel%d_output" % (self.__channel + 1) self.__dia_device_obj.property_set(property, Sample(0, new_val, "bool"))
def start(self, xbee_ddo_cfg): """\ Start up our channel and configure it to our initial parameters. .. note: This function will take the passed in 'xbee_ddo_cfg' variable, and add parameters to it as needed to configure the channel into the proper mode. Returns bool. """ # For all XBee-based DIO channels, they all can and do report their # input value, regardless of whether the channels is set to input # or output. self.__dia_device_obj.add_property( ChannelSourceDeviceProperty(name='channel%d_input' % (self.__channel + 1), type=bool, initial=Sample(timestamp=0, value=False, unit='bool'), perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP)) if self.__mode == 'in': digihw.configure_channel(self.__channel, DIO_HW_MODE_INPUT) xbee_ddo_cfg.add_parameter( self.LOCAL_DIO_CONTROL_LINES[self.__channel], XBEE_SERIES2_DIGITAL_INPUT_MODE) elif self.__mode == 'out': self.__dia_device_obj.add_property( ChannelSourceDeviceProperty( name='channel%d_output' % (self.__channel + 1), type=bool, initial=Sample(timestamp=0, value=False, unit='bool'), perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET), options=DPROP_OPT_AUTOTIMESTAMP, set_cb=lambda sample, io=self.__channel: self.set_output( sample, io))) # If set, subscribe to the channel that drives our output logic: if len(self.__source): cm = self.__dia_device_obj.__core.get_service( "channel_manager") cp = cm.channel_publisher_get() cp.subscribe( source, lambda chan, io=self.__channel: self.update(chan, io)) return True
def start(self, xbee_ddo_cfg): """\ Start up our channel and configure it to our initial parameters. .. note: This function will take the passed in 'xbee_ddo_cfg' variable, and add parameters to it as needed to configure the channel into the proper mode. Returns bool. """ # For all XBee-based DIO channels, they all can and do report their # input value, regardless of whether the channels is set to input # or output. self.__dia_device_obj.add_property( ChannelSourceDeviceProperty( name="channel%d_input" % (self.__channel + 1), type=bool, initial=Sample(timestamp=0, value=False, unit="bool"), perms_mask=DPROP_PERM_GET, options=DPROP_OPT_AUTOTIMESTAMP, ) ) if self.__mode == "in": digihw.configure_channel(self.__channel, DIO_HW_MODE_INPUT) xbee_ddo_cfg.add_parameter(self.LOCAL_DIO_CONTROL_LINES[self.__channel], XBEE_SERIES2_DIGITAL_INPUT_MODE) elif self.__mode == "out": self.__dia_device_obj.add_property( ChannelSourceDeviceProperty( name="channel%d_output" % (self.__channel + 1), type=bool, initial=Sample(timestamp=0, value=False, unit="bool"), perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET), options=DPROP_OPT_AUTOTIMESTAMP, set_cb=lambda sample, io=self.__channel: self.set_output(sample, io), ) ) # If set, subscribe to the channel that drives our output logic: if len(self.__source): cm = self.__dia_device_obj.__core.get_service("channel_manager") cp = cm.channel_publisher_get() cp.subscribe(source, lambda chan, io=self.__channel: self.update(chan, io)) return True
def set_output(self, sample, io_pin): new_val = False try: new_val = bool(sample.value) except: pass ddo_val = self.DIO_MODE_OUTPUT_LOW if new_val: ddo_val = self.DIO_MODE_OUTPUT_HIGH try: digihw.configure_channel(io_pin, ddo_val) except: self.__tracer.error("Error setting output '%s'", str(e)) property = "channel%d_output" % (io_pin + 1) self.property_set(property, Sample(0, new_val, "bool"))
def configure(self, channel, mode): """configure(channel, mode) - Define channel usage channel - Channel number to be configured. mode - One of (CurrentLoop, TenV) """ if channel >= len(input_lines): raise ValueError, "Unrecognized channel" if digihw.get_channel_type(channel) != Analog: raise ValueError, "Not an analog input channel" if mode == CurrentLoop or mode == TenV: digihw.configure_channel(channel, mode) self.XBeeCommandSet(input_lines[channel], 2) else: raise ValueError, "Unrecognized mode" self.channels[channel] = mode
def configure_channel(self, mode): """ Configure/Reconfigure our channel to the given mode. The mode is assumed checked and correct before calling this function. """ # Ensure that we are NOT in calibration mode. self.turn_off_calibration_series2() if mode == self.LOCAL_AIO_MODE_CURRENTLOOP: digihw.configure_channel(self.__channel, AIO_HW_MODE_CURRENTLOOP) elif mode == self.LOCAL_AIO_MODE_TENV: digihw.configure_channel(self.__channel, AIO_HW_MODE_TENV) self.__xbee_manager.xbee_device_ddo_set_param(None, self.LOCAL_AIO_CONTROL_LINES[self.__channel], XBEE_SERIES2_AIO_MODE, apply = True) self.__mode = mode
def configure(self, channel, mode, highlow=0): """ configure(channel, mode, highlow) - Define channel usage channel - Channel number to be configured. mode - One of (Input, Output) highlow - If in Output mode, this specifies whether the signal should be driven high or low. """ if channel >= len(control_lines): raise ValueError, "Unrecognized channel" if digihw.get_channel_type(channel) != Digital: raise ValueError, "Not a digital channel" # XBee pin is always a digital input self.XBeeCommandSet(control_lines[channel], 3) if mode == Output and highlow == 0: digihw.configure_channel(channel, Mode_OutputLow) else: digihw.configure_channel(channel, Mode_Input)
def set_output(self, sample, io_pin): """\ This callback function sets whether our output mode is High (True), or Low (False). """ new_val = False # Attempt to convert the give sample to a bool. # If we take an Exception, simply don't change anything, # and leave. try: new_val = bool(sample.value) except: return # Decide upon our output mode. High = True, Low = False. if new_val == True: hw_val = DIO_HW_MODE_OUTPUT_HIGH ddo_val = XBEE_SERIES2_DIGITAL_OUTPUT_HIGH_MODE else: hw_val = DIO_HW_MODE_OUTPUT_LOW ddo_val = XBEE_SERIES2_DIGITAL_OUTPUT_LOW_MODE # Attempt the mode change now. try: digihw.configure_channel(self.__channel, hw_val) self.__xbee_manager.xbee_device_ddo_set_param( None, self.LOCAL_DIO_CONTROL_LINES[self.__channel], ddo_val, apply=True) except: self.__tracer.error("Exception setting output '%s'", str(e)) property = "channel%d_output" % (self.__channel + 1) self.__dia_device_obj.property_set(property, Sample(0, new_val, "bool"))
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Attempt to detect if we are on older units that require a different # algorithm for determine calibration. try: device_info = query_state("device_info") for item in device_info: hardware_strapping = item.find('hardwarestrapping') if hardware_strapping != None: hardware_strapping = hardware_strapping.text break else: hardware_strapping = '' if hardware_strapping == self.LOCAL_AIO_R1_STRAPPING_A or hardware_strapping == self.LOCAL_AIO_R1_STRAPPING_B: self.__tracer.info("Old hardware detected. Turning on old support flag.") self.__OLD_HARDWARE = True except: pass # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Create a callback specification that calls back this driver when # our device has left the configuring state and has transitioned # to the running state: xbdm_running_event_spec = XBeeDeviceManagerRunningEventSpec() xbdm_running_event_spec.cb_set(self.running_indication) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_running_event_spec) extended_address = None # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) for io_pin in range(4): # I/O pin for analog input: xbee_ddo_cfg.add_parameter('D%d' % (io_pin), 2) mode = SettingsBase.get_setting(self, 'channel%d_mode' % (io_pin+1) ) mode = self.LOCAL_AIO_MODE_MAP[mode.lower()] if mode == self.LOCAL_AIO_MODE_CURRENTLOOP: digihw.configure_channel(io_pin, 1) xbee_ddo_cfg.add_parameter(self.LOCAL_AIO_CONTROL_LINES[io_pin], 2) elif mode == self.LOCAL_AIO_MODE_TENV: digihw.configure_channel(io_pin, 2) xbee_ddo_cfg.add_parameter(self.LOCAL_AIO_CONTROL_LINES[io_pin], 2) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Create a callback specification that calls back this driver when # our device has left the configuring state and has transitioned # to the running state: xbdm_running_event_spec = XBeeDeviceManagerRunningEventSpec() xbdm_running_event_spec.cb_set(self.running_indication) self.__xbee_manager.xbee_device_event_spec_add( self, xbdm_running_event_spec) extended_address = None my_address = ':'.join( ["%02x" % ord(b) for b in ''.join(gw_extended_address_tuple())]) my_address = '[' + my_address + ']!' # Create a callback specification for our device address, endpoint # Digi XBee profile and sample cluster id: xbdm_rx_event_spec = XBeeDeviceManagerRxEventSpec() xbdm_rx_event_spec.cb_set(self.sample_indication) xbdm_rx_event_spec.match_spec_set((my_address, 0xe8, 0xc105, 0x92), (False, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # Configure pins DIO0 .. DIO3 for digital input: pr = 0xe1 # DIO0-3 pullups off, all else on ic = 0 for io_pin in range(4): dir = SettingsBase.get_setting(self, 'channel%d_dir' % (io_pin + 1)) dir = dir.lower() # Enable input on all pins: xbee_ddo_cfg.add_parameter(self.DIO_CONTROL_LINES[io_pin], 3) # Build our change detection mask for all io pins: ic |= 1 << self.INPUT_CHANNEL_TO_PIN[io_pin] if dir == 'in': # Disable sinking driver output: pass elif dir == 'out': # Create the output channel for this IO pin: self.add_property( ChannelSourceDeviceProperty( name='channel%d_output' % (io_pin+1), type=bool, initial=Sample(timestamp=0, value=False, unit='bool'), perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET), options=DPROP_OPT_AUTOTIMESTAMP, set_cb=lambda sample, io=io_pin: \ self.set_output(sample, io) ) ) # Set initial value of output to low: digihw.configure_channel(io_pin, self.DIO_MODE_OUTPUT_LOW) # If set, subscribe to the channel that drives our output logic: source = SettingsBase.get_setting( self, 'channel%d_source' % (io_pin + 1)) if len(source): if source == "True": sample = Sample(digitime.time(), Boolean(True, style=STYLE_TF)) self.set_output(sample, io_pin) elif source == "False": sample = Sample(digitime.time(), Boolean(False, style=STYLE_TF)) self.set_output(sample, io_pin) else: cm = self.__core.get_service("channel_manager") cp = cm.channel_publisher_get() cp.subscribe( source, lambda chan, io=io_pin: self.update(chan, io)) # Enable I/O line monitoring on pins DIO0 .. DIO3 & # enable change detection on DIO11: # # 0x 8 0 0 # 1000 0000 0000 (b) # DDDD DDDD DDDD # IIII IIII IIII # OOOO OOOO OOOO # 1198 7654 3210 # 10 # xbee_ddo_cfg.add_parameter('IC', ic) # Disable any periodic I/O sampling: xbee_ddo_cfg.add_parameter('IR', 0) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Create a callback specification that calls back this driver when # our device has left the configuring state and has transitioned # to the running state: xbdm_running_event_spec = XBeeDeviceManagerRunningEventSpec() xbdm_running_event_spec.cb_set(self.running_indication) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_running_event_spec) extended_address = None my_address = ':'.join(["%02x"%ord(b) for b in ''.join(gw_extended_address_tuple())]) my_address = '[' + my_address + ']!' # Create a callback specification for our device address, endpoint # Digi XBee profile and sample cluster id: xbdm_rx_event_spec = XBeeDeviceManagerRxEventSpec() xbdm_rx_event_spec.cb_set(self.sample_indication) xbdm_rx_event_spec.match_spec_set((my_address, 0xe8, 0xc105, 0x92), (False, True, True, True)) self.__xbee_manager.xbee_device_event_spec_add(self, xbdm_rx_event_spec) # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) # Get the gateway's extended address: gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple() # Set the destination for I/O samples to be the gateway: xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh) xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl) # Configure pins DIO0 .. DIO3 for digital input: pr = 0xe1 # DIO0-3 pullups off, all else on ic = 0 for io_pin in range(4): dir = SettingsBase.get_setting(self, 'channel%d_dir' % (io_pin+1) ) dir = dir.lower() # Enable input on all pins: xbee_ddo_cfg.add_parameter(self.DIO_CONTROL_LINES[io_pin], 3) # Build our change detection mask for all io pins: ic |= 1 << self.INPUT_CHANNEL_TO_PIN[io_pin] if dir == 'in': # Disable sinking driver output: pass elif dir == 'out': # Create the output channel for this IO pin: self.add_property( ChannelSourceDeviceProperty( name='channel%d_output' % (io_pin+1), type=bool, initial=Sample(timestamp=0, value=False, unit='bool'), perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET), options=DPROP_OPT_AUTOTIMESTAMP, set_cb=lambda sample, io=io_pin: \ self.set_output(sample, io) ) ) # Set initial value of output to low: digihw.configure_channel(io_pin, self.DIO_MODE_OUTPUT_LOW) # If set, subscribe to the channel that drives our output logic: source = SettingsBase.get_setting(self, 'channel%d_source' % (io_pin+1)) if len(source): if source == "True": sample = Sample(digitime.time(), Boolean(True, style=STYLE_TF)) self.set_output(sample, io_pin) elif source == "False": sample = Sample(digitime.time(), Boolean(False, style=STYLE_TF)) self.set_output(sample, io_pin) else: cm = self.__core.get_service("channel_manager") cp = cm.channel_publisher_get() cp.subscribe(source, lambda chan, io=io_pin: self.update(chan, io)) # Enable I/O line monitoring on pins DIO0 .. DIO3 & # enable change detection on DIO11: # # 0x 8 0 0 # 1000 0000 0000 (b) # DDDD DDDD DDDD # IIII IIII IIII # OOOO OOOO OOOO # 1198 7654 3210 # 10 # xbee_ddo_cfg.add_parameter('IC', ic) # Disable any periodic I/O sampling: xbee_ddo_cfg.add_parameter('IR', 0) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True
def start(self): # Fetch the XBee Manager name from the Settings Manager: xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager") dm = self.__core.get_service("device_driver_manager") self.__xbee_manager = dm.instance_get(xbee_manager_name) # Attempt to detect if we are on older units that require a different # algorithm for determine calibration. try: device_info = query_state("device_info") for item in device_info: hardware_strapping = item.find('hardwarestrapping') if hardware_strapping != None: hardware_strapping = hardware_strapping.text break else: hardware_strapping = '' if hardware_strapping == self.LOCAL_AIO_R1_STRAPPING_A or hardware_strapping == self.LOCAL_AIO_R1_STRAPPING_B: self.__tracer.info( "Old hardware detected. Turning on old support flag.") self.__OLD_HARDWARE = True except: pass # Register ourselves with the XBee Device Manager instance: self.__xbee_manager.xbee_device_register(self) # Create a callback specification that calls back this driver when # our device has left the configuring state and has transitioned # to the running state: xbdm_running_event_spec = XBeeDeviceManagerRunningEventSpec() xbdm_running_event_spec.cb_set(self.running_indication) self.__xbee_manager.xbee_device_event_spec_add( self, xbdm_running_event_spec) extended_address = None # Create a DDO configuration block for this device: xbee_ddo_cfg = XBeeConfigBlockDDO(extended_address) for io_pin in range(4): # I/O pin for analog input: xbee_ddo_cfg.add_parameter('D%d' % (io_pin), 2) mode = SettingsBase.get_setting(self, 'channel%d_mode' % (io_pin + 1)) mode = self.LOCAL_AIO_MODE_MAP[mode.lower()] if mode == self.LOCAL_AIO_MODE_CURRENTLOOP: digihw.configure_channel(io_pin, 1) xbee_ddo_cfg.add_parameter( self.LOCAL_AIO_CONTROL_LINES[io_pin], 2) elif mode == self.LOCAL_AIO_MODE_TENV: digihw.configure_channel(io_pin, 2) xbee_ddo_cfg.add_parameter( self.LOCAL_AIO_CONTROL_LINES[io_pin], 2) # Register this configuration block with the XBee Device Manager: self.__xbee_manager.xbee_device_config_block_add(self, xbee_ddo_cfg) # Indicate that we have no more configuration to add: self.__xbee_manager.xbee_device_configure(self) return True