ModbusMasterNode.setTransmitBuffer()

[Modbus]

描述

Sets the value of the private array writeData in the ModbusMasterNode class.

writeData is the content of the Modbus packet using the Write function code.

語法

node1.setTransmitBuffer(index, value, mode)

參數

  • node1: ModbusMasterNode object.
  • index: the index value of the writeData array.
  • value: the value to be filled in the writeData array, i.e. the content of the Modbus packet to be sent.
  • mode: mode of reading data from writeData array, the citation is MODBUS_DATAMODE_BIT or MODBUS_DATAMODE_UINT16, if no citation is given it will be MODBUS_DATAMODE_UINT16 by default.

回傳

int: if successful return MODBUS_SUCCESS and vice versa return EXCEPTION_CODE.

範例

#include <Modbus86.h>
 
ModbusMaster bus1;
ModbusMasterNode node1;
 
uint8_t result;
 
void setup()
{
    while(!Serial);
    Serial1.begin(115200);
    bus1.begin(MODBUS_RTU, Serial1);
    node1.attach(16, bus1); 
 
    node1.setTransmitBuffer(0, true, MODBUS_DATAMODE_BIT);
    node1.setTransmitBuffer(1, false, MODBUS_DATAMODE_BIT);
    result = node1.writeMultipleCoils(5, 2);   
 
    if (result != MODBUS_SUCCESS) {
        Serial.print("ErrorCode: ");
        Serial.println(result);
    }
}
 
void loop() {}

也可以看看


函式庫參考主頁面

86Duino 參考的文本是根據 Creative Commons Attribution-ShareAlike 3.0 License,部分文本是從 the Arduino reference 修改的。 參考中的代碼示例已發佈到公共領域。

發表評論

上部へスクロール