forked from wirenboard/wb-mqtt-serial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodbus_device.cpp
39 lines (31 loc) · 1.34 KB
/
modbus_device.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "modbus_device.h"
#include "modbus_common.h"
#include <iostream>
#include <stdexcept>
REGISTER_BASIC_INT_PROTOCOL("modbus", TModbusDevice, TRegisterTypes({
{ Modbus::REG_COIL, "coil", "switch", U8 },
{ Modbus::REG_DISCRETE, "discrete", "switch", U8, true },
{ Modbus::REG_HOLDING, "holding", "text", U16 },
{ Modbus::REG_HOLDING_SINGLE, "holding_single", "text", U16 },
{ Modbus::REG_HOLDING_MULTI, "holding_multi", "text", U16 },
{ Modbus::REG_INPUT, "input", "text", U16, true }
}));
TModbusDevice::TModbusDevice(PDeviceConfig config, PPort port, PProtocol protocol)
: TBasicProtocolSerialDevice<TBasicProtocol<TModbusDevice>>(config, port, protocol)
{}
std::list<PRegisterRange> TModbusDevice::SplitRegisterList(const std::list<PRegister> & reg_list, bool enableHoles) const
{
return Modbus::SplitRegisterList(reg_list, DeviceConfig(), Port()->Debug(), enableHoles);
}
uint64_t TModbusDevice::ReadRegister(PRegister reg)
{
throw TSerialDeviceException("modbus: single register reading is not supported");
}
void TModbusDevice::WriteRegister(PRegister reg, uint64_t value)
{
ModbusRTU::WriteRegister(Port(), SlaveId, reg, value);
}
void TModbusDevice::ReadRegisterRange(PRegisterRange range)
{
ModbusRTU::ReadRegisterRange(Port(), SlaveId, range);
}