-
Notifications
You must be signed in to change notification settings - Fork 12
Setup and Connection
Felix Weiß edited this page Jun 21, 2022
·
1 revision
Setting up the interface class is fairly easy just create a new instance:
//attaching a logger
Logger.LogLevel = LogLevel.Verbose;
Logger.OnNewLogMessage((date, msg) => {
Console.WriteLine($"{date.ToString("HH:mm:ss")} {msg}");
});
//setting up a new PLC interface and register collection
MewtocolInterface plc = new MewtocolInterface("192.168.115.5");After that you cann call the ConnectAsync() method
await plc.ConnectAsync(
//PLC connected
(plcinf) => {
if(plcinf.OperationMode.RunMode)
Console.WriteLine("PLC is in RUN");
},
//Connection failed
() => {
Console.WriteLine("PLC failed to connect");
}
);Note that you cann either use the callbacks inside the ConnectAsync() method or attach to an event like:
plc.Connected += (plcinf) => {
if(plcinf.OperationMode.RunMode)
Console.WriteLine("PLC is in RUN");
};
await plc.ConnectAsync();await plc.ConnectAsync(
//PLC connected
(plcinf) => {
if(!plcinf.OperationMode.RunMode) {
await plc.SetOperationMode(OPMode.Run);
Console.WriteLine("PLC is in RUN");
}
}
);