This helper class helps you find IP addresses of the PLC devices on your network by their serial numbers (MAC) in a non-blocking manner.
protected override void OnLoad(EventArgs e) { base.OnLoad(e); tabControl1_SelectedIndexChanged(tabControl1, EventArgs.Empty); LogManager.LogFired += new LogManager.LogHandler(LogManager_LogFired); m_finder = new Finder(); m_finder.DeviceFound += new Finder.DeviceFoundHandler(m_finder_DeviceFound); rwHB.StringViewVisible = true; rwHB.LineInfoVisible = true; rwHB.UseFixedBytesPerLine = true; rwHB.BytesPerLine = 16; rwHB.VScrollBarVisible = true; readWriteP.Controls.Add(rwHB); DynamicByteProvider dbp = new DynamicByteProvider(new byte[1]); dbp.LengthChanged +=new EventHandler(writeRawLengthChangedHandler); rwHB.ByteProvider = dbp; }
static void Main(string[] args) { /* args = new string[4]; args[0] = "00:25:fc:00:02:bd"; args[1] = "1234"; args[2] = "fw"; args[3] = @"C:\users\engin\code\workspace-cpp\plc\app\plc.bin.enda"; * */ m_args = args; if (args.Length < 2) { Console.Error.WriteLine("Usage: plcctrl MAC|IP PASS ACTION PARAMS"); return; } IPEndPoint ip = null; if (args[0].Contains(":")) { Finder f = new Finder(); f.DeviceFound += new Finder.DeviceFoundHandler(f_DeviceFound); f.Scan(); m_wait.WaitOne(5000); } else { ip = new IPEndPoint(IPAddress.Parse(args[0]), 23); doit(ip, args); } }