created test script for modbus. (DH)
This commit is contained in:
parent
fcb6ce88a6
commit
50d7893963
18
tests/minimalmodbus_test.py
Executable file
18
tests/minimalmodbus_test.py
Executable file
@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import minimalmodbus
|
||||||
|
import serial
|
||||||
|
|
||||||
|
slave_address = 0x11
|
||||||
|
instrument = minimalmodbus.Instrument('/dev/ttyUSB0', slave_address, close_port_after_each_call=True) # port name, slave address (in decimal)
|
||||||
|
|
||||||
|
instrument.serial.baudrate = 115200
|
||||||
|
instrument.serial.bytesize = 8
|
||||||
|
instrument.serial.parity = serial.PARITY_EVEN
|
||||||
|
instrument.serial.stopbits = 1
|
||||||
|
instrument.serial.timeout = 0.05 # seconds
|
||||||
|
instrument.mode = minimalmodbus.MODE_RTU # rtu or ascii mode
|
||||||
|
instrument.clear_buffers_before_each_transaction = True
|
||||||
|
|
||||||
|
# read
|
||||||
|
CO2 = instrument.read_register(9, 1, functioncode=4) * 10
|
||||||
|
print(CO2)
|
Loading…
Reference in New Issue
Block a user