Exemplo n.º 1
0
    def init(self):
        super(SensirionSensorBridge, self).init()

        self.port = self._init['port']
        self.baudrate = self._init.get('baudrate', 460800)

        self.ser = ShdlcSerialPort(port=self.port, baudrate=self.baudrate)
Exemplo n.º 2
0
def main():
    # Connect to the device with default settings:
    #  - baudrate:      115200
    #  - slave address: 0
    with ShdlcSerialPort(port='COM1', baudrate=115200) as port:
        device = Sfa3xShdlcDevice(ShdlcConnection(port), slave_address=0)
        print("Resetting device... ")
        device.device_reset()

        # Print device information
        print("Device Marking: {}".format(device.get_device_marking()))

        # Measure
        device.start_measurement()
        print("Measurement started... ")
        while True:
            time.sleep(10.)
            hcho, humidity, temperature = device.read_measured_values()
            # use default formatting for printing output:
            print("{}, {}, {}".format(hcho, humidity, temperature))
            # custom printing of attributes:
            print(". Formaldehyde concentration = {} ppb "
                  "(received int16 = {}) ".format(hcho.ppb, hcho.ticks))
            print(". Humidity = {:0.2f} %RH (received int16 = {})".format(
                humidity.percent_rh, humidity.ticks))
            print(". Temperature = {:0.2f} °C (received int16 = {})".format(
                temperature.degrees_celsius, temperature.ticks))
Exemplo n.º 3
0
def main():
    # Connect to the device with default settings:
    #  - baudrate:      115200
    #  - slave address: 0
    with ShdlcSerialPort(port='COM1', baudrate=115200) as port:
        device = Svm40ShdlcDevice(ShdlcConnection(port), slave_address=0)
        print("Resetting device... ")
        device.device_reset()

        # Print some device information
        print("Version: {}".format(device.get_version()))
        print("Product Name: {}".format(device.get_product_name()))
        print("Serial Number: {}".format(device.get_serial_number()))

        # Measure
        device.start_measurement()
        print("Measurement started... ")
        while True:
            time.sleep(10.)
            air_quality, humidity, temperature = device.read_measured_values()
            # use default formatting for printing output:
            print("{}, {}, {}".format(air_quality, humidity, temperature))
            # custom printing of attributes:
            print(". VOC index = {} (received int16 = {}) ".format(
                air_quality.voc_index, air_quality.ticks))
            print(". Humidity = {:0.2f} %RH (received int16 = {})".format(
                humidity.percent_rh, humidity.ticks))
            print(". Temperature = {:0.2f} °C (received int16 = {})".format(
                temperature.degrees_celsius, temperature.ticks))
Exemplo n.º 4
0
 def update_devices(self, values):
     self.portLabel.setText(f"Serial port: {values['port']}")
     self.device = SensorBridgeShdlcDevice(
         ShdlcConnection(ShdlcSerialPort(values['port'], baudrate=values['baudrate'])),
         slave_address=values['address'])
     self.sht85device = SHT85(self.device, SensirionSensor.PORTS[self.sht85PortDropdown.currentText()])
     self.stc31device = STC31(self.device, SensirionSensor.PORTS[self.stc31PortDropdown.currentText()])
Exemplo n.º 5
0
def main():
    print("Prometheus Metrics endpoint is listening on 9140")
    start_http_server(9140)

    with ShdlcSerialPort(port="/dev/ttyUSB0", baudrate=115200) as port:
        device = Svm40ShdlcDevice(ShdlcConnection(port), slave_address=0)
        device.device_reset()

        # Print some device information
        print("Version: {}".format(device.get_version()))
        print("Product Name: {}".format(device.get_product_name()))
        print("Serial Number: {}".format(device.get_serial_number()))

        # Start measurement
        device.start_measurement()
        print("Measurement started... ")
        while True:
            _report_metrics(device)

            time.sleep(10.0)
Exemplo n.º 6
0
def bridge(request):
    serial_port = _get_serial_port(request.config, validate=True)
    serial_bitrate = _get_serial_bitrate(request.config)
    with ShdlcSerialPort(serial_port, serial_bitrate) as port:
        dev = SensorBridgeShdlcDevice(ShdlcConnection(port), slave_address=0)
        yield dev
