Added software reset
This commit is contained in:
@@ -8,7 +8,7 @@ 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")
|
||||
- action can be "read", "write", "reset" or it can be omitted completely (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
|
||||
@@ -78,7 +78,7 @@ while arg_index < len(argv):
|
||||
# sanity check
|
||||
if not action:
|
||||
action = 'all'
|
||||
if action != 'read' and action != 'write' and action != 'all':
|
||||
if action != 'read' and action != 'write' and action != 'all' and action != 'reset':
|
||||
print(f'Unknown action {action}')
|
||||
exit(-4)
|
||||
if action == 'write' and value == None:
|
||||
@@ -140,4 +140,11 @@ elif action == 'write':
|
||||
except ValueError:
|
||||
print(f'Register number {reg_number} cannot be written')
|
||||
exit(-9)
|
||||
exit(0)
|
||||
elif action == 'reset':
|
||||
if not s.reset():
|
||||
# reset should throw NoResponse; if it doesn't, reset failed
|
||||
print('Device reset failed!')
|
||||
else:
|
||||
print('---- Device reset ----')
|
||||
|
||||
exit(0)
|
||||
|
||||
Reference in New Issue
Block a user