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 ) ;