Omron Host Link
The Host Link module targets Omron PLC ASCII Host Link communication. It supports @UU station frames, FCS checks, CIO/LR/HR/AR/DM word access, point acquisition, write-back by point name, and virtual PLC simulation.
Start with a Virtual PLC
var memory = new HostLinkSlaveMemory();
memory.DataMemoryWords[100] = 253;
memory.CioWords[10] = 0x0001;
await using var app = ZeusHost.Create(builder =>
{
builder.AddAcquisition(TimeSpan.FromMilliseconds(100));
builder.AddVirtualChannel("host-link", new HostLinkSlaveResponder(unitNumber: 0, memory));
builder.AddOmronHostLink("plc", "host-link", new HostLinkOptions
{
UnitNumber = 0
}, points: map => map
.DmWord("temperature", address: 100, scale: 0.1).Writable("temperature")
.CioBit("running", address: 10, bitOffset: 0).Writable("running"));
});
await app.StartAsync();
var temperature = app.Points.Get<double>("temperature");
await app.Points.WriteAsync("temperature", 18.6);
Run sample: samples/Zeus.Samples.Console.HostLink.
Connect to a Real PLC
Serial settings depend on the PLC project:
await using var app = ZeusHost.Create(builder =>
{
builder.AddSerialPort("host-link", "COM3", 9600);
builder.AddOmronHostLink("plc", "host-link", new HostLinkOptions
{
UnitNumber = 0
});
});
If the site uses an Ethernet-to-serial gateway or TCP tunnel, use a TCP channel:
builder.AddTcpClient("host-link", "192.168.250.1", 9600);
builder.AddOmronHostLink("plc", "host-link", new HostLinkOptions { UnitNumber = 0 });
Read/Write API
var plc = app.Devices.Get<HostLinkDevice>("plc");
var dm = await plc.ReadDataMemoryWordsAsync(100, 2);
await plc.WriteDataMemoryWordsAsync(110, [10, 20, 30]);
var cio = await plc.ReadCioWordsAsync(10, 1);
await plc.WriteCioWordsAsync(10, [0x0001]);
Raw Host Link commands are also available:
string data = await plc.ExecuteAsync("RD", "01000002");
Memory Areas
| Area | Read command | Write command | Point helpers |
|---|---|---|---|
| CIO / IR | RR | WR | .CioWord(...) / .CioBit(...) |
| LR | RL | WL | .LinkWord(...) / .LinkBit(...) |
| HR | RH | WH | .HoldingWord(...) / .HoldingBit(...) |
| AR | RJ | WJ | .AuxiliaryWord(...) / .AuxiliaryBit(...) |
| DM | RD | WD | .DmWord(...) / .DmBit(...) |
Bit points are written by reading the owning word, changing only the target bit, then writing the word back.
Points
builder.AddOmronHostLink("plc", "host-link", new HostLinkOptions
{
UnitNumber = 0,
WordOrder = HostLinkWordOrder.HighWordFirst
}, points: map => map
.DmWord("temperature", 100, 0.1).Writable("temperature")
.Int16("pressure", HostLinkArea.DataMemory, 120)
.Real("flow", HostLinkArea.DataMemory, 130)
.CioBit("running", 10, 0).Writable("running"));
Host Link raw words are 16-bit. UInt32, Int32, and Real occupy two consecutive words; HostLinkOptions.WordOrder controls word order.
JSON Configuration
{
"channels": [
{ "name": "host-link", "type": "serial", "portName": "COM3", "baudRate": 9600 }
],
"devices": [
{
"name": "plc",
"channel": "host-link",
"type": "omron-host-link",
"unitId": 0,
"points": [
{ "name": "temperature", "area": "dm", "address": 100, "dataType": "word", "scale": 0.1, "writable": true },
{ "name": "running", "area": "cio", "address": 10, "bit": 0, "dataType": "bit", "writable": true }
]
}
]
}
Virtual Host Link PLC:
{ "name": "host-link", "type": "virtual", "responder": "host-link", "unitId": 0 }
Common Issues
| Symptom | Likely cause | Fix |
|---|---|---|
| Timeout | Unit number, serial parameters, or TCP tunnel port is wrong | Test with HostLinkSlaveResponder, then check PLC settings |
| FCS failure | Baud/parity mismatch or the peer is not Host Link ASCII | Verify serial settings and protocol mode |
| End code returned | Memory area, address, or count unsupported | Inspect HostLinkException.EndCode and PLC manual |
| 32-bit word order is wrong | PLC project uses opposite word order | Change HostLinkOptions.WordOrder |
Next: Points and Acquisition.