Modbus Master 写单个线圈

kayson
Posts: 1
Joined: Thu Jan 14, 2021 6:20 am

Modbus Master 写单个线圈

Postby kayson » Thu Jan 14, 2021 6:26 am

基于modbus/serial/mb master
对device_parameters[]的数据进行修改:
  1. {CID_RELAY_P1, STR("RelayP1"), STR("on/off"), MB_DEVICE_ADDR1, MB_PARAM_COIL,    -1, 1,
  2.                 COIL_OFFSET(coils_port0), PARAM_TYPE_U16, 2, OPTS(BIT0, 0, 0), PAR_PERMS_READ_WRITE}
这个是其中一行。

我的本意是发送05功能码,写单个线圈,但是实际发送的是0f功能码。
我应该如果修改代码才能让主机发送05功能码?
感谢支持

ESP_alisitsyn
Posts: 211
Joined: Fri Feb 01, 2019 4:02 pm
Contact:

Re: Modbus Master 写单个线圈

Postby ESP_alisitsyn » Thu Jan 28, 2021 1:27 pm

Hi @kayson ,

The Modbus command 0x0F (Writes Multiple Coils) can be used to set one or more coils. Usually it is enough to support only this command to write coils. The current stack implementation has this constraint in the design. If your device supports only command 0x05 (Force Single Coil) the stack should be updated to add this support. If you really need this I can provide instructions or patch to fix this for your project. Again, this is not issue but design decision.
Another way to implement it is to use
mbfunccoils_m.c::eMBMasterReqErrCode
eMBMasterReqWriteCoil( UCHAR ucSndAddr, USHORT usCoilAddr, USHORT usCoilData, LONG lTimeOut )
or change implementation of
esp_err_t mbc_serial_master_send_request(mb_param_request_t* request, void* data_ptr)
function to use the above function when we set just one coil.

Who is online

Users browsing this forum: No registered users and 104 guests