Exemplo n.º 7
0
class SensirionSensorBridge(TransferLayer):
    '''
    Driver for Sensirion Sensor Bridge using the official SHDLC drivers of Sensirion.
    The Sensirion Sensor Bridge is connected via USB and allows communication to two I2C ports.
    '''

    bridge_ports = {
        "one": SensorBridgePort.ONE,
        "two": SensorBridgePort.TWO,
        "all": SensorBridgePort.ALL,
    }

    def __init__(self, conf):
        super(SensirionSensorBridge, self).__init__(conf)

    def init(self):
        super(SensirionSensorBridge, self).init()

        self.port = self._init['port']
        self.baudrate = self._init.get('baudrate', 460800)

        self.ser = ShdlcSerialPort(port=self.port, baudrate=self.baudrate)

    def setup_i2c_device(self,
                         bridge_port=SensorBridgePort.ONE,
                         voltage=3.3,
                         frequency=400e3,
                         **_):
        device = SensorBridgeShdlcDevice(ShdlcConnection(self.ser),
                                         slave_address=0)
        device.set_i2c_frequency(bridge_port, frequency=frequency)
        device.set_supply_voltage(bridge_port, voltage=voltage)
        device.switch_supply_on(bridge_port)
        return device

    def disable_i2c_device(self, device, bridge_port=SensorBridgePort.ONE):
        if hasattr(self, 'device'):
            device.switch_supply_off(bridge_port)

    def print_i2c_device_information(self, device):
        logger.info("Product Name: {}".format(device.get_product_name()))
        logger.info("Product Type: {}".format(device.get_product_type()))
        logger.info("Serial Number: {}".format(device.get_serial_number()))
        logger.info("Version: {}".format(device.get_version()))

    def read_i2c(self,
                 device,
                 port,
                 address,
                 command,
                 read_n_bytes=0,
                 timeout_us=100e3):
        rx_data = device.transceive_i2c(port,
                                        address=address,
                                        tx_data=command,
                                        rx_length=read_n_bytes,
                                        timeout_us=timeout_us)
        return rx_data

    def write_i2c(self, device, port, address, command):
        device.transceive_i2c(port,
                              address=address,
                              rx_length=0,
                              tx_data=command,
                              timeout_us=0)

    def __del__(self):
        self.close()

    def close(self):
        super(SensirionSensorBridge, self).close()
        if hasattr(self, 'ser'):
            self.ser.close()
Exemplo n.º 8
0
def connection(serial_port, serial_bitrate=115200):
    with ShdlcSerialPort(serial_port, serial_bitrate) as port:
        connection = ShdlcConnection(port)
        yield connection
Exemplo n.º 9
0
def connection(serial_port):
    with ShdlcSerialPort(serial_port, 460800) as port:
        connection = ShdlcConnection(port)
        yield connection
Exemplo n.º 10
0
def connection(serial_port, serial_bitrate, slave_address):
    with ShdlcSerialPort(serial_port, serial_bitrate) as port:
        connection = ShdlcConnection(port)
        yield connection
Exemplo n.º 11
0
import logging
import time

from sensirion_shdlc_driver import ShdlcSerialPort, ShdlcConnection
from sensirion_shdlc_sensorbridge import SensorBridgePort, SensorBridgeShdlcDevice

from sensirion_sensorbridge_i2c_sfm.sfm3019 import Sfm3019I2cSensorBridgeDevice, MeasurementMode

logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',
                    level=logging.ERROR)

# Connect to the SensorBridge with default settings:
#  - baudrate:      460800
#  - slave address: 0
with ShdlcSerialPort(port='/dev/ttyUSB0', baudrate=460800) as port:
    # Initialize Sensorbridge
    bridge = SensorBridgeShdlcDevice(ShdlcConnection(port), slave_address=0)
    print("SensorBridge SN: {}".format(bridge.get_serial_number()))

    # Configure SensorBridge port 1 for SFM
    bridge.set_i2c_frequency(SensorBridgePort.ONE, frequency=400e3)
    bridge.set_supply_voltage(SensorBridgePort.ONE, voltage=3.3)
    bridge.switch_supply_on(SensorBridgePort.ONE)

    # Create SFM device
    sfm3019 = Sfm3019I2cSensorBridgeDevice(bridge,
                                           SensorBridgePort.ONE,
                                           slave_address=0x2E)

    # Define gas (or gas mixes)
    measure_mode = MeasurementMode.Air