-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModbusTypes.h
More file actions
58 lines (51 loc) · 2.14 KB
/
Copy pathModbusTypes.h
File metadata and controls
58 lines (51 loc) · 2.14 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef MODBUSTYPES_H
#define MODBUSTYPES_H
#include <QtGlobal>
// Modbus 功能码
enum ModbusFunctionCode : quint8 { // 强枚举类型,类型安全,确保底层类型只能为quint8
ReadCoils = 0x01, // 读线圈
ReadDiscreteInputs = 0x02, // 读离散输入
ReadHoldingRegisters = 0x03, // 读保持寄存器
ReadInputRegisters = 0x04, // 读输入寄存器
WriteSingleCoil = 0x05, // 写单个线圈
WriteSingleRegister = 0x06, // 写单个寄存器
WriteMultipleCoils = 0x0F, // 写多个线圈 (15)
WriteMultipleRegisters = 0x10, // 写多个寄存器 (16)
ReadFileRecord = 0x14, // 读文件记录 (20)
WriteFileRecord = 0x15, // 写文件记录 (21)
ReadFile = 0xCB, // 自定义读文件 (203)
WriteFile = 0xCC // 自定义写文件 (204)
};
// Modbus 异常码
enum ModbusExceptionCode : quint8 {
IllegalFunction = 0x01, // 非法功能
IllegalDataAddress = 0x02, // 非法数据地址
IllegalDataValue = 0x03, // 非法数据值
SlaveDeviceFailure = 0x04, // 从站设备故障
Acknowledge = 0x05, // 确认
SlaveDeviceBusy = 0x06, // 从站设备忙
MemoryParityError = 0x08 // 内存奇偶性错误
};
// Modbus 通信模式
enum ModbusMode {
ModeTCP,
ModeRTU
};
// Modbus 数据区类型
enum ModbusDataType {
DataTypeCoil, // 线圈
DataTypeDiscreteInput, // 离散输入
DataTypeHoldingRegister,// 保持寄存器
DataTypeInputRegister // 输入寄存器
};
// 寄存器数量限制常量定义
namespace ModbusConst {
constexpr quint16 MAX_COILS = 65535; // 编译期常量,在编译器计算,不占运行时内存开销,可用于模板参数、数组大小等编译器需要的常量
constexpr quint16 MAX_REGISTERS = 65535;
constexpr quint16 MAX_READ_COILS = 2000;
constexpr quint16 MAX_READ_REGISTERS = 125;
constexpr quint16 MAX_WRITE_COILS = 1968;
constexpr quint16 MAX_WRITE_REGISTERS = 123;
constexpr quint16 MAX_FILE_RECORDS = 10000;
}
#endif // MODBUSTYPES_H