Ejemplo n.º 1
0
        /// <summary>
        /// Записываем Feature Report в девайс.
        /// </summary>
        /// <param name="ReportID">Report ID</param>
        /// <param name="Data">Report Data to Write</param>
        /// <param name="RespondData">Respond Report Data</param>
        /// <returns>Возвращает True, если успешно отправленны и полученны данные,иначе False</returns>
        public bool WriteFeatureReport(byte ReportID, byte[] Data, ref byte[] RespondData)
        {
            bool success = false;

            byte[] Report = new byte[SpecifiedDevice.FeatureReportLength];

            if (SpecifiedDevice.FeatureReportLength - 1 > Data.Length)
            {
                Report[0] = ReportID;
                Array.Copy(Data, 0, Report, 1, Data.Length);
            }
            else
            {
                return(success);
            }

            try
            {
                RespondData = new byte[SpecifiedDevice.FeatureReportLength];
                RespondData = SpecifiedDevice.SendFeature(Report, ref success);
                success     = true;
            }
            catch (Exception ex)
            {
                success = false;
            }

            return(success);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Записываем Output Report в девайс.
        /// </summary>
        /// <param name="ReportID">Report ID</param>
        /// <param name="Data">Report Data</param>
        /// <returns>Возвращает True, если успешно отправленны данные,иначе False</returns>
        public bool WriteOutputReport(byte ReportID, byte[] Data)
        {
            bool success = false;

            byte[] Report = new byte[SpecifiedDevice.OutputReportLength];

            if (SpecifiedDevice.OutputReportLength - 1 > Data.Length)
            {
                Report[0] = ReportID;
                Array.Copy(Data, 0, Report, 1, Data.Length);
            }
            else
            {
                return(success);
            }

            try
            {
                SpecifiedDevice.SendData(Report);
                success = true;
            }
            catch (Exception ex)
            {
                success = false;
            }

            return(success);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Закрываем текущее подключение к устройству, если есть таковое.
 /// </summary>
 public void Close()
 {
     if (SpecifiedDevice != null)
     {
         SpecifiedDevice.Dispose();
         SpecifiedDevice = null;
         if (OnSpecifiedDeviceRemoved != null)
         {
             this.OnSpecifiedDeviceRemoved(this, new EventArgs());
         }
     }
 }
Ejemplo n.º 4
0
        public bool WriteOutputReport(byte[] Data)
        {
            bool success = false;

            try
            {
                SpecifiedDevice.SendData(Data);
                success = true;
            }
            catch (Exception ex)
            {
                success = false;
            }

            return(success);
        }
Ejemplo n.º 5
0
        public bool WriteFeatureReport(byte[] Data, ref byte[] RespondData)
        {
            bool success = false;

            try
            {
                RespondData = new byte[SpecifiedDevice.FeatureReportLength];
                RespondData = SpecifiedDevice.SendFeature(Data, ref success);
                success     = true;
            }
            catch (Exception ex)
            {
                success = false;
            }

            return(success);
        }
Ejemplo n.º 6
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());
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
 public static List <HIDDeviceAvalible> GetDevicesList()
 {
     return(SpecifiedDevice.GetDevicesList());
 }
Ejemplo n.º 9
0
 public static List <HIDDeviceAvalible> GetDevicesList(UInt16 VendorId)
 {
     return(SpecifiedDevice.GetDevicesListByVID(VendorId));
 }