beginTransmission()

描述

設定欲寫入的 Slave 裝置暫存器之起始位址,與無引數的 writeMultipleCoilswriteMultipleRegisters 搭配使用,詳見範例以示說明。

語法


node1.beginTransmission(write_address)

參數

node1ModbusMasterNode 物件。

write_address:欲寫入的 Slave 裝置暫存器之起始位址。

範例

#include <Arduino.h>
#include <Modbus86.h>

ModbusMaster bus1;
ModbusMasterNode node2;

uint8_t reg[2];
uint8_t result;

void setup()
{
	while(!Serial);
	Serial1.begin(115200);
	bus1.begin(MODBUS_RTU, Serial1);
	node2.begin(16, bus1); 

	reg[0] = 0x1234;
	reg[1] = 0xabcd;
	node2.beginTransmission(5);
	node2.send(reg[0]);
	node2.send(reg[1]);
	result = node2.writeMultipleRegisters();

	if (result != MODBUS_SUCCESS) {
		Serial.print("ErrorCode: ");
		Serial.println(result);
	}
}

void loop()
{
}


See Also

writeMultipleCoils()
writeMultipleRegisters()
sendBit()
send()


函式庫參考主頁面

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.