Esempio n. 1
0
        public UsbHidPort()
        {
            //initializing in initial state
            product_id       = 0;
            vendor_id        = 0;
            specified_device = null;
            device_class     = Win32Usb.HIDGuid;

            InitializeComponent();
        }
Esempio n. 2
0
        public UsbHidPort(IContainer container)
        {
            //initializing in initial state
            product_id       = 0;
            vendor_id        = 0;
            specified_device = null;
            device_class     = Win32Usb.HIDGuid;

            container.Add(this);
            InitializeComponent();
        }
Esempio n. 3
0
        /// <summary>
        /// Checks the devices that are present at the moment and checks if one of those
        /// is the device you defined by filling in the product id and vendor id.
        /// </summary>
        public void CheckDevicePresent()
        {
            try
            {
                //Mind if the specified device existed before.
                bool history = false;
                if (specified_device != null)
                {
                    history = true;
                }
                //USB\VID_0C2E&PID_0EE7
                //USB\VID_2571&PID_4101

                specified_device = SpecifiedDevice.FindSpecifiedDevice(this.vendor_id, this.product_id); // look for the device on the USB bus
                if (specified_device != null)                                                            // did we find it?
                {
                    if (OnSpecifiedDeviceArrived != null)
                    {
                        this.OnSpecifiedDeviceArrived(this, new EventArgs());
                        specified_device.DataRecieved += new DataRecievedEventHandler(OnDataRecieved);
                        specified_device.DataSend     += new DataSendEventHandler(OnDataSend);
                    }
                }
                else
                {
                    if (OnSpecifiedDeviceRemoved != null && history)
                    {
                        this.OnSpecifiedDeviceRemoved(this, new EventArgs());
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }