| | |
| | | #define CC_LINK_IE_FIELD_CHANNEL(x) (180 + (x)) // x 范围:1~4 |
| | | #define CC_LINK_IE_TSN_CHANNEL(x) (280 + (x)) // x 范围:1~4 |
| | | |
| | | // 自定义错误码 |
| | | // 自定义错误码 |
| | | #define ERROR_CODE_UNKNOWN 0x00010000 // 未知 |
| | | #define ERROR_CODE_NOT_CONNECTED 0x00020000 // 未连接 |
| | | #define ERROR_CODE_INVALID_PARAM 0x00030000 // 参数无效 |
| | |
| | | SPB = 0x0032, // 缓冲存储器 (字) |
| | | MAIL = 0x0065, // 特殊软元件类型:邮件类型 (10进制 101) |
| | | MAILMC = 0x0066, // 特殊软元件类型:无确认邮件 (10进制 102) |
| | | LX = 0x03E9, // 链接直接软元件 (链接输入) (0x03E9~0x04E7) (位) |
| | | LY = 0x07D1, // 链接直接软元件 (链接输出) (0x07D1~0x08CF) (位) |
| | | LB = 0x59D9, // 链接直接软元件 (链接继电器) (0x59D9~0x5AD7) (位) |
| | | LW = 0x5DC1, // 链接直接软元件 (链接寄存器) (0x5DC1~0x5EBF) (字) |
| | | LSB = 0x61A9, // 链接直接软元件 (链接特殊继电器) (0x61A9~0x62A7) (位) |
| | | LSW = 0x6D61, // 链接直接软元件 (链接特殊寄存器) (0x6D61~0x6E5F) (字) |
| | | SPG = 0x7148, // 智能功能模块软元件 (0x7148~0x7247) (字) |
| | | LX = 0x03E8, // 链接直接软元件 (链接输入) (0x03E9~0x04E7) (位) |
| | | LY = 0x07D0, // 链接直接软元件 (链接输出) (0x07D1~0x08CF) (位) |
| | | LB = 0x59D8, // 链接直接软元件 (链接继电器) (0x59D9~0x5AD7) (位) |
| | | LW = 0x5DC0, // 链接直接软元件 (链接寄存器) (0x5DC1~0x5EBF) (字) |
| | | LSB = 0x61A8, // 链接直接软元件 (链接特殊继电器) (0x61A9~0x62A7) (位) |
| | | LSW = 0x6D60, // 链接直接软元件 (链接特殊寄存器) (0x6D61~0x6E5F) (字) |
| | | SPG = 0x7147, // 智能功能模块软元件 (0x7148~0x7247) (字) |
| | | }; |
| | | |
| | | // 数据类型 |
| | | enum class DataType { |
| | | BIT = 1, // 位 (1位) |
| | | WORD = 2, // 字 (16位) |
| | | DWORD =4 // 双字 (32位) |
| | | DWORD = 4 // 双字 (32位) |
| | | }; |
| | | |
| | | // 控制代码 |
| | |
| | | * 1~239 表示普通网络号 |
| | | **/ |
| | | |
| | | /* |
| | | * [Station No.] |
| | | * MELSECNET/H:1~64 表示其他站点,255 表示本站 |
| | | * CC-Link 系列网络的范围类似,区别在于站号的取值范围 |
| | | * MELSECNET/H : 1~64(Other stations),255(Own station) |
| | | * CC-Link : 0~63(Other stations),255(Own station) |
| | | * CC-Link IE Controller : 1~120(Other stations),255(Own station) |
| | | * CC-Link IE Field : 0~120(Other stations),255(Own station) |
| | | * CC-Link IE TSN : 0~120(Other stations),255(Own station) |
| | | **/ |
| | | /* |
| | | * [Station No.] |
| | | * MELSECNET/H:1~64 表示其他站点,255 表示本站 |
| | | * CC-Link 系列网络的范围类似,区别在于站号的取值范围 |
| | | * MELSECNET/H : 1~64(Other stations),255(Own station) |
| | | * CC-Link : 0~63(Other stations),255(Own station) |
| | | * CC-Link IE Controller : 1~120(Other stations),255(Own station) |
| | | * CC-Link IE Field : 0~120(Other stations),255(Own station) |
| | | * CC-Link IE TSN : 0~120(Other stations),255(Own station) |
| | | **/ |
| | | |
| | | /* |
| | | * 高 8 位(网络号): 指定设备所属的网络 |
| | | * 低 8 位(站点号): 指定设备在网络中的编号 |
| | | * 用一个参数传递设备的网络号和站点号时: nSt = station.nStNo | ((station.nNetNo << 8) & 0xFF00); |
| | | **/ |
| | | /* |
| | | * 高 8 位(网络号): 指定设备所属的网络 |
| | | * 低 8 位(站点号): 指定设备在网络中的编号 |
| | | * 用一个参数传递设备的网络号和站点号时: nSt = station.nStNo | ((station.nNetNo << 8) & 0xFF00); |
| | | **/ |
| | | |
| | | short nNetNo = 0; // 网络编号:PLC所连接的网络编号,0表示默认网络 |
| | | short nStNo = 255; // 站点编号:指定与PLC连接的站点编号,255通常表示广播或所有站点 |
| | | |
| | | // 自定义构造函数,覆盖默认值 |
| | | explicit StationIdentifier(const short net, const short st) : nNetNo(net), nStNo(st) {} |
| | | |
| | | StationIdentifier() |
| | | { |
| | | nNetNo = 0; |
| | | nStNo = 255; |
| | | } |
| | | |
| | | // 将“网络号”和“站点号”组合成一个最终编码 |
| | | short StationIdentifier::toNetworkStationCode() const { |
| | |
| | | // 重载 < 运算符(用于排序或比较,通常用于 map 或 set 中作为 key) |
| | | bool operator<(const StationIdentifier& other) const { |
| | | return std::tie(nNetNo, nStNo) < |
| | | std::tie(other.nNetNo, other.nStNo); |
| | | std::tie(other.nNetNo, other.nStNo); |
| | | } |
| | | |
| | | // 重载 == 运算符(用于相等比较) |
| | | bool operator==(const StationIdentifier& other) const { |
| | | return std::tie(nNetNo, nStNo) == |
| | | std::tie(other.nNetNo, other.nStNo); |
| | | std::tie(other.nNetNo, other.nStNo); |
| | | } |
| | | |
| | | // 重载 = 运算符(用于赋值) |
| | |
| | | } |
| | | }; |
| | | |
| | | using BitContainer = std::vector<uint8_t>; // 每个元素存储 8 个位 |
| | | using BitContainer = std::vector<bool>; // 每个元素存储 1 位 |
| | | using WordContainer = std::vector<uint16_t>; // 每个元素存储 16 位 |
| | | using DWordContainer = std::vector<uint32_t>; // 每个元素存储 32 位 |
| | | |
| | |
| | | |
| | | // 容器转换 |
| | | static void ConvertCharToShort(const std::vector<char>& vecChar, std::vector<short>& vecShort); |
| | | static void ConvertShortToChar(const std::vector<short>& vecShort, std::vector<char>&vecChar); |
| | | static void ConvertShortToChar(const std::vector<short>& vecShort, std::vector<char>& vecChar); |
| | | static void ConvertUint8ToShort(const std::vector<uint8_t>& vecUint8, std::vector<short>& vecShort); |
| | | static void ConvertShortToUint8(const std::vector<short>& vecShort, std::vector<uint8_t>& vecUint8); |
| | | static void ConvertUint32ToShort(const std::vector<uint32_t>& vecUint32, std::vector<short>& vecShort); |