コード例 #1
0
ファイル: mh_z19b.py プロジェクト: ar-rehman135/Maxponics
    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)
コード例 #2
0
    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))
コード例 #3
0
ファイル: k30.py プロジェクト: magichammer/Mycodo
    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))
コード例 #4
0
ファイル: k30.py プロジェクト: ciscomonkey/Mycodo
    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))
コード例 #5
0
    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()
コード例 #6
0
ファイル: winsen_zh03b.py プロジェクト: ciscomonkey/Mycodo
    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))
コード例 #7
0
    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))
コード例 #8
0
    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))
コード例 #9
0
ファイル: mh_z19.py プロジェクト: magichammer/Mycodo
    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)
コード例 #10
0
    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))
コード例 #11
0
    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))
コード例 #12
0
ファイル: mh_z19.py プロジェクト: ciscomonkey/Mycodo
    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)
コード例 #13
0
    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()
コード例 #14
0
ファイル: mh_z19.py プロジェクト: Routout/Mycodo
    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)
コード例 #15
0
ファイル: mh_z19b.py プロジェクト: roniap/Mycodo
    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)
コード例 #16
0
ファイル: mh_z16.py プロジェクト: chitters2004/Mycodo-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()
コード例 #17
0
ファイル: mh_z16.py プロジェクト: ciscomonkey/Mycodo
    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()
コード例 #18
0
    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))
コード例 #19
0
    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))
コード例 #20
0
ファイル: k30_ttn.py プロジェクト: wllyng/Mycodo
    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))
コード例 #21
0
ファイル: k30.py プロジェクト: yhyuan/Mycodo
    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))