Esempio n. 1
0
        public static bool Get_This_Device(ushort p_VendorID, ushort p_PoductID, ushort p_index, ref IntPtr p_ReadHandle, ref IntPtr p_WriteHandle, ref string p_devicepath, bool p_pass_ptr_to_handle, ref Guid p_HidGuid, ref ushort p_num_devices_attached)
        {
            Utilities.InitializeParams();
            LIN.initialize_LIN_frames();
            IntPtr deviceInfoSet = IntPtr.Zero;
            IntPtr zero          = IntPtr.Zero;

            USB.HIDP_CAPS hIDP_CAPS = default(USB.HIDP_CAPS);
            ushort        num       = 0;
            IntPtr        intPtr    = IntPtr.Zero;
            int           num2      = 0;

            USB.SECURITY_ATTRIBUTES sECURITY_ATTRIBUTES = default(USB.SECURITY_ATTRIBUTES);
            IntPtr intPtr2 = new IntPtr(-1);

            sECURITY_ATTRIBUTES.lpSecurityDescriptor = 0;
            sECURITY_ATTRIBUTES.bInheritHandle       = Convert.ToInt32(true);
            sECURITY_ATTRIBUTES.nLength = Marshal.SizeOf(sECURITY_ATTRIBUTES);
            Guid empty = Guid.Empty;

            USB.SP_DEVICE_INTERFACE_DATA sP_DEVICE_INTERFACE_DATA;
            sP_DEVICE_INTERFACE_DATA.cbSize             = 0;
            sP_DEVICE_INTERFACE_DATA.Flags              = 0;
            sP_DEVICE_INTERFACE_DATA.InterfaceClassGuid = Guid.Empty;
            sP_DEVICE_INTERFACE_DATA.Reserved           = 0;
            USB.SP_DEVICE_INTERFACE_DETAIL_DATA sP_DEVICE_INTERFACE_DETAIL_DATA;
            sP_DEVICE_INTERFACE_DETAIL_DATA.cbSize     = 0;
            sP_DEVICE_INTERFACE_DETAIL_DATA.DevicePath = "";
            USB.HIDD_ATTRIBUTES hIDD_ATTRIBUTES;
            hIDD_ATTRIBUTES.ProductID     = 0;
            hIDD_ATTRIBUTES.Size          = 0;
            hIDD_ATTRIBUTES.VendorID      = 0;
            hIDD_ATTRIBUTES.VersionNumber = 0;
            bool result = false;

            sECURITY_ATTRIBUTES.lpSecurityDescriptor = 0;
            sECURITY_ATTRIBUTES.bInheritHandle       = Convert.ToInt32(true);
            sECURITY_ATTRIBUTES.nLength = Marshal.SizeOf(sECURITY_ATTRIBUTES);


            /*
             * USB.HidD_GetHidGuid(ref empty);
             * deviceInfoSet = USB.SetupDiGetClassDevs(ref empty, null, 0, 18);
             * sP_DEVICE_INTERFACE_DATA.cbSize = Marshal.SizeOf(sP_DEVICE_INTERFACE_DATA);
             * for (int i = 0; i < 30; i++)
             * {
             *      int num3 = USB.SetupDiEnumDeviceInterfaces(deviceInfoSet, 0, ref empty, i, ref sP_DEVICE_INTERFACE_DATA);
             *      if (num3 != 0)
             *      {
             *              USB.SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref sP_DEVICE_INTERFACE_DATA, IntPtr.Zero, 0, ref num2, IntPtr.Zero);
             *              sP_DEVICE_INTERFACE_DETAIL_DATA.cbSize = Marshal.SizeOf(sP_DEVICE_INTERFACE_DETAIL_DATA);
             *              IntPtr intPtr3 = Marshal.AllocHGlobal(num2);
             *              Marshal.WriteInt32(intPtr3, 4 + Marshal.SystemDefaultCharSize);
             *              USB.SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref sP_DEVICE_INTERFACE_DATA, intPtr3, num2, ref num2, IntPtr.Zero);
             *              IntPtr intPtr4 = new IntPtr(intPtr3.ToInt32() + 4);
             *              string text = Marshal.PtrToStringAuto(intPtr4);
             *              intPtr = USB.CreateFile(text, 3221225472u, 3u, ref sECURITY_ATTRIBUTES, 3, 0u, 0);
             *              if (intPtr != intPtr2)
             *              {
             *                      hIDD_ATTRIBUTES.Size = Marshal.SizeOf(hIDD_ATTRIBUTES);
             *                      num3 = USB.HidD_GetAttributes(intPtr, ref hIDD_ATTRIBUTES);
             *                      if (num3 != 0)
             *                      {
             *                              if (hIDD_ATTRIBUTES.VendorID == p_VendorID && hIDD_ATTRIBUTES.ProductID == p_PoductID)
             *                              {
             *                                      if (num == p_index)
             *                                      {
             *                                              result = true;
             *                                              if (p_pass_ptr_to_handle)
             *                                              {
             *                                                      p_WriteHandle = intPtr;
             *                                              }
             *                                              p_devicepath = text;
             *                                              p_HidGuid = empty;
             *                                              //Utilities.m_flags.HID_write_handle = intPtr;
             *                                              USB.HidD_GetPreparsedData(intPtr, ref zero);
             *                                              USB.HidP_GetCaps(zero, ref hIDP_CAPS);
             *                                              Utilities.m_flags.irbl = (ushort)hIDP_CAPS.InputReportByteLength;
             *                                              //Utilities.m_flags.HID_read_handle = USB.CreateFile(text, 3221225472u, 3u, ref sECURITY_ATTRIBUTES, 3, 0u, 0);
             *                                              if (p_pass_ptr_to_handle)
             *                                              {
             *                                                      //p_ReadHandle = Utilities.m_flags.HID_read_handle;
             *                                              }
             *                                              USB.HidD_FreePreparsedData(ref zero);
             *                                              break;
             *                                      }
             *                                      num += 1;
             *                              }
             *                              else
             *                              {
             *                                      result = false;
             *                                      USB.CloseHandle(intPtr);
             *                              }
             *                      }
             *                      else
             *                      {
             *                              result = false;
             *                              USB.CloseHandle(intPtr);
             *                      }
             *              }
             *      }
             * }
             * USB.SetupDiDestroyDeviceInfoList(deviceInfoSet);
             * p_num_devices_attached = num;
             */
            Utilities.m_flags.irbl = 65;
            if (DeviceScanner.ScanOnce(p_VendorID, p_PoductID))
            {
                Utilities.m_flags.HID_Handle      = new USBDevice(p_VendorID, p_PoductID, null, false, 65);
                Utilities.m_flags.HID_DeviceReady = true;
                result = true;
            }
            else
            {
                Utilities.m_flags.HID_DeviceReady = false;
                result = false;
            }
            return(result);
        }
