Ejemplo n.º 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;
                    }
                }
            }
        }
Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 5
0
        public DeviceMonitor StartMonitor()
        {
            var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));

            monitor.Start();
            return(monitor);
        }
Ejemplo n.º 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;
         }
     }
 }
Ejemplo n.º 7
0
        private void Test_Click_2(object sender, RoutedEventArgs e)
        {
            DeviceMonitor device = new DeviceMonitor();

            device.Do();
            bGo.IsEnabled = false;
        }
Ejemplo n.º 8
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);
                });
            }
        }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 13
0
        private void Moniter()
        {
            var monitor = new DeviceMonitor(AdbSocket);

            monitor.DeviceConnected    += this.OnDeviceConnected;
            monitor.DeviceDisconnected += this.onDeviceDisConnected;
            monitor.Start();
        }
Ejemplo n.º 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 ?? "";
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 16
0
 public void DisposeMonitorTest()
 {
     using (DeviceMonitor monitor = new DeviceMonitor(new AdbSocket(AdbServer.Instance.EndPoint)))
     {
         monitor.Start();
         Thread.Sleep(1000);
     }
 }
Ejemplo n.º 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"));
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 20
0
 /// <summary>
 /// 監視を停止します。
 /// </summary>
 public void Stop()
 {
     if (this.monitor == null)
     {
         return;
     }
     this.monitor.Dispose();
     this.monitor = null;
 }
Ejemplo n.º 21
0
        public void Stop_ForInvoked_CallsStop(
            DeviceMonitor sut,
            [Freeze] IWatcher watcher)
        {
            sut.Stop();

            watcher.Received()
            .Stop();
        }
Ejemplo n.º 22
0
 /// <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();
 }
Ejemplo n.º 23
0
        /* 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);
        }
Ejemplo n.º 24
0
        private DeviceMonitor CreateSut()
        {
            var deviceMonitor = new DeviceMonitor(_logger,
                                                  _scheduler,
                                                  _factory,
                                                  _devices,
                                                  _watcher);

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

            devices.Received()
            .RemoveDevice(device);
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 27
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);
     }
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 29
0
        public void DiscoveredDevices_ForInvoked_CallsDevices(
            DeviceMonitor sut,
            [Freeze] IDevices devices)
        {
            devices.DiscoveredDevices
            .Returns(new List <IDevice>().AsReadOnly());

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

            sut.IsListening
            .Should()
            .BeTrue();
        }
Ejemplo n.º 31
0
 public override void Dispose()
 {
     lock (mSyncLock)
     {
         if (mDeviceMonitor != null)
         {
             mDeviceMonitor.Abort();
             mDeviceMonitor = null;
         }
     }
 }
Ejemplo n.º 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);
                });
            }
        }
Ejemplo n.º 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>();
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 35
0
 public void ConstructorNullTest()
 {
     DeviceMonitor monitor = new DeviceMonitor(null);
 }
Ejemplo n.º 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);
                });
            }
        }