Esempio n. 1
0
        public fTestDeviceNotify()
        {
            InitializeComponent();
            devNotifier = DeviceNotifier.OpenDeviceNotifier();

            devNotifier.OnDeviceNotify += onDevNotify;
        }
        public MainWindow()
        {
            InitializeComponent();

            autoReadTimer          = new DispatcherTimer();
            autoReadTimer.Tick    += new EventHandler(autoReadObjects);
            autoReadTimer.Interval = new TimeSpan(0, 0, 1);   // Hours, Minutes, Seconds



            // try to connect to device. Show status in status bar
            try
            {
                traqpaq = new TraqpaqDevice();
                // update status bar
                //traqpaq.myOTPreader.reqSerialNumber();
                statusBarItemTraqpaq.Content = "Device connected";
                oneTimeRead();
                autoReadTimer.Start();
            }
            catch (TraqPaqNotConnectedException)
            {
                // Device not found
                traqpaq = null;
                // update status bar
                statusBarItemTraqpaq.Content = "Device not found";
                // Set up event handler to wait for a usb device to connect to
                deviceNotifier = DeviceNotifier.OpenDeviceNotifier();
                deviceNotifier.OnDeviceNotify += new EventHandler <DeviceNotifyEventArgs>(deviceNotifier_OnDeviceNotify);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Objeto construtor
        /// </summary>
        public Serial() : base()
        {
            devNotifier = DeviceNotifier.OpenDeviceNotifier();
            devNotifier.OnDeviceNotify += (object sender, DeviceNotifyEventArgs e) =>
            {
                if (e == null || e.Device == null)
                {
                    return;
                }

                string idportcom = PortCom.HardwareID.Split('&')[1];
                string iddevnoti = e.Device.Name.Split('#')[1].Split('&')[0];

                if (e.EventType == EventType.DeviceArrival)
                {
                    if (idportcom == iddevnoti)
                    {
                        RaiseAoConectarCaboUSB($"O equipamento {PortCom.Fabricante} {PortCom.Modelo} foi localizado\nporém não foi possível determinar se ele ainda está utilizando a mesma porta de conexão");
                    }

                    return;
                }

                if (idportcom == iddevnoti)
                {
                    TratamentoErros erro     = new TratamentoErros();
                    string          mensagem = $"O equipamento  {PortCom.Fabricante} {PortCom.Modelo} foi desconectado da porta {PortCom.PortName}";
                    erro.Mensagem = mensagem;
                    erro.Numero   = 1;
                    erro.Detalhes = new Exception(mensagem);
                    RaiseAoEncontrarErro(erro);
                }
            };
        }
Esempio n. 4
0
 /// <summary>
 /// Creates an instance of a USB device using a VID PID pair
 /// </summary>
 /// <param name="vid">VID</param>
 /// <param name="pid">PID</param>
 public VUsbDevice(int vid, int pid)
 {
     MyUsbFinder       = new UsbDeviceFinder(vid, pid);
     UsbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier();
     UsbDeviceNotifier.OnDeviceNotify += new EventHandler <DeviceNotifyEventArgs>(UsbDeviceNotifier_OnDeviceNotify);
     UsbDeviceNotifier.Enabled         = true;
 }
Esempio n. 5
0
        public void RegDeviceEvent(bool b)
        {
            if (this.devNotifier == null)
            {
                this.devNotifier = DeviceNotifier.OpenDeviceNotifier();
            }
            try
            {
                switch (b)
                {
                case false:
                {
                    this.IsRegistered = false;
                    this.devNotifier.OnDeviceNotify -= (new EventHandler <DeviceNotifyEventArgs>(this.devNotifier_OnDeviceNotify));
                    break;
                }

                case true:
                {
                    this.IsRegistered = true;
                    this.USBDrive     = string.Empty;
                    this.devNotifier.OnDeviceNotify -= (new EventHandler <DeviceNotifyEventArgs>(this.devNotifier_OnDeviceNotify));
                    this.devNotifier.OnDeviceNotify += (new EventHandler <DeviceNotifyEventArgs>(this.devNotifier_OnDeviceNotify));
                    break;
                }
                }
            }
            catch
            {
            }
        }
 public RemoteManager()
 {
     InitializeComponent();
     manager                           = new ManagerHandler(this, managerColour);
     USBDeviceNotifier                 = DeviceNotifier.OpenDeviceNotifier();
     USBDeviceNotifier.Enabled         = false;
     USBDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent;
 }
Esempio n. 7
0
        /// <summary>
        /// USB插拔监控
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button15_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();

            //判断设备连接情况
            devNotifier = DeviceNotifier.OpenDeviceNotifier();
            devNotifier.OnDeviceNotify += onDevNotify;
        }
        private LCTFController()
        {
            this.usbFinder         = new UsbDeviceFinder(new Guid("{d67436ae-96c7-4da3-83c9-322c4ceb41f3}"));
            this.usbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier();
            this.usbDeviceNotifier.OnDeviceNotify += this.OnDeviceNotify;
            this.usbDeviceNotifier.Enabled         = true;

            this.UpdateAttachedDevices();
        }
Esempio n. 9
0
 public ArduinoUsbDevice(int vendorId, int productId)
 {
     _vendorId          = vendorId;
     _productId         = productId;
     _myUsbFinder       = new UsbDeviceFinder(_vendorId, _productId);
     _usbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier();
     _usbDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent;
     ConnectUsbDevice();
 }
Esempio n. 10
0
 public Teensy(int pid, int vid)
 {
     _vid         = vid;
     _pid         = pid;
     _usbFinder   = new UsbDeviceFinder(_vid, _pid);
     _buffer      = null;
     _devNotifier = DeviceNotifier.OpenDeviceNotifier();
     _devNotifier.OnDeviceNotify += OnDeviceNotify;
 }
 protected override void Initialize()
 {
     #if IOS
     startPollThread();
     #else
     UsbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier();
     UsbDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent;
     #endif
 }
Esempio n. 12
0
 protected override bool ReleaseHandle()
 {
     if (handle != IntPtr.Zero)
     {
         bool bSuccess = DeviceNotifier.UnregisterDeviceNotification(handle);
         handle = IntPtr.Zero;
         return(bSuccess);
     }
     return(false);
 }
Esempio n. 13
0
        public Form1()
        {
            InitializeComponent();

            devNotifier = DeviceNotifier.OpenDeviceNotifier();

            //    devNotifier.OnDeviceNotify += onDevNotify;

            devNotifier.OnDeviceNotify += new EventHandler <DeviceNotifyEventArgs>(onDevNotify);
        }
Esempio n. 14
0
        private void AttachUsbNotifier()
        {
            usbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier();
            usbDeviceNotifier.OnDeviceNotify += OnDeviceNotify;

            while (true)
            {
                Application.DoEvents();
            }
        }
Esempio n. 15
0
        public FirmwareManagerForm()
        {
            InitializeComponent();
            devNotifier = DeviceNotifier.OpenDeviceNotifier();
            // devNotifier.OnDeviceNotify += devNotifier_OnDeviceNotify;

            TreehopperManager manager = new TreehopperManager();

            manager.BoardAdded   += manager_BoardAdded;
            manager.BoardRemoved += manager_BoardRemoved;
        }
Esempio n. 16
0
        public ClearShotWinUsbService()
        {
            _targetDevice = UsbDevice.OpenUsbDevice(x => x.Pid == ClearShotDevice.ProductId && x.Vid == ClearShotDevice.VendorId);

            if (_targetDevice != null)
            {
                OnConnected(this, EventArgs.Empty);
            }

            _devNotifier = DeviceNotifier.OpenDeviceNotifier();
            _devNotifier.OnDeviceNotify += OnDevNotify;
        }
Esempio n. 17
0
 public MainWindow()
 {
     InitializeComponent();
     _UsbKeyDataStruct           = new UsbKeyDataStruct();
     devNotifier                 = DeviceNotifier.OpenDeviceNotifier();
     devNotifier.OnDeviceNotify += devNotifier_OnDeviceNotify;
     this.Loaded                += new RoutedEventHandler(MainWindow_Loaded);
     btnG.IsEnabled              = false;
     // byte[] aaa = new byte[12] { 0x35, 0x77, 0x61, 0x54, 0x42, 0x6A, 0x49, 0x44, 0x46, 0x2f, 0x34, 0x3d };
     //byte[] ret = Decrypt(aaa);
     // string aa = System.Text.Encoding.Default.GetString(ret);
     ;
 }
Esempio n. 18
0
        public UsbMonitor()
        {
            switch (HidSharp.PlatformDetector.RunningPlatform())
            {
            case HidSharp.PlatformDetector.Platform.Windows:
                winUsbDeviceMonitor = new WinUsbDeviceMonitor();
                winUsbDeviceMonitor.DeviceListChanged += HandleDeviceListChanged;
                break;

            case HidSharp.PlatformDetector.Platform.Linux:
                UsbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier();
                UsbDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent;
                break;
            }
        }
Esempio n. 19
0
        public MainWindow()
        {
            InitializeComponent();
            _UsbKeyDataStruct           = new UsbKeyDataStruct();
            devNotifier                 = DeviceNotifier.OpenDeviceNotifier();
            devNotifier.OnDeviceNotify += devNotifier_OnDeviceNotify;
            this.Loaded                += new RoutedEventHandler(MainWindow_Loaded);
            btnG.IsEnabled              = false;
            Uri        uri = new Uri(@"disconnect.jpg", UriKind.Relative);
            ImageBrush ib  = new ImageBrush();

            ib.ImageSource    = new BitmapImage(uri);
            ib.Stretch        = Stretch.Uniform;
            lbicon.Background = ib;
        }
Esempio n. 20
0
        public UsbPanel()
        {
            InitializeComponent();

            this.Icon = Icon.FromHandle(GraphicsResx.usbpanelicon.GetHicon());

            try
            {
                UsbDevice.UsbErrorEvent += OnUsbError;

                devNotifier = DeviceNotifier.OpenDeviceNotifier();
                devNotifier.OnDeviceNotify += onDevNotify;

                FillDeviceInfo();
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Error Initializing USB Panel");
            }
        }
Esempio n. 21
0
        public void BeginDiscovery()
        {
            if (m_usbNotifier != null)
            {
                throw new InvalidOperationException();
            }

            // Test all the loaded HID devices to see if they're valid
            HidDeviceLoader loader = new HidDeviceLoader();

            foreach (var device in loader.GetDevices())
            {
                DeviceID id = new DeviceID(device);
                IInitDevice(id, DeviceEventType.DeviceDiscovered);
            }

            // Register for new device insertions
            m_usbNotifier = DeviceNotifier.OpenDeviceNotifier();
            m_usbNotifier.OnDeviceNotify += IOnUsbNotify;
        }
Esempio n. 22
0
        protected override EventResult OnConnectBusy()
        {
            try {
                if (usb_finder_ == null)
                {
                    usb_finder_ = new UsbDeviceFinder((int)devp_.CommVendorID.Value, (int)devp_.CommProductID.Value);
                }

                if ((devp_.DeviceEventCapture.Value) && (usb_notifier_ == null))
                {
                    usb_notifier_         = DeviceNotifier.OpenDeviceNotifier();
                    usb_notifier_.Enabled = false;
                }

                if (usb_notifier_ != null)
                {
                    usb_notifier_.Enabled         = false;
                    usb_notifier_.OnDeviceNotify -= OnUsbDeviceNotify;
                    usb_notifier_.OnDeviceNotify += OnUsbDeviceNotify;
                    usb_notifier_.Enabled         = true;
                }

                if ((devp_.DeviceComm.Value) && (usb_device_ == null) && (usb_finder_ != null))
                {
                    usb_device_ = UsbDevice.OpenUsbDevice(usb_finder_);
                }

                if (((devp_.DeviceEventCapture.Value) && (usb_notifier_ == null)) ||
                    ((devp_.DeviceComm.Value) && (usb_device_ == null))
                    )
                {
                    return(EventResult.Busy);
                }

                return(EventResult.Success);
            } catch {
                return(EventResult.Busy);
            }
        }
Esempio n. 23
0
 public Form1()
 {
     InitializeComponent();
     mDevNotifier = new DeviceNotifier();
     mDevNotifier.OnDeviceNotify += new EventHandler <DeviceNotifyEventArgs>(mDevNotifier_OnDeviceNotify);
 }
Esempio n. 24
0
 public void Hook()
 {
     UsbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier();
     UsbDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent;
 }
Esempio n. 25
0
 public void fDeviceNotify()
 {
     devNotifier = DeviceNotifier.OpenDeviceNotifier();
     devNotifier.OnDeviceNotify += onDevNotify;
 }
Esempio n. 26
0
        public MainControl()
        {
            InitializeComponent();
            //初始化浏览器
            this.initChartBrowser();
            this.chartBrowser.Navigate(dirRoot + @"\Views\Browser\main.html");

            //若过了试用期并且未注册,则不进行U盘监听
            if (!deviceService.CheckEffective())
            {
                return;
            }
            deviceDic      = new Dictionary <string, bool>();
            deviceNotifier = DeviceNotifier.OpenDeviceNotifier();
            deviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent;

            try
            {
                allUsbDrives = DriveInfo.GetDrives().Where(x => x.DriveType == DriveType.Removable).ToArray();
                //开启任务异步操作,避免多个采集站统计加载时界面假死
                Thread ts = new Thread(() =>
                {
                    var resourceIndex = 0;
                    var searcher      = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDiskToPartition");
                    foreach (ManagementObject dm in searcher.Get())
                    {
                        var drive   = getValueInQuotes(dm["Dependent"].ToString()) + @"\";
                        diskArray   = getValueInQuotes(dm["Antecedent"].ToString()).Split(',');
                        driveNumber = Convert.ToInt32(diskArray[0].Remove(0, 6).Trim());
                        var disks   = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
                        foreach (ManagementObject disk in disks.Get())
                        {
                            if (disk["Name"].ToString() == ("\\\\.\\PHYSICALDRIVE" + driveNumber.ToString()) & disk["InterfaceType"].ToString() == "USB")
                            {
                                DeviceControl device = new DeviceControl();
                                var serialNumber     = parseSerialFromDeviceID(disk["PNPDeviceID"].ToString()).ToUpper();
                                DriveInfo d          = allUsbDrives.FirstOrDefault(x => x.Name == drive);
                                if (d == null)
                                {
                                    continue;
                                }
                                var deviceName = d.Name;
                                var deviceRoot = d.RootDirectory;
                                var checkToken = device.CheckDeviceToken(deviceName, serialNumber);
                                if (checkToken < 0)
                                {
                                    continue;
                                }
                                if (resourceIndex == 0)
                                {
                                    MessageUtil.ShowMessage("资源已就绪,开始采集...", EnumData.MessageType.Information, this);
                                    resourceIndex++;
                                }
                                device.SetProgressDelegate += HandleRefreshProgess;
                                Action <DirectoryInfo, string> copyAction = device.CopyFilesTo;
                                copyAction.BeginInvoke(deviceRoot, serialNumber, null, null);
                            }
                        }
                    }
                });
                ts.IsBackground = true;
                ts.Start();
            }
            catch
            {
                MessageUtil.ShowMessage("资源识别失败,请重启程序!", EnumData.MessageType.Warning, this);
            }
        }