Beispiel #1
0
        //写并置位
        private void btnSetAndReset_Click(object sender, RoutedEventArgs e)
        {
            FmsAssetTagSetting tag = cmbTags.SelectedItem as FmsAssetTagSetting;

            if (tag == null)
            {
                return;
            }

            string error     = "";
            string sTagValue = tbTagResult.Text;

            DeviceMonitor.WriteTagToDevice(tag.PKNO, sTagValue, out error);  //写入执行的值
            if (!error.IsEmpty())
            {
                DeviceMonitor.WriteTagToDevice(tag.PKNO, sTagValue, out error);  //写入执行的值
                if (!error.IsEmpty())
                {
                    tbTagResult.Text = error;
                }
            }
            else
            {
                Thread.Sleep(200);
                DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);  //写入执行的值 置0
                if (!error.IsEmpty())
                {
                    DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);  //写入执行的值 置0
                    if (!error.IsEmpty())
                    {
                        tbTagResult.Text = error;
                    }
                }
            }
        }
Beispiel #2
0
        private static void RunInDebugMode()
        {
            ConfigureDebugLogging();

            Console.WriteLine("Running in debug");

            var deviceMonitor = new DeviceMonitor(ConfigurationManager.ConnectionStrings["MetroMonitorData"].ConnectionString);

            deviceMonitor.Initialise();
            deviceMonitor.Start();

            Console.WriteLine("Press <enter> to stop or 'cls' and <enter> to clear the log");
            while (true)
            {
                var command = Console.ReadLine() ?? "";
                switch (command)
                {
                case "cls":
                    Console.Clear();
                    break;

                default:
                    deviceMonitor.Stop();
                    return;
                }
            }
        }
        public void AdbKilledTest()
        {
            var dummyAdbServer = new DummyAdbServer();

            AdbServer.Instance = dummyAdbServer;

            using (DeviceMonitor monitor = new DeviceMonitor(this.Socket))
            {
                base.RunTest(
                    new AdbResponse[] { AdbResponse.OK, AdbResponse.OK },
                    ResponseMessages(
                        DummyAdbSocket.ServerDisconnected,
                        string.Empty),
                    Requests(
                        "host:track-devices",
                        "host:track-devices"),
                    () =>
                {
                    monitor.Start();

                    Assert.IsTrue(this.Socket.DidReconnect);
                    Assert.IsTrue(dummyAdbServer.WasRestarted);
                });
            }
        }
        public static void Run(string[] args)
        {
            Application.Init(ref args);
            GtkSharp.GstreamerSharp.ObjectManager.Initialize();

            var devmon = new DeviceMonitor();
//            var caps = new Caps("video/x-raw");
//            var filtId = devmon.AddFilter("Video/Source", caps);

            var bus = devmon.Bus;

            bus.AddWatch(OnBusMessage);
            if (!devmon.Start())
            {
                "Device monitor cannot start".PrintErr();
                return;
            }

            Console.WriteLine("Video devices count = " + devmon.Devices.Length);
            foreach (var dev in devmon.Devices)
            {
                DumpDevice(dev);
            }

            var loop = new GLib.MainLoop();

            loop.Run();
        }
Beispiel #5
0
        public DeviceMonitor StartMonitor()
        {
            var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));

            monitor.Start();
            return(monitor);
        }
Beispiel #6
0
 private void ManageDeviceMonitor(bool startMonitor)
 {
     while (true)
     {
         if (startMonitor)
         {
             try
             {
                 monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));
                 monitor.DeviceConnected    += OnDeviceConnected;
                 monitor.DeviceDisconnected += OnDeviceDisconnected;
                 monitor.Start();
                 break;
             }
             catch (System.Net.Sockets.SocketException se)
             {
                 mainForm.SetLastStatus($"{se.Message}. Trying again...");
                 continue;
             }
         }
         else
         {
             if (monitor != null && monitor.IsRunning)
             {
                 monitor = null;
             }
             break;
         }
     }
 }
