setTransmitBuffer()

描述

設定 ModbusMasterNode 類別中的私有陣列 writeData 的數值。
writeData 是使用 Write 功能碼的 Modbus 封包內容。

語法


node1.setTransmitBuffer(index, value, mode)

參數

node1ModbusMasterNode 物件。

indexwriteData 陣列的索引值。

value:填入 writeData 陣列的數值,即欲傳送的 Modbus 封包內容。

mode:從 writeData 陣列中讀取數據的模式,其引數為 MODBUS_DATAMODE_BITMODBUS_DATAMODE_UINT16 ,若不給予引數將預設為 MODBUS_DATAMODE_UINT16

回傳

int:如果成功回傳 MODBUS_SUCCESS,反之回傳 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.begin(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()
{
}


See Also

clearTransmitBuffer()
writeSingleCoil()
writeSingleRegisters()
writeMultipleCoils()
writeMultipleRegisters()
readWriteMultipleRegisters()


函式庫參考主頁面

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.