[Modbus]
描述
Reads the Coils register.
語法
node1.readCoil(address)
node2.readCoil(address, size, buffer)
參數
node1/node2: ModbusSlaveNode object.address: The address of the Coils register you want to read.size: The number of Coils registers you want to read.buffer: Copy the read-out Coils register data to the array space pointed to by the buffer.
回傳
int: The Coil location data is returned when using address fader only, as MODBUS_COIL_ON or MODBUS_COIL_OFF.
When reading with the specified buffer, MODBUS_SUCCESS is returned, and EXCEPTION_CODE is returned in the opposite direction.
範例
#include <Modbus86.h>
ModbusSlave bus;
ModbusSlaveNode node;
uint8_t write_single_coil( uint8_t function,
uint16_t address,
uint16_t length)
{
uint16_t value;
if (address == 0) {
node.readCoil(address, 1, &value);
if (value)
digitalWrite(LED_BUILTIN, HIGH);
else
digitalWrite(LED_BUILTIN, LOW);
}
return MODBUS_SUCCESS;
}
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
Serial485.begin(115200);
/* Modbus RTU Mode via RS485. */
bus.begin(MODBUS_RTU, Serial485);
/* Slave node with ID 11. */
node.attach(11, bus);
/* Set the callback function of Write Single Coil (0x05). */
node.cbFunc[MODBUS_CB_WRITE_SINGLE_COIL]
= write_single_coil;
}
void loop()
{
node.poll();
}也可以看看
函式庫參考主頁面
86Duino 參考的文本是根據 知識共享署名-相同方式分享 3.0 許可證,部分文本是從 Arduino 參考 修改的。 參考中的代碼示例已發佈到公共領域。