Beispiel #7
0
        private void Test_Click_2(object sender, RoutedEventArgs e)
        {
            DeviceMonitor device = new DeviceMonitor();

            device.Do();
            bGo.IsEnabled = false;
        }
        public void StartInitialDeviceListTest()
        {
            using (DeviceMonitor monitor = new DeviceMonitor(this.Socket))
            {
                DeviceMonitorSink sink = new DeviceMonitorSink(monitor);

                Assert.AreEqual(0, monitor.Devices.Count);

                base.RunTest(
                    OkResponse,
                    ResponseMessages("169.254.109.177:5555\tdevice\n"),
                    Requests("host:track-devices"),
                    () =>
                {
                    monitor.Start();

                    Assert.AreEqual(1, monitor.Devices.Count);
                    Assert.AreEqual("169.254.109.177:5555", monitor.Devices.ElementAt(0).Serial);
                    Assert.AreEqual(1, sink.ConnectedEvents.Count);
                    Assert.AreEqual("169.254.109.177:5555", sink.ConnectedEvents[0].Device.Serial);
                    Assert.AreEqual(0, sink.ChangedEvents.Count);
                    Assert.AreEqual(0, sink.DisconnectedEvents.Count);
                });
            }
        }
 public bool RunServer(int websocketport = 0)
 {
     adb_server_ = new AdbServer();
     try
     {
         var ret = adb_server_.StartServer(adb_path_, true);
         if (ret != StartServerResult.Started)
         {
             adb_server_.RestartServer();
         }
         var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));
         monitor.DeviceConnected    += this.OnDeviceConnectedNotify;
         monitor.DeviceDisconnected += this.OnDeviceDisconnectedNotify;
         monitor.DeviceChanged      += this.OnDeviceChangedNotify;
         monitor.Start();
     }
     catch (Exception e)
     {
         log_.Error($"RunServer {e.ToString()}");
         adb_server_ = null;
         return(false);
     }
     finally
     {
     }
     RunWebSocket(websocketport);
     return(true);
 }
        private void InitializeDeviceUpdate()
        {
            DeviceMonitor deviceMonitor;

            lock (mSyncLock)
            {
                if (mDeviceMonitor != null && mDeviceMonitor.IsBound)
                {
                    return;
                }

                if (mDeviceMonitor == null || mDeviceMonitor.StopRequested)
                {
                    mDeviceMonitor = new DeviceMonitor();
                }

                mDeviceMonitor.ActivityProvider = this;

                deviceMonitor = mDeviceMonitor;
            }

            deviceMonitor.DeviceStatusChanged += MDeviceMonitor_DeviceStatusChanged;

            deviceMonitor.Start();
        }
        void InitGStreamerPipeline()
        {
            _mainLoop       = new GLib.MainLoop();
            _mainGlibThread = new System.Threading.Thread(_mainLoop.Run);
            _mainGlibThread.Start();

            _pipeline = CreatePipeline("camera-pipeline");
            Assert(_pipeline != null, "Pipeline could not be created");

            _pipeline.Bus.EnableSyncMessageEmission();
            _pipeline.Bus.SyncMessage += OnBusSyncMessage;
            _pipeline.Bus.AddWatch(OnBusMessage);

            _devMon = new DeviceMonitor();
            var caps   = new Caps("video/x-raw");
            var filtId = _devMon.AddFilter("Video/Source", caps);

            foreach (var d in _devMon.Devices.Select(d => d.DisplayName))
            {
                _devices.Add(d);
            }

            var cam = _devMon.Devices.FirstOrDefault(d => d.DeviceClass == "Video/Source");

            if (cam != null)
            {
                ShowCamera(cam.DisplayName);
            }

            Assert(_devMon.Start(), "Device monitor cannot start");
            _devMon.Bus.AddWatch(OnBusMessage);
        }
