Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update modbus && qmi8658 doc #65

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/doc/en/modules/qmi8658.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ from maix import ext_dev, pinmap, err, time
QMI8658_I2CBUS_NUM = 4

imu = ext_dev.qmi8658.QMI8658(QMI8658_I2CBUS_NUM,
mode=ext_dev.qmi8658.Mode.DUAL,
acc_scale=ext_dev.qmi8658.AccScale.ACC_SCALE_2G,
acc_odr=ext_dev.qmi8658.AccOdr.ACC_ODR_8000,
gyro_scale=ext_dev.qmi8658.GyroScale.GYRO_SCALE_16DPS,
gyro_odr=ext_dev.qmi8658.GyroOdr.GYRO_ODR_8000)
mode=ext_dev.imu.Mode.DUAL,
acc_scale=ext_dev.imu.AccScale.ACC_SCALE_2G,
acc_odr=ext_dev.imu.AccOdr.ACC_ODR_8000,
gyro_scale=ext_dev.imu.GyroScale.GYRO_SCALE_16DPS,
gyro_odr=ext_dev.imu.GyroOdr.GYRO_ODR_8000)

while True:
data = imu.read()
Expand Down
10 changes: 5 additions & 5 deletions docs/doc/zh/modules/qmi8658.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ from maix import ext_dev, pinmap, err, time
QMI8658_I2CBUS_NUM = 4

imu = ext_dev.qmi8658.QMI8658(QMI8658_I2CBUS_NUM,
mode=ext_dev.qmi8658.Mode.DUAL,
acc_scale=ext_dev.qmi8658.AccScale.ACC_SCALE_2G,
acc_odr=ext_dev.qmi8658.AccOdr.ACC_ODR_8000,
gyro_scale=ext_dev.qmi8658.GyroScale.GYRO_SCALE_16DPS,
gyro_odr=ext_dev.qmi8658.GyroOdr.GYRO_ODR_8000)
mode=ext_dev.imu.Mode.DUAL,
acc_scale=ext_dev.imu.AccScale.ACC_SCALE_2G,
acc_odr=ext_dev.imu.AccOdr.ACC_ODR_8000,
gyro_scale=ext_dev.imu.GyroScale.GYRO_SCALE_16DPS,
gyro_odr=ext_dev.imu.GyroOdr.GYRO_ODR_8000)

while True:
data = imu.read()
Expand Down
10 changes: 5 additions & 5 deletions examples/ext_dev/sensors/acc_gyro_qmi8658/qmi8658_rw_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
QMI8658_I2CBUS_NUM = 4

imu = ext_dev.qmi8658.QMI8658(QMI8658_I2CBUS_NUM,
mode=ext_dev.qmi8658.Mode.DUAL,
acc_scale=ext_dev.qmi8658.AccScale.ACC_SCALE_2G,
acc_odr=ext_dev.qmi8658.AccOdr.ACC_ODR_8000,
gyro_scale=ext_dev.qmi8658.GyroScale.GYRO_SCALE_16DPS,
gyro_odr=ext_dev.qmi8658.GyroOdr.GYRO_ODR_8000)
mode=ext_dev.imu.Mode.DUAL,
acc_scale=ext_dev.imu.AccScale.ACC_SCALE_2G,
acc_odr=ext_dev.imu.AccOdr.ACC_ODR_8000,
gyro_scale=ext_dev.imu.GyroScale.GYRO_SCALE_16DPS,
gyro_odr=ext_dev.imu.GyroOdr.GYRO_ODR_8000)

while True:
data = imu.read()
Expand Down
39 changes: 39 additions & 0 deletions examples/protocol/comm_modbus_rtu.py
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()


39 changes: 39 additions & 0 deletions examples/protocol/comm_modbus_tcp.py
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()