Esempio n. 1
0
        void CheckDevicePresent()
        {
            try
            {
                bool history = false;

                if (SpecifiedDevice != null)
                {
                    history = true;
                }

                SpecifiedDevice = SpecifiedDevice.FindSpecifiedDevice(VendorId, ProductId);

                if (SpecifiedDevice != null)
                {
                    OnSpecifiedDeviceArrived?.Invoke(this, new EventArgs());
                    if (OnDataRecieved != null)
                    {
                        SpecifiedDevice.DataRecieved += new DataRecievedEventHandler(OnDataRecieved);
                    }
                    if (OnDataSend != null)
                    {
                        SpecifiedDevice.DataSend += new DataSendEventHandler(OnDataSend);
                    }
                }
                else
                {
                    if (OnSpecifiedDeviceRemoved != null && history)
                    {
                        this.OnSpecifiedDeviceRemoved(this, new EventArgs());
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Esempio n. 2
0
        public bool Open(HIDDeviceAvalible Device)
        {
            bool success = true;

            SpecifiedDevice = SpecifiedDevice.OpenSpecifiedDevice(Device.Path);

            if (SpecifiedDevice == null)
            {
                success = false;
            }
            else
            {
                OnSpecifiedDeviceArrived?.Invoke(this, new EventArgs());
                if (OnDataRecieved != null)
                {
                    SpecifiedDevice.DataRecieved += new DataRecievedEventHandler(OnDataRecieved);
                }
                if (OnDataSend != null)
                {
                    SpecifiedDevice.DataSend += new DataSendEventHandler(OnDataSend);
                }
            }
            return(success);
        }