MewtocolNet
v0.8.1
易于使用的 Mewtocol 协议库,可通过 TCP/串行与 Panasonic PLC 连接。
️ 该库不是松下官方产品,松下也不提供任何形式的财务支持或限制。
️ 目前不支持 FP7
该库仅在少数 PLC 上进行了测试,支持 Panasonic Mewtocol 协议的其他类型可能也适用。使用风险自负,其他人可能会遵循社区反馈
该库是用netstandard2.0编写的,应该与许多 .NET 环境兼容。
有关受支持的 .NET clrs 的完整列表,请参阅此页面
使用 dotnet CLI 并运行
dotnet add package Mewtocol.NET
松下已在其网站上发布了协议定义。如果您想查看一般功能或添加/报告缺失的功能,请参阅此站点。
该库当时功能尚不完整,但提供了所有基本功能
要查看示例的完整列表,请单击此处。
连接到 PLC 非常简单
using MewtocolNet ;
using ( var plc = Mewtocol . Ethernet ( "192.168.178.55" ) . Build ( ) ) {
await plc . ConnectAsync ( ) ;
if ( ! plc . IsConnected ) {
Console . WriteLine ( "Failed to connect to the plc..." ) ;
} else {
Console . WriteLine ( plc . PlcInfo ) ;
}
}
详细说明
RegisterCollection
的新类 using MewtocolNet ;
using MewtocolNet . RegisterAttributes ;
public class TestRegisters : RegisterCollection {
//corresponds to a R100 boolean register in the PLC
[ Register ( "R100" ) ]
public bool TestBool1 { get ; private set ; }
//corresponds to a XD input of the PLC
[ Register ( "XD" ) ]
public bool TestBoolInputXD { get ; private set ; }
//corresponds to a DDT7012 - DDT7013 as a 32bit time value that gets parsed as a timespan (TIME)
//the smallest value to communicate to the PLC is 10ms
[ Register ( "DDT7012" ) ]
public TimeSpan TestTime { get ; private set ; }
//corresponds to a DT1101 - DT1104 string register in the PLC with (STRING[4])
[ Register ( "DT1101" , "STRING[4]" ) ]
public string TestString1 { get ; private set ; }
}
.WithPoller()
来附加自动轮询器 TestRegisters registers = null ;
//setting up a new PLC serial interface and tell it to use the register collection
var plc = Mewtocol . Serial ( "COM4" , BaudRate . _19200 )
. WithPoller ( )
. WithRegisterCollections ( c => {
registers = c . AddCollection < TestRegisters > ( ) ;
// or use
// c.AddCollection(new TestRegisters());
// if you want to pass data to a constructor
} )
. Build ( ) ;
//connect to it
await plc . ConnectAsync ( async ( ) => {
//restart the plc program during the connection process
await plc . RestartProgramAsync ( ) ;
} ) ;
//wait for the first data cycle of the poller module
//otherwise the property value might still be unset or null
await App . ViewModel . Plc . AwaitFirstDataCycleAsync ( ) ;
if ( App . ViewModel . Plc . IsConnected ) {
Console . WriteLine ( registers . TestBool1 ) ;
}
笔记!这不是您读取寄存器的唯一选择,请参见此处
除了自动属性绑定之外,您还可以使用以下模式:
await plc . Register . Struct < short > ( "DT100" ) . WriteAsync ( 100 ) ;
var value = await plc . Register . Struct < short > ( "DT100" ) . ReadAsync ( ) ;
IRegister < bool > outputContactReference ;
var plc = Mewtocol . Ethernet ( "127.0.0.1" )
. WithRegisters ( b => {
b . Bool ( "Y4" ) . Build ( out outputContactReference ) ;
} )
. Build ( ) ;
await plc . ConnectAsync ( ) ;
await outputContactReference . WriteAsync ( true ) ;