DrvHJ212 Communicator Driver (Custom)
Functional Description
DrvHJ212 is a custom Communicator driver in ScadaV6CommExt for field device connectivity. Protocol details follow the source implementation.
Scope and Version
- Source:
ScadaV6CommExt/DrvHJ212.Logic - TFM:
net8.0 - Version:
V6.x
Install and Enable
- Deploy driver binaries to Communicator folders.
- Activate driver in Administrator → Communicator → Drivers.
- Upload configuration and restart Communicator.
Line and Device Configuration
- Create a communication line with the proper channel type.
- Add device and set address/timeouts.
- Set polling options and CmdLine as required by this driver; see Functional notes and configuration (template and source) below for file names, address format, and line keys.
CustomOptions (extracted)
| Key | Default | Note |
|---|
ServerPort | 6000 | Extracted from source; confirm meaning in driver implementation. |
Code hints
29: protected class TemplateDict : Dictionary
47: ConnectionRequired = false;//不使用默认链接
96: protected virtual DeviceTemplate GetDeviceTemplate()
98: DeviceTemplate deviceTemplate = null;
99: string fileName = PollingOptions.CmdLine.Trim();
109: if (templateDict.TryGetValue(fileName, out DeviceTemplate existingTemplate))
117: DeviceTemplate newTemplate = CreateDeviceTemplate();
133: protected virtual DeviceTemplate CreateDeviceTemplate()
135: return new DeviceTemplate();
146: private int serverPort = 6000;
154: serverPort = LineContext.LineConfig.CustomOptions.GetValueAsInt("ServerPort", 6000);
155: server = new NetServer("0.0.0.0", serverPort);
166: Log.WriteLine($"开始监听: {serverPort}");
171: Log.WriteLine($"发送给: {session.RemoteIPEndPoint}: {rawText}");
176: Log.WriteLine("会话关闭: " + session.RemoteIPEndPoint + ", 当前会话总数: " + server.SessionCount);
181: Log.WriteLine("会话开始: " + session.RemoteIPEndPoint + ", 当前会话总数: " + server.SessionCount);
186: var sb = new StringBuilder("收到自: " + session.RemoteIPEndPoint + ": " + rawText);
215: public override void OnConnectionSet()
221: DeviceTemplate deviceTemplate;
227: deviceTemplate = GetDeviceTemplate();
Administrator UI (DrvHJ212.View)
Configure in Administrator → Communicator. Labels below come from the View language pack.
- View source:
ScadaV6CommExt/DrvHJ212.View - Main forms:
FrmDeviceProps.csFrmDeviceTemplate.csFrmTemplateOptions.cs
| Phrase key | Text |
|---|
gbCmd | Command Parameters |
lblCmdCode | Command code |
lblCmdNum | Command number |
lblCmdAddress | Element address |
lblTemplateFileName | Device template |
ConfigDirRequired | The device template file must be located inside {0} |
TemplateNotExists | The device template file does not exist. |
btnAddCmd.ToolTip | Add Command |
gbTemplate | Device Template |
TemplateTitle | {0} - MODBUS. Device Template Editor |
DuplicatedCmdNums | Duplicated command numbers: |
EmptyCmdCodes | Empty command codes found. |
AddressHint | {0}, starting from {1} |
lblCmdName | Name |
lblCmdCodeWarn | Fill out code |
lblCmdDataBlock | Data block |
cbCmdDataBlock.Items[0] | Coils (0X) |
cbCmdDataBlock.Items[1] | Holding Registers (4X) |
cbCmdDataBlock.Items[2] | Custom |
chkCmdMultiple | Multiple |
lblCmdFuncCode | Function code |
lblCmdFuncCodeHex | Hexadecimal |
lblCmdElemType | Element type |
cbCmdElemType.Items[0] | Undefined |
cbCmdElemType.Items[1] | ushort (2 bytes) |
cbCmdElemType.Items[2] | short (2 bytes) |
cbCmdElemType.Items[3] | uint (4 bytes) |
cbCmdElemType.Items[4] | int (4 bytes) |
cbCmdElemType.Items[5] | ulong (8 bytes) |
cbCmdElemType.Items[6] | long (8 bytes) |
Functional notes and configuration (template and source)
Derived from Logic/Common and device template XML: driver behavior and the Administrator/Communicator fields to set (address, CmdLine, line CustomOptions, template nodes).
Logic location
ScadaV6CommExt/DrvHJ212.Logic- Common:
DrvHJ212.Common
Overrides
OnCommLineStart(), OnConnectionSet(), InitDeviceTags(), Session(), SendCommand()
CmdLine / template
PollingOptions.CmdLine.Trim();
DeviceConfig properties referenced
| Property | Note |
|---|
| 未检测到 DeviceConfig.* 引用(可能使用基类封装)。 |
Line CustomOptions
XML keys (Common)
| Node | Note |
|---|
Elem | 来自 Common 配置加载/保存相关源码中的 XML 节点名 |
ZeroAddr | 来自 Common 配置加载/保存相关源码中的 XML 节点名 |
DecAddr | 来自 Common 配置加载/保存相关源码中的 XML 节点名 |
DefByteOrder2 | 来自 Common 配置加载/保存相关源码中的 XML 节点名 |
DefByteOrder4 | 来自 Common 配置加载/保存相关源码中的 XML 节点名 |
DefByteOrder8 | 来自 Common 配置加载/保存相关源码中的 XML 节点名 |
Options | 来自 Common 配置加载/保存相关源码中的 XML 节点名 |
ElemGroups | 来自 Common 配置加载/保存相关源码中的 XML 节点名 |
ElemGroup | 来自 Common 配置加载/保存相关源码中的 XML 节点名 |
Cmds | 来自 Common 配置加载/保存相关源码中的 XML 节点名 |
Cmd | 来自 Common 配置加载/保存相关源码中的 XML 节点名 |
Code excerpt
93: ///
94: protected virtual DeviceTemplate GetDeviceTemplate()
95: {
96: DeviceTemplate deviceTemplate = null;
96: DeviceTemplate deviceTemplate = null;
97: string fileName = PollingOptions.CmdLine.Trim();
98:
99: if (string.IsNullOrEmpty(fileName))
151: {
152: serverPort = LineContext.LineConfig.CustomOptions.GetValueAsInt("ServerPort", 6000);
153: server = new NetServer("0.0.0.0", serverPort);
154: server.Started += OnNetServer_Started;
222: ///
223: public override void InitDeviceTags()
224: {
225: deviceTemplate = GetDeviceTemplate();
224: {
225: deviceTemplate = GetDeviceTemplate();
226:
227: if (deviceTemplate == null)
278: ///
279: public override void Session()
280: {
281: base.Session();
Troubleshooting
- No data: line, address, template, connectivity.
- Template load errors: check logs.
- Options ignored: verify option scope (line vs device).