[Modbus]
説明
Write to the Input Registers.
構文
node1.writeInputRegister(address, value)
node2.writeInputRegister(address, size, buffer)
媒介変数
node1/node2: ModbusSlaveNode object.address: The address of the Input Registers to write to.value: The value of the single Input Registers that you want to write to.size: The number of plural Input Registers you want to write to.buffer: Copy the data of the array in the array space pointed to by the buffer to the Input Registers.
戻り値
int: If it succeeds, send back MODBUS_SUCCESS, and vice versa send back EXCEPTION_CODE.
例
#include <Modbus86.h>
ModbusSlave bus;
ModbusSlaveNode node;
uint8_t read_input_registers( uint8_t function,
uint16_t address,
uint16_t length)
{
int sensorPin = A2;
if (address <= 2 && address + length > 2)
node.writeInputRegister(2, analogRead(sensorPin));
return MODBUS_SUCCESS;
}
void setup()
{
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 Read Input Registers (0x04). */
node.cbFunc[MODBUS_CB_READ_INPUT_REGISTERS]
= read_input_registers;
}
void loop()
{
node.poll();
}ライブラリリファレンスホーム
86Duinoリファレンスのテキストは、Arduinoリファレンスを改変したもので、Creative Commons Attribution-ShareAlike 3.0ライセンスに基づいてライセンスされています。リファレンス内のコードサンプルはパブリックドメインとして公開されています。