Beispiel #12
0
        public static void MonitorDevicesConnection(EventHandler <DeviceDataEventArgs> eventHandler)
        {
            var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));

            monitor.DeviceChanged      += eventHandler;
            monitor.DeviceDisconnected += eventHandler;
            monitor.Start();
        }
Beispiel #13
0
        private void Moniter()
        {
            var monitor = new DeviceMonitor(AdbSocket);

            monitor.DeviceConnected    += this.OnDeviceConnected;
            monitor.DeviceDisconnected += this.onDeviceDisConnected;
            monitor.Start();
        }
Beispiel #14
0
        private void btnTest2_Click(object sender, RoutedEventArgs e)
        {
            string pkno = cmbTags.SelectedValue?.ToString();

            tbValue.Text = copyTags.FirstOrDefault(c => c.PKNO == pkno)?.CUR_VALUE ?? "";

            tbValueOld.Text = DeviceMonitor.GetTagSettingById(pkno)?.CUR_VALUE ?? "";
        }
Beispiel #15
0
        void TestDeviceConnect()
        {
            var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));

            monitor.DeviceConnected    += Monitor_DeviceConnected;
            monitor.DeviceDisconnected += Monitor_DeviceDisconnected;
            monitor.Start();
        }
 public void DisposeMonitorTest()
 {
     using (DeviceMonitor monitor = new DeviceMonitor(new AdbSocket(AdbServer.Instance.EndPoint)))
     {
         monitor.Start();
         Thread.Sleep(1000);
     }
 }
Beispiel #17
0
        private static void ListenForDevices()
        {
            var sock = new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort);

            _monitor = new DeviceMonitor(new AdbSocket(sock));
            _monitor.DeviceConnected    += OnDeviceConnected;
            _monitor.DeviceDisconnected += OnDeviceDisconnected;
            _monitor.Start();
        }
 protected override void OnStart(string[] args)
 {
     Logger.Info(i => i("Initialising Device Monitor"));
     _deviceMonitor =
         new DeviceMonitor(ConfigurationManager.ConnectionStrings["MetroMonitorData"].ConnectionString);
     _deviceMonitor.Initialise();
     _deviceMonitor.Start();
     Logger.Info(i => i("Service Successfully Started"));
 }
Beispiel #19
0
        public static void StartAdbMonitor()
        {
            var monitor = new DeviceMonitor(new AdbSocket(AdbServer.Instance.EndPoint));

            monitor.DeviceConnected    += Monitor_DeviceConnected;
            monitor.DeviceDisconnected += Monitor_DeviceDisconnected;
            monitor.DeviceChanged      += Monitor_DeviceChanged;
            monitor.Start();
        }
Beispiel #20
0
 /// <summary>
 /// 監視を停止します。
 /// </summary>
 public void Stop()
 {
     if (this.monitor == null)
     {
         return;
     }
     this.monitor.Dispose();
     this.monitor = null;
 }
        public void Stop_ForInvoked_CallsStop(
            DeviceMonitor sut,
            [Freeze] IWatcher watcher)
        {
            sut.Stop();

            watcher.Received()
            .Stop();
        }
 /// <summary>
 /// Create new adb controller
 /// </summary>
 /// <param name="adbPath"></param>
 internal AdbController(string adbPath, ILog logger)
 {
     server.StartServer(Path.Combine(adbPath, "adb.exe"), false);
     this.logger = logger;
     KillPortUsage();
     monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));
     monitor.DeviceConnected    += OnDeviceConnected;
     monitor.DeviceDisconnected += OnDeviceDisconnected;
     devices = client.GetDevices();
 }
        /* example:
         * monitor_usb_devices("Win32_USBControllerDevice");
         * monitor_usb_devices("Win32_USBHub");
         */
        public static void monitor_usb_devices(string usb_class)
        {
            var md = new DeviceMonitor()
            {
                DeviceAddedEvent = on_DeviceAddedEvent_dump_info, DeviceDeletedEvent = OnDeletedDevice_dump_info
            };

            md.Monitor(usb_class);
            Thread.Sleep(2000000);
        }
        private DeviceMonitor CreateSut()
        {
            var deviceMonitor = new DeviceMonitor(_logger,
                                                  _scheduler,
                                                  _factory,
                                                  _devices,
                                                  _watcher);

            return(deviceMonitor);
        }
        public void RemoveDevice_ForInvoked_CallsDevices(
            DeviceMonitor sut,
            [Freeze] IDevices devices,
            IDevice device)
        {
            sut.RemoveDevice(device);

            devices.Received()
            .RemoveDevice(device);
        }
