def initialize_input(self): import serial if is_device(self.input_dev.uart_location): try: self.ser = serial.Serial(port=self.input_dev.uart_location, baudrate=self.input_dev.baud_rate, timeout=1, writeTimeout=5) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". Check the device location is correct.' .format(dev=self.input_dev.uart_location)) if self.abc_enable: self.abcon() else: self.abcoff() if self.measure_range: self.set_measure_range(self.measure_range) time.sleep(0.1)
def initialize_input(self): import serial import binascii if is_device(self.input_dev.uart_location): try: self.binascii = binascii self.ser = serial.Serial(port=self.input_dev.uart_location, baudrate=self.input_dev.baud_rate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=10, writeTimeout=10) self.ser.flushInput() self.set_qa() if not self.fan_modulate: self.dormant_mode('run') time.sleep(0.1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". Check the device location is correct.' .format(dev=self.input_dev.uart_location))
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__() self.logger = logging.getLogger("mycodo.inputs.k30") self._co2 = None if not testing: import serial self.logger = logging.getLogger( "mycodo.k30_{id}".format(id=input_dev.unique_id.split('-')[0])) self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate self.convert_to_unit = input_dev.convert_to_unit # Check if device is valid self.serial_device = is_device(self.uart_location) if self.serial_device: try: self.ser = serial.Serial(self.serial_device, baudrate=self.baud_rate, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location))
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__() self.logger = logging.getLogger("mycodo.inputs.k30") if not testing: import serial self.logger = logging.getLogger( "mycodo.k30_{id}".format(id=input_dev.unique_id.split('-')[0])) self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate # Check if device is valid self.serial_device = is_device(self.uart_location) if self.serial_device: try: self.ser = serial.Serial(self.serial_device, baudrate=self.baud_rate, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location))
def initialize_input(self): if self.input_dev.interface == 'UART': import serial if is_device(self.input_dev.uart_location): try: self.ser = serial.Serial( port=self.input_dev.uart_location, timeout=1, writeTimeout=5) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.input_dev.uart_location)) elif self.input_dev.interface == 'I2C': from smbus2 import SMBus self.i2c_address = int(str(self.input_dev.i2c_location), 16) self.cmd_measure = [0xFF, 0x01, 0x9C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63] self.IOCONTROL = 0X0E << 3 self.FCR = 0X02 << 3 self.LCR = 0X03 << 3 self.DLL = 0x00 << 3 self.DLH = 0X01 << 3 self.THR = 0X00 << 3 self.RHR = 0x00 << 3 self.TXLVL = 0X08 << 3 self.RXLVL = 0X09 << 3 self.i2c = SMBus(self.input_dev.i2c_bus) self.begin()
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__() self.logger = logging.getLogger("mycodo.inputs.winsen_zh03b") self.fan_is_on = False if not testing: import serial import binascii self.logger = logging.getLogger( "mycodo.winsen_zh03b_{id}".format(id=input_dev.unique_id.split('-')[0])) self.device_measurements = db_retrieve_table_daemon( DeviceMeasurements).filter( DeviceMeasurements.device_id == input_dev.unique_id) self.binascii = binascii self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate # Check if device is valid self.serial_device = is_device(self.uart_location) self.fan_modulate = True self.fan_seconds = 50.0 if input_dev.custom_options: for each_option in input_dev.custom_options.split(';'): option = each_option.split(',')[0] value = each_option.split(',')[1] if option == 'fan_modulate': self.fan_modulate = bool(value) elif option == 'fan_seconds': self.fan_seconds = float(value) if self.serial_device: try: self.ser = serial.Serial( port=self.serial_device, baudrate=self.baud_rate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=10 ) self.ser.flushInput() if not self.fan_modulate: self.dormant_mode('run') time.sleep(0.1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location))
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__() self.logger = logging.getLogger("mycodo.inputs.winsen_zh03b") self.fan_is_on = False if not testing: import serial import binascii self.logger = logging.getLogger("mycodo.winsen_zh03b_{id}".format( id=input_dev.unique_id.split('-')[0])) self.device_measurements = db_retrieve_table_daemon( DeviceMeasurements).filter( DeviceMeasurements.device_id == input_dev.unique_id) self.binascii = binascii self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate # Check if device is valid self.serial_device = is_device(self.uart_location) self.fan_modulate = True self.fan_seconds = 50.0 if input_dev.custom_options: for each_option in input_dev.custom_options.split(';'): option = each_option.split(',')[0] value = each_option.split(',')[1] if option == 'fan_modulate': self.fan_modulate = bool(value) elif option == 'fan_seconds': self.fan_seconds = float(value) if self.serial_device: try: self.ser = serial.Serial(port=self.serial_device, baudrate=self.baud_rate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=10) self.ser.flushInput() if not self.fan_modulate: self.dormant_mode('run') time.sleep(0.1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location))
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__(input_dev, testing=testing, name=__name__) self.fan_is_on = False if not testing: import serial import binascii self.binascii = binascii self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate # Check if device is valid self.serial_device = is_device(self.uart_location) self.fan_modulate = True self.fan_seconds = 50.0 if input_dev.custom_options: for each_option in input_dev.custom_options.split(';'): option = each_option.split(',')[0] value = each_option.split(',')[1] if option == 'fan_modulate': self.fan_modulate = bool(value) elif option == 'fan_seconds': self.fan_seconds = float(value) if self.serial_device: try: self.ser = serial.Serial(port=self.serial_device, baudrate=self.baud_rate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=10) self.ser.flushInput() if not self.fan_modulate: self.dormant_mode('run') time.sleep(0.1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location))
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__() self.logger = logging.getLogger("mycodo.inputs.mh_z19") self._co2 = None self.measure_range = None self.abc_enable = False if not testing: import serial self.logger = logging.getLogger("mycodo.mhz19_{id}".format( id=input_dev.unique_id.split('-')[0])) self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate self.convert_to_unit = input_dev.convert_to_unit # Check if device is valid self.serial_device = is_device(self.uart_location) if self.serial_device: try: self.ser = serial.Serial(self.serial_device, baudrate=self.baud_rate, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location)) if input_dev.custom_options: for each_option in input_dev.custom_options.split(';'): option = each_option.split(',')[0] value = each_option.split(',')[1] if option == 'abc_enable': self.abc_enable = bool(value) elif option == 'measure_range': self.measure_range = value if self.abc_enable: self.abcon() else: self.abcoff() if self.measure_range: self.set_measure_range(self.measure_range) time.sleep(0.1)
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__(input_dev, testing=testing, name=__name__) self.fan_is_on = False # Initialize custom options self.fan_modulate = None self.fan_seconds = None self.number_measurements = None # Set custom options self.setup_custom_options(INPUT_INFORMATION['custom_options'], input_dev) if not testing: import serial import binascii self.binascii = binascii self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate # Check if device is valid self.serial_device = is_device(self.uart_location) if self.serial_device: try: self.ser = serial.Serial(port=self.serial_device, baudrate=self.baud_rate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=10) self.ser.flushInput() self.set_qa() if not self.fan_modulate: self.dormant_mode('run') time.sleep(0.1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location))
def initialize_input(self): import serial # Check if device is valid if is_device(self.input_dev.uart_location): try: self.ser = serial.Serial(port=self.input_dev.uart_location, baudrate=self.input_dev.baud_rate, timeout=1, writeTimeout=5) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". Check the device location is correct.' .format(dev=self.input_dev.uart_location))
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__() self.logger = logging.getLogger("mycodo.inputs.mh_z19") self.measure_range = None self.abc_enable = False if not testing: import serial self.logger = logging.getLogger( "mycodo.mhz19_{id}".format(id=input_dev.unique_id.split('-')[0])) self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate # Check if device is valid self.serial_device = is_device(self.uart_location) if self.serial_device: try: self.ser = serial.Serial(self.serial_device, baudrate=self.baud_rate, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location)) if input_dev.custom_options: for each_option in input_dev.custom_options.split(';'): option = each_option.split(',')[0] value = each_option.split(',')[1] if option == 'abc_enable': self.abc_enable = bool(value) elif option == 'measure_range': self.measure_range = value if self.abc_enable: self.abcon() else: self.abcoff() if self.measure_range: self.set_measure_range(self.measure_range) time.sleep(0.1)
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__() self.logger = logging.getLogger("mycodo.inputs.mh_z16") self._co2 = None if not testing: self.logger = logging.getLogger("mycodo.mh_z16_{id}".format( id=input_dev.unique_id.split('-')[0])) self.interface = input_dev.interface self.uart_location = input_dev.uart_location self.convert_to_unit = input_dev.convert_to_unit if self.interface == 'UART': import serial # Check if device is valid self.serial_device = is_device(self.uart_location) if self.serial_device: try: self.ser = serial.Serial(self.serial_device, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location)) elif self.interface == 'I2C': from smbus2 import SMBus self.i2c_address = int(str(input_dev.i2c_location), 16) self.i2c_bus = input_dev.i2c_bus self.cmd_measure = [ 0xFF, 0x01, 0x9C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63 ] self.IOCONTROL = 0X0E << 3 self.FCR = 0X02 << 3 self.LCR = 0X03 << 3 self.DLL = 0x00 << 3 self.DLH = 0X01 << 3 self.THR = 0X00 << 3 self.RHR = 0x00 << 3 self.TXLVL = 0X08 << 3 self.RXLVL = 0X09 << 3 self.i2c = SMBus(self.i2c_bus) self.begin()
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__() self.setup_logger(testing=testing, name=__name__, input_dev=input_dev) self.measure_range = None self.abc_enable = False if not testing: import serial self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate # Check if device is valid self.serial_device = is_device(self.uart_location) if self.serial_device: try: self.ser = serial.Serial(self.serial_device, baudrate=self.baud_rate, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location)) if input_dev.custom_options: for each_option in input_dev.custom_options.split(';'): option = each_option.split(',')[0] value = each_option.split(',')[1] if option == 'abc_enable': self.abc_enable = bool(value) elif option == 'measure_range': self.measure_range = value if self.abc_enable: self.abcon() else: self.abcoff() if self.measure_range: self.set_measure_range(self.measure_range) time.sleep(0.1)
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__(input_dev, testing=testing, name=__name__) self.measuring = None self.calibrating = None # Initialize custom options self.measure_range = None self.abc_enable = False # Set custom options self.setup_custom_options(INPUT_INFORMATION['custom_options'], input_dev) if not testing: import serial self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate # Check if device is valid self.serial_device = is_device(self.uart_location) if self.serial_device: try: self.ser = serial.Serial(self.serial_device, baudrate=self.baud_rate, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location)) if self.abc_enable: self.abcon() else: self.abcoff() if self.measure_range: self.set_measure_range(self.measure_range) time.sleep(0.1)
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__(input_dev, testing=testing, name=__name__) if not testing: self.interface = input_dev.interface self.uart_location = input_dev.uart_location if self.interface == 'UART': import serial # Check if device is valid self.serial_device = is_device(self.uart_location) if self.serial_device: try: self.ser = serial.Serial(self.serial_device, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location)) elif self.interface == 'I2C': from smbus2 import SMBus self.i2c_address = int(str(input_dev.i2c_location), 16) self.i2c_bus = input_dev.i2c_bus self.cmd_measure = [ 0xFF, 0x01, 0x9C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63 ] self.IOCONTROL = 0X0E << 3 self.FCR = 0X02 << 3 self.LCR = 0X03 << 3 self.DLL = 0x00 << 3 self.DLH = 0X01 << 3 self.THR = 0X00 << 3 self.RHR = 0x00 << 3 self.TXLVL = 0X08 << 3 self.RXLVL = 0X09 << 3 self.i2c = SMBus(self.i2c_bus) self.begin()
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__() self.logger = logging.getLogger("mycodo.inputs.mh_z16") if not testing: self.logger = logging.getLogger( "mycodo.mh_z16_{id}".format(id=input_dev.unique_id.split('-')[0])) self.interface = input_dev.interface self.uart_location = input_dev.uart_location if self.interface == 'UART': import serial # Check if device is valid self.serial_device = is_device(self.uart_location) if self.serial_device: try: self.ser = serial.Serial(self.serial_device, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location)) elif self.interface == 'I2C': from smbus2 import SMBus self.i2c_address = int(str(input_dev.i2c_location), 16) self.i2c_bus = input_dev.i2c_bus self.cmd_measure = [0xFF, 0x01, 0x9C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63] self.IOCONTROL = 0X0E << 3 self.FCR = 0X02 << 3 self.LCR = 0X03 << 3 self.DLL = 0x00 << 3 self.DLH = 0X01 << 3 self.THR = 0X00 << 3 self.RHR = 0x00 << 3 self.TXLVL = 0X08 << 3 self.RXLVL = 0X09 << 3 self.i2c = SMBus(self.i2c_bus) self.begin()
def initialize_input(self): import serial self.serial = serial if is_device(self.input_dev.uart_location): try: self.ser = serial.Serial( self.input_dev.uart_location, baudrate=self.input_dev.baud_rate, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error('Could not open "{dev}". Check the device location is correct.'.format( dev=self.input_dev.uart_location)) self.logger.debug("Min time between transmissions: {} seconds".format( min_seconds_between_transmissions))
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__(input_dev, testing=testing, name=__name__) self.timer = 0 # Initialize custom options self.serial_device = None # Set custom options self.setup_custom_options(INPUT_INFORMATION['custom_options'], input_dev) if not testing: import serial self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate # Check if device is valid self.uart_location = is_device(self.uart_location) if self.uart_location: try: self.ser = serial.Serial(self.uart_location, baudrate=self.baud_rate, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location)) self.serial = serial self.serial_send = None self.lock_file = "/var/lock/mycodo_ttn.lock" self.ttn_serial_error = False self.logger.debug( "Min time between transmissions: {} seconds".format( min_seconds_between_transmissions))
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__(input_dev, testing=testing, name=__name__) self.timer = 0 if not testing: import serial if input_dev.custom_options: for each_option in input_dev.custom_options.split(';'): option = each_option.split(',')[0] value = each_option.split(',')[1] if option == 'serial_device': self.serial_device = value self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate # Check if device is valid self.uart_location = is_device(self.uart_location) if self.uart_location: try: self.ser = serial.Serial(self.uart_location, baudrate=self.baud_rate, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location)) self.serial = serial self.serial_send = None self.lock_file = "/var/lock/mycodo_ttn.lock" self.ttn_serial_error = False self.logger.debug( "Min time between transmissions: {} seconds".format( min_seconds_between_transmissions))
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__(input_dev, testing=testing, name=__name__) if not testing: import serial self.uart_location = input_dev.uart_location self.baud_rate = input_dev.baud_rate # Check if device is valid self.serial_device = is_device(self.uart_location) if self.serial_device: try: self.ser = serial.Serial( self.serial_device, baudrate=self.baud_rate, timeout=1) except serial.SerialException: self.logger.exception('Opening serial') else: self.logger.error( 'Could not open "{dev}". ' 'Check the device location is correct.'.format( dev=self.uart_location))