Panasonic MEWTOCOL
Zeus 的 MEWTOCOL 模块面向 Panasonic FP 系列 PLC 的 MEWTOCOL-COM ASCII 通信,支持 %NN# 站号帧、BCC 校验、DT/LD/FL 数据寄存器、X/Y/R/L 接点字读写、点表采集、按点名写回和虚拟 PLC 联调。
没硬件时先跑虚拟 PLC
var memory = new MewtocolSlaveMemory();
memory.DataRegisterWords[100] = 253;
memory.InternalRelayWords[10] = 0x0001;
await using var app = ZeusHost.Create(builder =>
{
builder.AddAcquisition(TimeSpan.FromMilliseconds(100));
builder.AddVirtualChannel("mewtocol", new MewtocolSlaveResponder(stationNumber: 1, memory));
builder.AddPanasonicMewtocol("plc", "mewtocol", new MewtocolOptions
{
StationNumber = 1
}, points: map => map
.DtWord("temperature", address: 100, scale: 0.1).Writable("temperature")
.RBit("running", wordAddress: 10, bitOffset: 0).Writable("running"));
});
await app.StartAsync();
var temperature = app.Points.Get<double>("temperature");
await app.Points.WriteAsync("temperature", 18.6);
这段代码里:
| 代码 | 含义 |
|---|---|
MewtocolSlaveMemory | 虚拟 PLC 的 DT/LD/FL 数据寄存器和 X/Y/R/L 接点字映像 |
MewtocolSlaveResponder(1, memory) | 模拟 01 号 MEWTOCOL PLC |
StationNumber = 1 | MEWTOCOL 帧里的两位十进制站号 |
.DtWord(..., 0.1) | DT100 原始字乘以 0.1 后进入点表;写回时反算 |
可运行示例:samples/Zeus.Samples.Console.Mewtocol。
连接真实 PLC
MEWTOCOL-COM 常用于串口或 RS-485。串口参数由 PLC 工程决定,示例:
await using var app = ZeusHost.Create(builder =>
{
builder.AddSerialPort("mewtocol", "COM3", 9600);
builder.AddPanasonicMewtocol("plc", "mewtocol", new MewtocolOptions
{
StationNumber = 1
});
});
如果现场通过以太网串口服务器做 TCP 透传,通道可以换成 TCP:
builder.AddTcpClient("mewtocol", "192.168.250.1", 9094);
builder.AddPanasonicMewtocol("plc", "mewtocol", new MewtocolOptions { StationNumber = 1 });
读写 API
var plc = app.Devices.Get<MewtocolDevice>("plc");
var dt = await plc.ReadDataRegistersAsync(100, 2);
await plc.WriteDataRegistersAsync(110, [10, 20, 30]);
var relays = await plc.ReadInternalRelayWordsAsync(10, 1);
await plc.WriteInternalRelayWordsAsync(10, [0x0001]);
也可以直接发任意 MEWTOCOL 命令:
string data = await plc.ExecuteAsync("RD", "D0010000101");
支持的内存区
| 区域 | 命令 | 点表便捷方法 |
|---|---|---|
| DT 数据寄存器 | RD / WD | .DtWord(...) / .DtBit(...) |
| LD 链接数据寄存器 | RD / WD | .LdWord(...) |
| FL 文件寄存器 | RD / WD | .FlWord(...) |
| X 外部输入接点字 | RC | .XWord(...) / .XBit(...) |
| Y 外部输出接点字 | RC / WC | .YWord(...) / .YBit(...) |
| R 内部继电器接点字 | RC / WC | .RWord(...) / .RBit(...) |
| L 链接继电器接点字 | RC / WC | .LWord(...) / .LBit(...) |
MEWTOCOL 位点通过读写所在字实现,写回时会先读取当前字,再只修改目标 bit。X 输入区通常由 PLC 侧驱动,JSON 和点表会拒绝把 X 点标成可写。
点表采集
builder.AddPanasonicMewtocol("plc", "mewtocol", new MewtocolOptions
{
StationNumber = 1,
WordOrder = MewtocolWordOrder.HighWordFirst
}, points: map => map
.DtWord("temperature", 100, 0.1).Writable("temperature")
.Int16("pressure", MewtocolDataArea.DataRegister, 120)
.Real("flow", MewtocolDataArea.DataRegister, 130)
.RBit("running", 10, 0).Writable("running"));
MEWTOCOL 原始字是 16 位。UInt32、Int32 和 Real 占两个连续字,字序由 MewtocolOptions.WordOrder 控制,默认高字在前。
JSON 配置
{
"channels": [
{ "name": "mewtocol", "type": "serial", "portName": "COM3", "baudRate": 9600 }
],
"devices": [
{
"name": "plc",
"channel": "mewtocol",
"type": "panasonic-mewtocol",
"unitId": 1,
"points": [
{ "name": "temperature", "area": "dt", "address": 100, "dataType": "word", "scale": 0.1, "writable": true },
{ "name": "running", "area": "r", "address": 10, "bit": 0, "dataType": "bit", "writable": true }
]
}
]
}
虚拟 MEWTOCOL PLC:
{ "name": "mewtocol", "type": "virtual", "responder": "mewtocol", "unitId": 1 }
可直接复制的真实串口配置样例位于 samples/Zeus.Samples.Console.Config/zeus-mewtocol.json。
常见问题
| 现象 | 最可能原因 | 处理 |
|---|---|---|
| 一直超时 | 站号、串口参数或 TCP 透传端口不对 | 先用 MewtocolSlaveResponder 跑通,再查 PLC 通信设置 |
| BCC 校验失败 | 波特率/校验位错误,或接入的不是 MEWTOCOL-COM ASCII | 核对串口参数和对端协议模式 |
| 读到错误码 | 内存区、地址或数量不被 PLC 支持 | 看异常里的 MEWTOCOL 错误码,核对 CPU 手册 |
| 32 位值高低字反了 | 字序和 PLC 工程约定不一致 | 改 MewtocolOptions.WordOrder |
| 写回没执行 | 点没有 .Writable(...) 或 JSON 没设 writable: true | 标记点为可写;X 输入区不能写 |
下一步:周期读取数据看 点表与采集。