Beispiel #26
0
 public void ConstructorTest()
 {
     using (DeviceMonitor monitor = new DeviceMonitor(this.Socket))
     {
         Assert.IsNotNull(monitor.Devices);
         Assert.AreEqual(0, monitor.Devices.Count);
         Assert.AreEqual(this.Socket, monitor.Socket);
         Assert.IsFalse(monitor.IsRunning);
     }
 }
 public void ConstructorTest()
 {
     using (DeviceMonitor monitor = new DeviceMonitor(this.Socket))
     {
         Assert.IsNotNull(monitor.Devices);
         Assert.AreEqual(0, monitor.Devices.Count);
         Assert.AreEqual(this.Socket, monitor.Socket);
         Assert.IsFalse(monitor.IsRunning);
     }
 }
Beispiel #28
0
        /// <summary>
        /// Initialize Adb Server and Monitor
        /// </summary>
        public static void InitializeAdbServer(string path)
        {
            Server.StartServer(Path.GetFullPath(Path.Combine(path)), restartServerIfNewer: false);
            var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));

            Instance = CustomMonitor.Instance;
            monitor.DeviceConnected    += OnDeviceConnected;
            monitor.DeviceChanged      += OnDeviceChanged;
            monitor.DeviceDisconnected += OnDeviceDisconnected;
            monitor.Start();
        }
        public void DiscoveredDevices_ForInvoked_CallsDevices(
            DeviceMonitor sut,
            [Freeze] IDevices devices)
        {
            devices.DiscoveredDevices
            .Returns(new List <IDevice>().AsReadOnly());

            sut.DiscoveredDevices
            .Should()
            .BeEmpty();
        }
        public void IsListening_ForInvoked_CallsWatcher(
            DeviceMonitor sut,
            [Freeze] IWatcher watcher)
        {
            _watcher.IsListening
            .Returns(true);

            sut.IsListening
            .Should()
            .BeTrue();
        }
 public override void Dispose()
 {
     lock (mSyncLock)
     {
         if (mDeviceMonitor != null)
         {
             mDeviceMonitor.Abort();
             mDeviceMonitor = null;
         }
     }
 }
Beispiel #32
0
        public void DeviceChangedTest()
        {
            using (DeviceMonitor monitor = new DeviceMonitor(this.Socket))
            {
                DeviceMonitorSink sink = new DeviceMonitorSink(monitor);

                Assert.AreEqual(0, monitor.Devices.Count);

                // Start the monitor, detect the initial device.
                base.RunTest(
                OkResponse,
                ResponseMessages("169.254.109.177:5555\toffline\n"),
                Requests("host:track-devices"),
                () =>
                {
                    monitor.Start();

                    Assert.AreEqual(1, monitor.Devices.Count);
                    Assert.AreEqual(DeviceState.Offline, monitor.Devices.ElementAt(0).State);
                    Assert.AreEqual(1, sink.ConnectedEvents.Count);
                    Assert.AreEqual(0, sink.ChangedEvents.Count);
                    Assert.AreEqual(0, sink.DisconnectedEvents.Count);
                });

                this.Socket.ResponseMessages.Clear();
                this.Socket.Responses.Clear();
                this.Socket.Requests.Clear();

                // Device disconnects
                var eventWaiter = sink.CreateEventSignal();

                base.RunTest(
                NoResponses,
                ResponseMessages("169.254.109.177:5555\tdevice\n"),
                Requests(),
                () =>
                {
                    eventWaiter.WaitOne(1000);

                    Assert.AreEqual(1, monitor.Devices.Count);
                    Assert.AreEqual(DeviceState.Online, monitor.Devices.ElementAt(0).State);
                    Assert.AreEqual(1, sink.ConnectedEvents.Count);
                    Assert.AreEqual(1, sink.ChangedEvents.Count);
                    Assert.AreEqual(0, sink.DisconnectedEvents.Count);
                    Assert.AreEqual("169.254.109.177:5555", sink.ChangedEvents[0].Device.Serial);
                });
            }
        }
