-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from MK16kawai/dev
update modbus && qmi8658 doc
- Loading branch information
Showing
5 changed files
with
93 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from maix.comm import modbus | ||
from maix import app, err | ||
|
||
slave = modbus.Slave( | ||
modbus.Mode.RTU, # mode | ||
"/dev/ttyS0", # serial device | ||
0x00, 10, # coils | ||
0x00, 10, # discrete input | ||
0x00, 10, # input registers | ||
0x00, 10, # holding registers | ||
115200, 1, # serial 115200-8N1, slave | ||
0, False # tcp port, debug OFF | ||
) | ||
|
||
|
||
old_ir = slave.input_registers() | ||
print("old ir: ", old_ir) | ||
data : list[int] = [0x22, 0x33, 0x44] | ||
slave.input_registers(data, 3) | ||
new_ir = slave.input_registers() | ||
print("new ir:", new_ir) | ||
|
||
while not app.need_exit(): | ||
if err.Err.ERR_NONE != slave.receive(2000): #timeout 2000ms | ||
continue | ||
|
||
rtype = slave.request_type() | ||
if rtype == modbus.RequestType.READ_HOLDING_REGISTERS: | ||
print("master read hr") | ||
hr = slave.holding_registers() | ||
print("now hr: ", hr) | ||
hr = [x+1 for x in hr] | ||
print("now we make hr+1: ", hr) | ||
print("update hr") | ||
slave.holding_registers(hr) | ||
|
||
slave.reply() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from maix.comm import modbus | ||
from maix import app, err | ||
|
||
slave = modbus.Slave( | ||
modbus.Mode.TCP, # mode | ||
"", # ip, keep empty | ||
0x00, 10, # coils | ||
0x00, 10, # discrete input | ||
0x00, 10, # input registers | ||
0x00, 10, # holding registers | ||
0, 1, # serial 115200-8N1, slave, ignore | ||
5020, False # tcp port, debug OFF | ||
) | ||
|
||
|
||
old_ir = slave.input_registers() | ||
print("old ir: ", old_ir) | ||
data : list[int] = [0x22, 0x33, 0x44] | ||
slave.input_registers(data, 3) | ||
new_ir = slave.input_registers() | ||
print("new ir:", new_ir) | ||
|
||
while not app.need_exit(): | ||
if err.Err.ERR_NONE != slave.receive(2000): #timeout 2000ms | ||
continue | ||
|
||
rtype = slave.request_type() | ||
if rtype == modbus.RequestType.READ_HOLDING_REGISTERS: | ||
print("master read hr") | ||
hr = slave.holding_registers() | ||
print("now hr: ", hr) | ||
hr = [x+1 for x in hr] | ||
print("now we make hr+1: ", hr) | ||
print("update hr") | ||
slave.holding_registers(hr) | ||
|
||
slave.reply() | ||
|
||
|