public ZoneChecker(RoadLink connection, int interval) { if (connection == null) { throw new ArgumentNullException(); } Connection = connection; Connection.Disconnected += Connection_Disconnected; checkTimer = new Timer(interval * 1000); checkTimer.Elapsed += CheckTimer_Elapsed; checkTimer.Start(); }
private void Discover() { EventWaitHandle waithandler = new EventWaitHandle( false, EventResetMode.AutoReset, Guid.NewGuid().ToString()); while (startDiscovering) { // possible fix for OSX's toomanyfilesexception GC.Collect(); string[] ports = SerialPort.GetPortNames(); foreach (string p in ports) { foreach (Link l in Links) { if (p == l.Address) { continue; } } SerialPort sp = new SerialPort(p, baudRate); if (DetectRoadAt(sp)) { RoadLink rl = new RoadLink(this, sp); NewLink(rl); } else { sp.Close(); sp.Dispose(); } } // discover at interval to reduce cpu usage waithandler.WaitOne(TimeSpan.FromSeconds(discoverInterval)); } }