Esempio n. 2
0
        internal static ushort Count_Attached_PKSA(ushort p_VendorID, ushort p_PoductID, ushort p_index, ref IntPtr p_ReadHandle, ref IntPtr p_WriteHandle, ref string p_devicepath, bool p_pass_ptr_to_handle, ref Guid p_HidGuid)
        {
            IntPtr deviceInfoSet = IntPtr.Zero;
            IntPtr arg_0B_0      = IntPtr.Zero;
            ushort num           = 0;
            IntPtr intPtr        = IntPtr.Zero;
            int    num2          = 0;

            USB.SECURITY_ATTRIBUTES sECURITY_ATTRIBUTES = default(USB.SECURITY_ATTRIBUTES);
            IntPtr intPtr2 = new IntPtr(-1);

            sECURITY_ATTRIBUTES.lpSecurityDescriptor = 0;
            sECURITY_ATTRIBUTES.bInheritHandle       = Convert.ToInt32(true);
            sECURITY_ATTRIBUTES.nLength = Marshal.SizeOf(sECURITY_ATTRIBUTES);
            Guid empty = Guid.Empty;

            USB.SP_DEVICE_INTERFACE_DATA sP_DEVICE_INTERFACE_DATA;
            sP_DEVICE_INTERFACE_DATA.cbSize             = 0;
            sP_DEVICE_INTERFACE_DATA.Flags              = 0;
            sP_DEVICE_INTERFACE_DATA.InterfaceClassGuid = Guid.Empty;
            sP_DEVICE_INTERFACE_DATA.Reserved           = 0;
            USB.SP_DEVICE_INTERFACE_DETAIL_DATA sP_DEVICE_INTERFACE_DETAIL_DATA;
            sP_DEVICE_INTERFACE_DETAIL_DATA.cbSize     = 0;
            sP_DEVICE_INTERFACE_DETAIL_DATA.DevicePath = "";
            USB.HIDD_ATTRIBUTES hIDD_ATTRIBUTES;
            hIDD_ATTRIBUTES.ProductID                = 0;
            hIDD_ATTRIBUTES.Size                     = 0;
            hIDD_ATTRIBUTES.VendorID                 = 0;
            hIDD_ATTRIBUTES.VersionNumber            = 0;
            sECURITY_ATTRIBUTES.lpSecurityDescriptor = 0;
            sECURITY_ATTRIBUTES.bInheritHandle       = Convert.ToInt32(true);
            sECURITY_ATTRIBUTES.nLength              = Marshal.SizeOf(sECURITY_ATTRIBUTES);

            /*
             * USB.HidD_GetHidGuid(ref empty);
             * deviceInfoSet = USB.SetupDiGetClassDevs(ref empty, null, 0, 18);
             * sP_DEVICE_INTERFACE_DATA.cbSize = Marshal.SizeOf(sP_DEVICE_INTERFACE_DATA);
             * for (int i = 0; i < 30; i++)
             * {
             *      int num3 = USB.SetupDiEnumDeviceInterfaces(deviceInfoSet, 0, ref empty, i, ref sP_DEVICE_INTERFACE_DATA);
             *      if (num3 != 0)
             *      {
             *              USB.SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref sP_DEVICE_INTERFACE_DATA, IntPtr.Zero, 0, ref num2, IntPtr.Zero);
             *              sP_DEVICE_INTERFACE_DETAIL_DATA.cbSize = Marshal.SizeOf(sP_DEVICE_INTERFACE_DETAIL_DATA);
             *              IntPtr intPtr3 = Marshal.AllocHGlobal(num2);
             *              Marshal.WriteInt32(intPtr3, 4 + Marshal.SystemDefaultCharSize);
             *              USB.SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref sP_DEVICE_INTERFACE_DATA, intPtr3, num2, ref num2, IntPtr.Zero);
             *              IntPtr intPtr4 = new IntPtr(intPtr3.ToInt32() + 4);
             *              string lpFileName = Marshal.PtrToStringAuto(intPtr4);
             *              intPtr = USB.CreateFile(lpFileName, 3221225472u, 3u, ref sECURITY_ATTRIBUTES, 3, 0u, 0);
             *              if (intPtr != intPtr2)
             *              {
             *                      hIDD_ATTRIBUTES.Size = Marshal.SizeOf(hIDD_ATTRIBUTES);
             *                      num3 = USB.HidD_GetAttributes(intPtr, ref hIDD_ATTRIBUTES);
             *                      if (num3 != 0)
             *                      {
             *                              if (hIDD_ATTRIBUTES.VendorID == p_VendorID && hIDD_ATTRIBUTES.ProductID == p_PoductID)
             *                              {
             *                                      num += 1;
             *                                      USB.CloseHandle(intPtr);
             *                              }
             *                              else
             *                              {
             *                                      USB.CloseHandle(intPtr);
             *                              }
             *                      }
             *                      else
             *                      {
             *                              USB.CloseHandle(intPtr);
             *                      }
             *              }
             *      }
             * }
             * USB.SetupDiDestroyDeviceInfoList(deviceInfoSet);
             */
            return(num);
        }