我想找...

搜尋

分享

目錄

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() {}

也可以看看


函式庫參考主頁面

The text of the 86Duino reference is a modification of the Arduino reference and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

返回頂端