Наследование: LitDev.Engines.HIDDevice
Пример #1
0
        private static bool CreateDevice(string VID, string PID, string name)
        {
            try
            {
                int iVID = -1;
                int iPID = -1;
                int.TryParse(VID, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out iVID);
                int.TryParse(PID, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out iPID);
                if (DeviceExists(iVID, iPID, name))
                {
                    return(false);
                }

                if (iVID >= 0 && iPID >= 0)
                {
                    HID_Device myDevice = (HID_Device)HID_Device.FindDevice(iVID, iPID, typeof(HID_Device));
                    if (null != myDevice)
                    {
                        myDevice.VID  = iVID;
                        myDevice.PID  = iPID;
                        myDevice.name = name;
                        HID_Devices.Add(myDevice);
                        myDevice.OnDeviceRemoved += new EventHandler(_OnDeviceRemoved);
                        myDevice.OnDeviceChanged += new HIDChangedEventHandler(_OnDeviceChanged);
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Get the output record length for a HID device.
        /// </summary>
        /// <param name="name">The HID device name.</param>
        /// <returns>The number of bytes in the output record.</returns>
        public static Primitive OutputLength(Primitive name)
        {
            HID_Device device = GetDevice(name);

            if (null == device)
            {
                return(0);
            }
            return(device.OutputReportLength);
        }
Пример #3
0
 /// <summary>
 /// Send data to the HID device.
 /// This must be an array of bytes (0 to 255).
 /// The array must be indexed from 1 and have size OutputLength.
 /// </summary>
 /// <param name="name">The HID device name.</param>
 /// <param name="data">The data to send.</param>
 /// <returns>"True" or "False" for data consistency.</returns>
 public static Primitive Output(Primitive name, Primitive data)
 {
     try
     {
         HID_Device device = GetDevice(name);
         if (null == device)
         {
             return("False");
         }
         HIDOutputReport report   = new HIDOutputReport(device);
         int[]           sendData = new int[device.OutputReportLength];
         for (int i = 0; i < sendData.Length; i++)
         {
             sendData[i] = data[i + 1];
         }
         return(report.SendData(sendData));
     }
     catch (Exception ex)
     {
         Utilities.OnError(Utilities.GetCurrentMethod(), ex);
     }
     return("False");
 }
Пример #4
0
 public HIDOutputReport(HID_Device oDev)
     : base(oDev)
 {
 }
Пример #5
0
 public HIDInputReport(HID_Device oDev)
     : base(oDev)
 {
     name = oDev.name;
 }
Пример #6
0
 public HIDInputReport(HID_Device oDev) : base(oDev)
 {
     name = oDev.name;
 }
Пример #7
0
 public HIDOutputReport(HID_Device oDev) : base(oDev)
 {
 }