Execute measurements
The following steps show how to use this driver to execute a simple measurement on a Windows system.
Install the SVM4X sensor driver and all required packages as described in Installation.
Connect the SVM4X sensor to your system with the serial USB cable.
Run the example script from the root of the repository.
By default the script assumes the sensor is connected to COM1 serial port. If this is different on your system, pass the port in use with the
--serial-port
parameter as outlined below.python examples/example_usage_uart_svm4x.py --serial-port <your COM port>
Example script
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2023 Sensirion AG, Switzerland
#
# THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator: sensirion-driver-generator 0.33.0
# Product: svm4x
# Model-Version: 2.0.3
#
import time
import argparse
from sensirion_shdlc_driver import ShdlcSerialPort
from sensirion_driver_adapters.shdlc_adapter.shdlc_channel import ShdlcChannel
from sensirion_uart_svm4x.device import Svm4xDevice
parser = argparse.ArgumentParser()
parser.add_argument('--serial-port', '-p', default='COM1')
args = parser.parse_args()
with ShdlcSerialPort(port=args.serial_port, baudrate=115200) as port:
channel = ShdlcChannel(port)
sensor = Svm4xDevice(channel)
sensor.device_reset()
time.sleep(2.0)
serial_number = sensor.get_serial_number()
print(f"serial_number: {serial_number}; "
)
product_type = sensor.get_product_type()
print(f"product_type: {product_type}; "
)
product_name = sensor.get_product_name()
print(f"product_name: {product_name}; "
)
(firmware_major, firmware_minor, firmware_debug, hardware_major, hardware_minor, protocol_major, protocol_minor
) = sensor.get_version()
print(f"firmware_major: {firmware_major}; "
f"firmware_minor: {firmware_minor}; "
f"firmware_debug: {firmware_debug}; "
f"hardware_major: {hardware_major}; "
f"hardware_minor: {hardware_minor}; "
f"protocol_major: {protocol_major}; "
f"protocol_minor: {protocol_minor}; "
)
t_offset = sensor.get_temperature_offset_for_rht_measurements()
print(f"t_offset: {t_offset}; "
)
sensor.set_temperature_offset_for_rht_measurements(0)
sensor.start_measurement()
for i in range(100):
try:
time.sleep(1.0)
(a_humidity, a_temperature, a_voc_index, a_nox_index
) = sensor.read_measured_values()
print(f"a_humidity: {a_humidity}; "
f"a_temperature: {a_temperature}; "
f"a_voc_index: {a_voc_index}; "
f"a_nox_index: {a_nox_index}; "
)
except BaseException:
continue
sensor.stop_measurement()