Exemplo n.º 1
0
        // Opens a handle to the devTH device attached the HIDUSB.SYS driver
        internal unsafe override bool Open(byte dev)
        {
            // If this object already has the driver open, close it.
            if (_hDevice != CyConst.INVALID_HANDLE)
            {
                Close();
            }

            int Devices = DeviceCount;

            if (Devices == 0)
            {
                return(false);
            }
            if (dev > (Devices - 1))
            {
                return(false);
            }

            string pathDetect;

            _path      = PInvoke.GetDevicePath(_drvGuid, dev);
            pathDetect = _path;

            if (pathDetect.Contains("&mi_00#") == true || pathDetect.Contains("hid#mshw0030&col01#") == true)
            {
                return(false);
            }

            _hDevice = PInvoke.GetDeviceHandle(_path, false, ref _Access);
            if (_hDevice == CyConst.INVALID_HANDLE)
            {
                return(false);
            }

            _devNum = dev;

            PInvoke.HidD_GetPreparsedData(_hDevice, ref PreParsedData);
            PInvoke.HidD_GetAttributes(_hDevice, ref Attributes);
            PInvoke.HidP_GetCaps(PreParsedData, ref _Capabilities);

            _Inputs   = new CyHidReport(HIDP_REPORT_TYPE.HidP_Input, _Capabilities, PreParsedData);
            _Outputs  = new CyHidReport(HIDP_REPORT_TYPE.HidP_Output, _Capabilities, PreParsedData);
            _Features = new CyHidReport(HIDP_REPORT_TYPE.HidP_Feature, _Capabilities, PreParsedData);

            PInvoke.HidD_FreePreparsedData(PreParsedData);
            PreParsedData = null;

            byte[] buffer = new byte[512];

            fixed(byte *buf = buffer)
            {
                char *sChars = (char *)buf;

                if (PInvoke.HidD_GetManufacturerString(_hDevice, buffer, 512))
                {
                    _manufacturer = new string(sChars);
                }

                if (PInvoke.HidD_GetProductString(_hDevice, buffer, 512))
                {
                    _product = new string(sChars);
                }

                if (PInvoke.HidD_GetSerialNumberString(_hDevice, buffer, 512))
                {
                    _serialNumber = new string(sChars);
                }
            }

            // Shortcut members.
            _vendorID  = Attributes.VendorID;
            _productID = Attributes.ProductID;
            _Version   = Attributes.VersionNumber;
            _Usage     = _Capabilities.Usage;
            _UsagePage = _Capabilities.UsagePage;

            _driverName = "usbhid.sys";

            return(true);
        }
Exemplo n.º 2
0
        private string GetDevicePath(byte dev)
        {
            string dPath;
            byte   dCnt = 0;

            //string s = "USBSTOR";
            //byte[] sClass = new byte[s.Length+1];
            //Encoding.ASCII.GetBytes(s,0,s.Length,sClass,0);

            //dPath = PInvoke.GetDevicePath(Guid.Empty,0,sClass);

            // First look for the devTH USBSTOR Disk
            byte i = 0;

            do
            {
                dPath = PInvoke.GetDevicePath(CyConst.DiskGuid, i);

                if (dPath.IndexOf("\\usbstor#") > -1)
                {
                    if (dev == dCnt)
                    {
                        _drvGuid = CyConst.DiskGuid;
                        return(dPath);
                    }
                    else
                    {
                        dCnt++;
                    }
                }

                i++;
            }while (dPath.Length > 0);



            // Next look for the devTH USBSTOR CD
            i = 0;
            do
            {
                dPath = PInvoke.GetDevicePath(CyConst.CdGuid, i);

                if (dPath.IndexOf("\\usbstor#") > -1)
                {
                    if (dev == dCnt)
                    {
                        _drvGuid = CyConst.CdGuid;
                        return(dPath);
                    }
                    else
                    {
                        dCnt++;
                    }
                }

                i++;
            }while (dPath.Length > 0);



            return("");
        }