Example #1
0
    // Use this for initialization
    void Start()
    {
        Guid hidGuid;

        HidD_GetHidGuid(out hidGuid);

        IntPtr deviceInfoSet = SetupDiGetClassDevs(ref hidGuid, null, IntPtr.Zero, 22);

        try
        {
            DEVICE_INTERFACE_DATA did = new DEVICE_INTERFACE_DATA();
            did.cbSize = Marshal.SizeOf(did);

            for (int i = 0; ; i++)
            {
                if (!SetupDiEnumDeviceInterfaces(deviceInfoSet, IntPtr.Zero, ref hidGuid, (uint)i, ref did))
                {
                    if (Marshal.GetLastWin32Error() != 259)
                    {
                    }

                    break;
                }

                DEVICE_INTERFACE_DETAIL_DATA didd = new DEVICE_INTERFACE_DETAIL_DATA();
                didd.cbSize = IntPtr.Size == 4 ? 4 + Marshal.SystemDefaultCharSize : 8;

                uint requiredSize = 0;
                SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref did, ref didd, (uint)Marshal.SizeOf(didd), ref requiredSize, IntPtr.Zero);

                using (SafeFileHandle fileHandle = CreateFile(didd.DevicePath, 0, 3, IntPtr.Zero, 3, 0, IntPtr.Zero))
                {
                    HIDD_ATTRIBUTES attributes;
                    HidD_GetAttributes(fileHandle, out attributes);

                    if (attributes.VendorID == 0x0483 && attributes.ProductID == 0x5750)
                    {
                        Debug.Log("Cyclone X10 has detected on \"" + didd.DevicePath + "\".");

                        this.fileHandle = CreateFile(didd.DevicePath, 0xc0000000, 3, IntPtr.Zero, 3, 0, IntPtr.Zero);
                        break;
                    }
                }
            }
        }
        finally
        {
            if (deviceInfoSet.ToInt64() != -1)
            {
                SetupDiDestroyDeviceInfoList(deviceInfoSet);
            }
        }
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        Guid hidGuid;
        HidD_GetHidGuid(out hidGuid);

        IntPtr deviceInfoSet = SetupDiGetClassDevs(ref hidGuid, null, IntPtr.Zero, 22);
        try
        {
            DEVICE_INTERFACE_DATA did = new DEVICE_INTERFACE_DATA();
            did.cbSize = Marshal.SizeOf(did);

            for (int i = 0; ; i++)
            {
                if (!SetupDiEnumDeviceInterfaces(deviceInfoSet, IntPtr.Zero, ref hidGuid, (uint)i, ref did))
                {
                    if (Marshal.GetLastWin32Error() != 259)
                    {
                    }

                    break;
                }

                DEVICE_INTERFACE_DETAIL_DATA didd = new DEVICE_INTERFACE_DETAIL_DATA();
                didd.cbSize = IntPtr.Size == 4 ? 4 + Marshal.SystemDefaultCharSize : 8;

                uint requiredSize = 0;
                SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref did, ref didd, (uint)Marshal.SizeOf(didd), ref requiredSize, IntPtr.Zero);

                using (SafeFileHandle fileHandle = CreateFile(didd.DevicePath, 0, 3, IntPtr.Zero, 3, 0, IntPtr.Zero))
                {
                    HIDD_ATTRIBUTES attributes;
                    HidD_GetAttributes(fileHandle, out attributes);

                    if (attributes.VendorID == 0x0483 && attributes.ProductID == 0x5750)
                    {
                        Debug.Log("Cyclone X10 has detected on \"" + didd.DevicePath + "\".");

                        this.fileHandle = CreateFile(didd.DevicePath, 0xc0000000, 3, IntPtr.Zero, 3, 0, IntPtr.Zero);
                        break;
                    }
                }
            }
        }
        finally
        {
            if (deviceInfoSet.ToInt64() != -1)
            {
                SetupDiDestroyDeviceInfoList(deviceInfoSet);
            }
        }
    }
Example #3
0
 static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr hDevInfo, ref DEVICE_INTERFACE_DATA deviceInterfaceData, ref DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData, uint deviceInterfaceDetailDataSize, ref uint requiredSize, IntPtr deviceInfoData);
Example #4
0
 static extern Boolean SetupDiEnumDeviceInterfaces(IntPtr deviceInfoSet, IntPtr deviceInfoData, ref Guid interfaceClassGuid, uint memberIndex, ref DEVICE_INTERFACE_DATA deviceInterfaceData);
Example #5
0
 static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr hDevInfo, ref DEVICE_INTERFACE_DATA deviceInterfaceData, ref DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData, uint deviceInterfaceDetailDataSize, ref uint requiredSize, IntPtr deviceInfoData);
Example #6
0
 static extern Boolean SetupDiEnumDeviceInterfaces(IntPtr deviceInfoSet, IntPtr deviceInfoData, ref Guid interfaceClassGuid, uint memberIndex, ref DEVICE_INTERFACE_DATA deviceInterfaceData);