cv4ab api dotnet
v0.1.7
.NET Core 中 Allen-Bradley Rockwell PLC 的通信
LibPLCTag 库 C++ Api
基于libplctag-csharp
努盖特
特别感谢您测试 Mavert
特别感谢 Mario Averoldi 的技术支持 [email protected]。
科斯投资有限公司
______ _ __
/ ____/___ __________(_)___ _ _____ _____/ /_
/ / / __ / ___/ ___/ / __ | / / _ / ___/ __/
/ /___/ /_/ / / (__ ) / / / / |/ / __(__ ) /_
____/____/_/ /____/_/_/ /_/|___/___/____/__/
Client Api Allen-Bradley PLC (Made in Italy)
注意: PLC控制多种设备,如果编程或访问出现错误,可能会造成财产、生产甚至生命的损失。访问或编程 PLC 时务必小心!
我们不对本代码对于任何目的的适用性做出任何声明或保证。
当心!
客户端是 LibPLCTag 库的包装器。
[ Serializable ]
public class Test12
{
public int AA1 { get ; set ; }
public int AA2 { get ; set ; }
public int AA3 { get ; set ; }
public int AA4 { get ; set ; }
public int AA5 { get ; set ; }
public int AA6 { get ; set ; }
public int AA7 { get ; set ; }
public int AA8 { get ; set ; }
}
public static void Main ( string [ ] args )
{
//initialize controller
using ( var controller = new Controller ( "10.155.128.192" , "1, 0" , CPUType . LGX ) )
{
//ping controller
Console . Out . WriteLine ( "Ping " + controller . Ping ( true ) ) ;
//create group tag
var grp = controller . CreateGroup ( ) ;
//add tag
var tag = grp . CreateTagType < string [ ] > ( "Track" , TagSize . STRING , 300 ) ;
tag . Changed += TagChanged ;
var value = tag . Read ( ) ;
//add tag from Class
var tag1 = grp . CreateTagType < Test12 > ( "Test" ) ;
tag . Changed += TagChanged ;
var tag2 = grp . CreateTagFloat32 ( "Fl32" ) ;
grp . Changed += GroupChanged ;
grp . Read ( ) ;
}
}
private static void PrintChange ( string @event , ResultOperation result )
{
Console . Out . WriteLine ( $ " { @event } { result . Timestamp } Changed: { result . Tag . Name } " ) ;
}
static void TagChanged ( ResultOperation result )
{
PrintChange ( "TagChanged" , result ) ;
}
static void GroupChanged ( IEnumerable < ResultOperation > results )
{
foreach ( var result in results ) PrintChange ( "GroupTagChanged" , result ) ;
} 可以创建任何类型的标签:
大小在 TagSize 中指定。
对于数组,在定义中指定大小。
例子:
public class TestArray
{
public int InTest { get ; set ; }
public int [ ] InTestArray { get ; set ; } = new int [ 5 ] ;
public string [ ] StringTestArray { get ; set ; } = new string [ 300 ] ;
}自定义类型是类。属性按顺序读取。