public AtemDiscoveryService(int updatePeriod = 10000, bool debug = false)
        {
            _debug        = debug;
            _knownDevices = new Dictionary <string, AtemDeviceInfo>();

            _mdns         = new MulticastService();
            _mdns.UseIpv4 = true;
            _mdns.UseIpv6 = false;
            _mdns.NetworkInterfaceDiscovered += (s, e) => SendQuery();
            _mdns.AnswerReceived             += (s, e) => AnswerReceived(e.Message);
            _mdns.Start();

            _updateTimer = new Timer(a => {
                DateTime now = DateTime.Now;

                lock (_knownDevices)
                {
                    List <string> ids = _knownDevices.Keys.ToList();
                    foreach (string id in ids)
                    {
                        AtemDeviceInfo dev = _knownDevices[id];
                        // Remove if not seen in too long
                        if (dev != null && now.Subtract(dev.LastSeen).TotalMilliseconds > updatePeriod * 3)
                        {
                            _knownDevices.Remove(id);
                            OnDeviceLost?.Invoke(this, dev);
                        }
                    }
                }

                SendQuery();
            }, null, updatePeriod, updatePeriod);
        }
示例#2
0
        /// <summary>
        /// controls the read thread
        /// </summary>
        public async void StartReadHIDReport()
        {
            var t = DoReadHIDReport(cts.Token);

            try
            {
                await t;
            }
            catch (Exception ex)
            {
                // Do nothing if error
            }
            finally
            {
                this.DisconnectDevice();

                OnDeviceLost?.Invoke(this, new EventArgs());
            }
        }
 /// <summary>
 /// Raises the on device lost.
 /// </summary>
 protected void RaiseOnDeviceLost()
 {
     OnDeviceLost?.Invoke(this, EventArgs.Empty);
 }