Added script for MODBUS device search
This commit is contained in:
parent
a290f52d4d
commit
8776a84678
33
tests/find_address.py
Executable file
33
tests/find_address.py
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from time import sleep
|
||||||
|
from sys import exit
|
||||||
|
import minimalmodbus
|
||||||
|
import serial
|
||||||
|
|
||||||
|
|
||||||
|
print('---- Looking for device ----')
|
||||||
|
slave_address_list = range(1,256)
|
||||||
|
CO2_addr = 9
|
||||||
|
total_devices = 0
|
||||||
|
for slave_address in slave_address_list:
|
||||||
|
print(f'Address {slave_address}:\t', end='')
|
||||||
|
try:
|
||||||
|
# modbus init
|
||||||
|
instrument = minimalmodbus.Instrument('/dev/rs485', 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
|
||||||
|
##
|
||||||
|
CO2 = instrument.read_register(CO2_addr, 1, functioncode=4) * 10
|
||||||
|
print('DEVICE RESPONDED')
|
||||||
|
total_devices += 1
|
||||||
|
except minimalmodbus.NoResponseError:
|
||||||
|
print(f'no response')
|
||||||
|
sleep(0.1)
|
||||||
|
print(f'Found {total_devices} devices (tried {len(slave_address_list)} addresses)')
|
||||||
|
print('---- DONE ----')
|
||||||
|
exit(0)
|
Loading…
Reference in New Issue
Block a user