Added README.md for test folder

This commit is contained in:
mj
2021-11-26 21:08:30 +01:00
parent cfb945408e
commit 4cf93cdc89
2 changed files with 91 additions and 18 deletions

View File

@@ -2,25 +2,31 @@
from sensor import Sensor
from sys import argv,exit
# query read input
# read holding
# write input/holding [REG]
#
#
#
# query_device.py ADDR [BAUDRATE] [{read [REGISTER] | write REGISTER}]
# where:
# - ADDR is MODBUS address. Special case is ADDR=0 (broadcast),
# for which you may write, but not read
# - BAUDRATE is baudrate (duh!), default value 19200
# - REGISTER is either register number (e.g. 30010 for input register CO2),
# or register name (e.g. CO2)
# - list of register names...
# - if only ADDR (and optionally BAUDRATE) is supplied, query all possible information from sensor
#
def print_help():
print("HEEEELP")
print( \
f'''{argv[0]} ADDR [BAUDRATE] [{{read [REGISTER ...] | write VALUE REGISTER}}]
where:
- ADDR is Modbus address (use 0 for broadcast; note that only write can be broadcast)
- BAUDRATE is (optional) baud rate; default value is 19200
- action can be "read", "write" or can be omitted (defaults to "read all")
- REGISTER can be either human-friendly register name (e.g. "CO2") or register number (30001)
- read may have list of REGISTER arguments (combining both register numbers and names)
- VALUE is 16-bit integer in decimal format
- to get list of human-friendly names just read all registers from sensor (run script with address only)
EXAMPLES
Read all registers from sensor 247, default baud rate:
{argv[0]} 247
Read only CO2 register from sensor 123, baudrate 4800:
{argv[0]} 123 4800 read CO2
Read CO2, T_SHT4x and RH_SCD4x from sensor 222, default baudrate:
{argv[0]} 222 read CO2 T_SHT4x RH_SCD4x
Turn LED off for sensor 247, baud 115200:
{argv[0]} 247 115200 write 0 LED_on_register
Set brightness of all connected sensors to 50%:
{argv[0]} 0 write 50 LED_brightness_register
''')
# default values
DEFAULT_BAUDRATE = 19200
@@ -87,6 +93,9 @@ if action != 'write' and len(register_name) + len(register_number) == 0:
input_registers = [ x for x in Sensor.input_register_offset.keys() ]
holding_registers = [ x for x in Sensor.holding_register_offset.keys() ]
register_name = input_registers + holding_registers
if action != 'write' and addr == 0:
print(f'Cannot broadcast action "{action}"')
exit(-12)
# Query device
print('---- Query device ----')