static void Main(string[] args) { var ip = "10.10.11.38"; var plc = new S7.Net.Plc(CpuType.S7300, ip, 0, 2); Console.WriteLine("Connecting " + ip); plc.Open(); Console.WriteLine("Reading items"); var tc = new ByteTest(); plc.ReadClass(tc, 800, 0); plc.Close(); // result Console.WriteLine("Results: "); var t = typeof(ByteTest); PropertyInfo[] propInfos = t.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var item in propInfos) { var val = tc.GetType().GetProperty(item.Name).GetValue(tc, null); Console.WriteLine("{0}: {1}", item.Name, val.ToString()); } // keep console open Console.WriteLine("Press [Enter] to exit."); Console.Read(); }
public async Task Execute(S7.Net.Plc plc) { await plc.WriteAsync(Address, true); await Task.Delay(100); // TODO - make param configurable from file or UI await plc.WriteAsync(Address, false); }
public Form1() { InitializeComponent(); // new plc instance MyPlc = new S7.Net.Plc(S7.Net.CpuType.S71500, "192.168.0.1", 0, 0); // connect to PLC MyPlc.Open(); // read a value var plcValue = MyPlc.Read("DB8.DBD2"); }
private static void Open() { string type = Global.Configuration.Type ?? Energy.Core.Tilde.Ask("S7 Type", "1500"); var cpu = S7.Net.CpuType.S71500; switch ((type ?? "").ToUpper()) { case "1200": cpu = S7.Net.CpuType.S71200; break; case "300": cpu = S7.Net.CpuType.S7300; break; case "200": cpu = S7.Net.CpuType.S7200; break; case "400": cpu = S7.Net.CpuType.S7400; break; case "1500": cpu = S7.Net.CpuType.S71500; break; case "LOGO": cpu = S7.Net.CpuType.Logo0BA8; break; default: Energy.Core.Tilde.WriteLine("~r~Uknown S7 type, possible values are ~y~200~r~, ~y~300~r~, ~y~400~r~, ~y~1200~r~, ~y~1500~r~, and ~y~LOGO~r~!"); return; } string host = Global.Configuration.Host ?? Energy.Core.Tilde.Ask("S7 Host", "192.168.0.1"); int port = Energy.Base.Cast.As <int>(Global.Configuration.Port); if (0 == port) { port = Energy.Core.Tilde.Ask <int>("S7 Port", 102); } short rack = Energy.Base.Cast.As <short>(Global.Configuration.Rack); if ("0" != Global.Configuration.Rack && 0 == rack) { rack = Energy.Core.Tilde.Ask <short>("S7 Rack", 0); } short slot = Energy.Base.Cast.As <short>(Global.Configuration.Slot); if ("0" != Global.Configuration.Slot && 0 == slot) { slot = Energy.Core.Tilde.Ask <short>("S7 Slot", 1); } var plc = new S7.Net.Plc(cpu, host, port, rack, slot); plc.Open(); if (!plc.IsConnected) { Energy.Core.Tilde.WriteLine("~r~Can't connect to PLC"); return; } if (!Global.Configuration.Quiet) { Energy.Core.Tilde.WriteLine("~lc~PLC connection open"); } Global.Plc = plc; }
public PLC(S7.Net.CpuType cpuType, IPAddress iPAddress, short rack, short slot) { string ip = iPAddress.ToString(); _plc = new S7.Net.Plc(cpuType, ip, rack, slot); }