Skip to content

Commit

Permalink
Merge pull request #65 from MK16kawai/dev
Browse files Browse the repository at this point in the history
update modbus && qmi8658 doc
  • Loading branch information
Neutree authored Nov 6, 2024
2 parents f86cf27 + 477bf40 commit 2d2cf2a
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 15 deletions.
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()


0 comments on commit 2d2cf2a

Please sign in to comment.