public S7PlcService(int index, ICpuConfig config, List <IDatablockModel> datablocks) : base(index, config, datablocks) { S7.Net.CpuType S7NetCpuType = ConvertCpuType(Config.CpuType); _plcReader = new S7.Net.Plc(S7NetCpuType, config.Ip, (short)config.Rack, (short)config.Slot); _plcWriter = new S7.Net.Plc(S7NetCpuType, config.Ip, (short)config.Rack, (short)config.Slot); }
/// <summary> /// Create a plc that will connect to localhost (Snap 7 server) and connect to it /// </summary> public S7NetTests() { plc = new Plc(CpuType.S7300, "127.0.0.1", 0, 2); //ConsoleManager.Show(); ShutDownServiceS7oiehsx64(); S7TestServer.Start(); plc.Open(); }
public static void LogConnectCpu(S7.Net.Plc plc) { writeMsg("Cpu LastErrorString -> " + plc.LastErrorString + "\n" + "CpuType -> " + Properties.Settings.Default.CpuType.ToString() + "\n" + "IpCpu -> " + Properties.Settings.Default.IpCpu + "\n" + "RackCpu -> " + Properties.Settings.Default.RackCpu + "\n" + "SlotCpu -> " + Properties.Settings.Default.SlotCpu); }
//public string LastError { get; private set; } public override async Task ConnectAsync() { ComState = ComState.Connecting; await DelayAsync(1000); S7.Net.CpuType S7NetCpuType = ConvertCpuType(Config.CpuType); try { string ip = "100.67.165.113"; _plcReader = new Plc(S7NetCpuType, ip /*Config.Ip*/, (short)Config.Rack, (short)Config.Slot); _plcWriter = new Plc(S7NetCpuType, ip /*Config.Ip*/, (short)Config.Rack, (short)Config.Slot); await _plcReader.OpenAsync(); await _plcWriter.OpenAsync(); if (_plcReader.IsConnected && _plcWriter.IsConnected) { ComState = ComState.Connected; } else { ComState = ComState.ConnectFailed; if (_plcReader.IsConnected) { _plcReader.Close(); } if (_plcWriter.IsConnected) { _plcWriter.Close(); } } } catch (Exception) { //LastError = ex.Message; ComState = ComState.ConnectFailed; } }
public S7NetPlcDriver(CpuType cpu, string ip, short rack, short slot) { client = new Plc(cpu, ip, rack, slot); }