/* Summary The function sets the device, as the one having VID=04b4 and PID=1004 This will detect only the devices with the above VID,PID combinations */ public void setDevice() { try { loopDevice = usbDevices[0x04b4, 0x8613] as CyUSBDevice; StartBtn.Enabled = (loopDevice != null); if (loopDevice != null) Text = loopDevice.FriendlyName; else Text = "BVCOMVC - no device"; outEndpoint = loopDevice.EndPointOf(0x02) as CyBulkEndPoint; inEndpoint = loopDevice.EndPointOf(0x86) as CyBulkEndPoint; outEndpoint.TimeOut = 1000; inEndpoint.TimeOut = 1000; } catch { Text = "BVCOMVC - no device"; } }
void SetEndPoints() { if (_configs == 0) return; if (_interfaces == 0) return; EndPoints = USBCfgs[_cfgNum].Interfaces[_intfcIndex].EndPoints; int eptCount = EndPointCount; IsocInEndPt = null; IsocOutEndPt = null; BulkInEndPt = null; BulkOutEndPt = null; InterruptInEndPt = null; InterruptOutEndPt = null; for (int i = 1; i < eptCount; i++) { bool bIn = (EndPoints[i].Address & 0x80) > 0; byte attrib = EndPoints[i].Attributes; if (EndPoints[i] != null) EndPoints[i].XferMode = XMODE.DIRECT; if ((IsocInEndPt == null) && (attrib == 1) && bIn) IsocInEndPt = EndPoints[i] as CyIsocEndPoint; if ((BulkInEndPt == null) && (attrib == 2) && bIn) BulkInEndPt = EndPoints[i] as CyBulkEndPoint; if ((InterruptInEndPt == null) && (attrib == 3) && bIn) InterruptInEndPt = EndPoints[i] as CyInterruptEndPoint; if ((IsocOutEndPt == null) && (attrib == 1) && !bIn) IsocOutEndPt = EndPoints[i] as CyIsocEndPoint; if ((BulkOutEndPt == null) && (attrib == 2) && !bIn) BulkOutEndPt = EndPoints[i] as CyBulkEndPoint; if ((InterruptOutEndPt == null) && (attrib == 3) && !bIn) InterruptOutEndPt = EndPoints[i] as CyInterruptEndPoint; } }
/* Summary set the endpoints 2/4 as OUT and 4/8 as IN */ private void EptPair1Btn_Click(object sender, EventArgs e) { if (loopDevice != null) { if (EptPair1Btn.Checked) { outEndpoint = loopDevice.EndPointOf(0x01) as CyBulkEndPoint; inEndpoint = loopDevice.EndPointOf(0x81) as CyBulkEndPoint; } else { outEndpoint = loopDevice.EndPointOf(0x04) as CyBulkEndPoint; inEndpoint = loopDevice.EndPointOf(0x88) as CyBulkEndPoint; } if ((outEndpoint != null) && (inEndpoint != null)) { //make sure that the device configuration doesn't contain the other than bulk endpoint if ((outEndpoint.Attributes & 0x03/*0,1 bit for type of transfer*/) != 0x02/*Bulk endpoint*/) { Text = "Device Configuration mismatch"; StartBtn.Enabled = false; return; } if ((inEndpoint.Attributes & 0x03) != 0x02) { Text = "Device Configuration mismatch"; StartBtn.Enabled = false; return; } outEndpoint.TimeOut = 1000; inEndpoint.TimeOut = 1000; } else { Text = "Device Configuration mismatch"; StartBtn.Enabled = false; return; } } }
ushort _wTotalLength; // Needed in case Intfc has additional (non-endpt) descriptors #endregion Fields #region Constructors internal unsafe CyUSBInterface(IntPtr handle, byte* DescrData, CyControlEndPoint ctlEndPt) { USB_INTERFACE_DESCRIPTOR* pIntfcDescriptor = (USB_INTERFACE_DESCRIPTOR*)DescrData; _bLength = pIntfcDescriptor->bLength; _bDescriptorType = pIntfcDescriptor->bDescriptorType; _bInterfaceNumber = pIntfcDescriptor->bInterfaceNumber; _bAlternateSetting = pIntfcDescriptor->bAlternateSetting; _bNumEndpoints = pIntfcDescriptor->bNumEndpoints; _bInterfaceClass = pIntfcDescriptor->bInterfaceClass; _bInterfaceSubClass = pIntfcDescriptor->bInterfaceSubClass; _bInterfaceProtocol = pIntfcDescriptor->bInterfaceProtocol; _iInterface = pIntfcDescriptor->iInterface; _bAltSettings = 0; _wTotalLength = bLength; byte* desc = (byte*)(DescrData + pIntfcDescriptor->bLength); int i; int unexpected = 0; EndPoints = new CyUSBEndPoint[bNumEndpoints + 1]; EndPoints[0] = ctlEndPt; for (i = 1; i <= bNumEndpoints; i++) { USB_ENDPOINT_DESCRIPTOR* endPtDesc = (USB_ENDPOINT_DESCRIPTOR*)desc; _wTotalLength += endPtDesc->bLength; if (endPtDesc->bDescriptorType == CyConst.USB_ENDPOINT_DESCRIPTOR_TYPE) { switch (endPtDesc->bmAttributes) { case 0: EndPoints[i] = ctlEndPt; break; case 1: EndPoints[i] = new CyIsocEndPoint(handle, endPtDesc); break; case 2: EndPoints[i] = new CyBulkEndPoint(handle, endPtDesc); break; case 3: EndPoints[i] = new CyInterruptEndPoint(handle, endPtDesc); break; } desc += endPtDesc->bLength; } else { unexpected++; if (unexpected < 12) { // Sanity check - prevent infinite loop // This may have been a class-specific descriptor (like HID). Skip it. desc += endPtDesc->bLength; // Stay in the loop, grabbing the next descriptor i--; } } } }
/* Summary The function sets the device, as the one having VID=04b4 and PID=1004 This will detect only the devices with the above VID,PID combinations */ public void setDevice() { loopDevice = usbDevices[0x04b4, 0x0010] as CyUSBDevice; btnSendConfiguration.Enabled = (loopDevice != null); sendDeviceStateToFromHeader(); // Set the IN and OUT endpoints per the selected radio buttons. if (loopDevice != null) { outEndpoint = loopDevice.EndPointOf(0x02) as CyBulkEndPoint;//0x00 is out + EP2 = 0x02 inEndpoint = loopDevice.EndPointOf(0x81) as CyBulkEndPoint; //0x80 is in + EP1 = 0x81 outEndpoint.TimeOut = 1000; inEndpoint.TimeOut = 1000; } }