Beispiel #33
0
        public DeviceMonitorSink(DeviceMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException(nameof(monitor));
            }

            this.Monitor = monitor;
            this.Monitor.DeviceChanged += OnDeviceChanged;
            this.Monitor.DeviceConnected += OnDeviceConnected;
            this.Monitor.DeviceDisconnected += OnDeviceDisconnected;

            this.ChangedEvents = new Collection<DeviceDataEventArgs>();
            this.DisconnectedEvents = new Collection<DeviceDataEventArgs>();
            this.ConnectedEvents = new Collection<DeviceDataEventArgs>();
        }
Beispiel #34
0
        /// <summary>
        /// Connects the specified device.
        /// </summary>
        /// <param name="device">The device.</param>
        public void Connect( string device )
        {
            try {

                if ( DeviceMonitor != null ) {
                    DeviceMonitor.Stop ( );
                    DeviceMonitor = null;
                }

                DeviceMonitor = new DeviceMonitor ( device );
                DeviceMonitor.Connected += ( s, e ) => {
                    if ( this.Connected != null ) {
                        this.State = e.State;
                        this.Connected ( this, e );
                    }
                };
                DeviceMonitor.Disconnected += ( s, e ) => {
                    Disconnect ( e.Device );
              if ( this.Disconnected != null ) {
                        this.State = e.State;
                        this.Disconnected ( this, e );
                    }
                };
                DeviceMonitor.DeviceStateChanged += ( s, e ) => {
                    if ( this.DeviceStateChanged != null ) {
                        this.State = e.State;
                        this.DeviceStateChanged ( this, e );
                    }
                };

                DeviceMonitor.Start ( );
              } catch ( Exception ex ) {
                this.LogError ( ex.Message, ex );
                State = DeviceState.Unknown;
            }
        }
Beispiel #35
0
 public void ConstructorNullTest()
 {
     DeviceMonitor monitor = new DeviceMonitor(null);
 }
Beispiel #36
0
        public void StartInitialDeviceListTest()
        {
            using (DeviceMonitor monitor = new DeviceMonitor(this.Socket))
            {
                DeviceMonitorSink sink = new DeviceMonitorSink(monitor);

                Assert.AreEqual(0, monitor.Devices.Count);

                base.RunTest(
                OkResponse,
                ResponseMessages("169.254.109.177:5555\tdevice\n"),
                Requests("host:track-devices"),
                () =>
                {
                    monitor.Start();

                    Assert.AreEqual(1, monitor.Devices.Count);
                    Assert.AreEqual("169.254.109.177:5555", monitor.Devices.ElementAt(0).Serial);
                    Assert.AreEqual(1, sink.ConnectedEvents.Count);
                    Assert.AreEqual("169.254.109.177:5555", sink.ConnectedEvents[0].Device.Serial);
                    Assert.AreEqual(0, sink.ChangedEvents.Count);
                    Assert.AreEqual(0, sink.DisconnectedEvents.Count);
                });
            }
        }