// 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); }
// 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) 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; }
/* Summary Any selection changes in the tree view will trigger this function "at start the first device is always selected leading into this function" */ private void DeviceTreeView_AfterSelect(object sender, TreeViewEventArgs e) { XferTextBox.Text = ""; XferDataBox.Text = ""; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(">&&"); for (int i = 1; i < this.XferTextBox.MaxLength; i++) { sb.Append(" &&"); } this.XferDataBox.Mask = sb.ToString(); TreeNode selNode = DeviceTreeView.SelectedNode; string nodeText = selNode.Text; CyUSBInterfaceContainer curIntfcContainer = selNode.Tag as CyUSBInterfaceContainer; CyUSBInterface curIntfc = selNode.Tag as CyUSBInterface; CyUSBConfig curConfig = selNode.Tag as CyUSBConfig; curEndpt = selNode.Tag as CyUSBEndPoint; curCyUsbDev = selNode.Tag as CyUSBDevice; curHidDev = null; curHidReport = null; if (curConfig != null) { curCyUsbDev = selNode.Parent.Tag as CyUSBDevice; } else if (curIntfcContainer != null) { curCyUsbDev = selNode.Parent.Parent.Tag as CyUSBDevice; } else if (curIntfc != null) { curCyUsbDev = selNode.Parent.Parent.Parent.Tag as CyUSBDevice; curCyUsbDev.AltIntfc = curIntfc.bAlternateSetting; } else if (curEndpt != null) { int minXfer = curEndpt.MaxPktSize; if (curEndpt.Attributes == 1) minXfer *= 8; NumBytesBox.Text = minXfer.ToString(); // Set the AltSetting if (curEndpt.Address != 0) // Only if we're not on the Control Endpoint { curCyUsbDev = selNode.Parent.Parent.Parent.Parent.Tag as CyUSBDevice; curIntfc = selNode.Parent.Tag as CyUSBInterface; curCyUsbDev.AltIntfc = curIntfc.bAlternateSetting; } else { curCyUsbDev = selNode.Parent.Parent.Tag as CyUSBDevice; } } else if ((selNode.Tag is CyHidButton) || (selNode.Tag is CyHidValue)) { curHidDev = selNode.Parent.Parent.Tag as CyHidDevice; curHidReport = selNode.Parent.Tag as CyHidReport; NumBytesBox.Text = curHidReport.RptByteLen.ToString(); nodeText = selNode.Parent.Text; } else if (selNode.Tag is CyHidReport) { curHidDev = selNode.Parent.Tag as CyHidDevice; curHidReport = selNode.Tag as CyHidReport; NumBytesBox.Text = curHidReport.RptByteLen.ToString(); } else if (selNode.Tag is CyHidDevice) curHidDev = selNode.Tag as CyHidDevice; ConfigDataXferBtn(nodeText); DescText.Text = selNode.Tag.ToString(); Sync_Form_Resize = 1; Form1_Resize(sender, null); }
/* Summary Initialize global variables defined */ private void Initialize() { scriptfile = ""; playscriptfile = ""; Resetreg = 0xE600; Maxaddr = 0x4000; Max_Ctlxfer_size = 0x1000; bRecording = false; Xaction = new TTransaction(); list = new ArrayList(); list1 = new ArrayList(); curEndpt = null; curCyUsbDev = null; curHidDev = null; curHidReport = null; }
/* Summary Event handler to handle changes in Check box of Device Class Selection Tabpage and at Start */ private void CyUSBDeviceBox_CheckedChanged(object sender, EventArgs e) { byte DeviceMask = 0; DeviceMask |= CyUSBDeviceBox.Checked ? CyConst.DEVICES_CYUSB : (byte)0; DeviceMask |= MSCDeviceBox.Checked ? CyConst.DEVICES_MSC : (byte)0; DeviceMask |= HIDDeviceBox.Checked ? CyConst.DEVICES_HID : (byte)0; if (usbDevices != null) { usbDevices.DeviceRemoved -= usbDevices_DeviceRemoved; usbDevices.DeviceAttached -= usbDevices_DeviceAttached; usbDevices.Dispose(); } usbDevices = new USBDeviceList(DeviceMask); usbDevices.DeviceRemoved += new EventHandler(usbDevices_DeviceRemoved); usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached); curEndpt = null; curCyUsbDev = null; curHidDev = null; curHidReport = null; RefreshDeviceTree(); }