public static byte[] ReceiveVendorResponse(CyUSBDevice usbDevice, MonoUsbDeviceHandle monoDeviceHandle, byte reqCode, int length, ushort value = 0, ushort index = 0) { if (usbDevice != null) { CyControlEndPoint ctrlEpt = usbDevice.ControlEndPt; ctrlEpt.TimeOut = TIMEOUT; ctrlEpt.Direction = CyConst.DIR_FROM_DEVICE; ctrlEpt.ReqType = CyConst.REQ_VENDOR; ctrlEpt.Target = CyConst.TGT_DEVICE; ctrlEpt.ReqCode = reqCode; ctrlEpt.Value = value; ctrlEpt.Index = index; int bytes = length; byte[] buffer = new byte[bytes]; ctrlEpt.XferData(ref buffer, ref bytes); if (bytes == buffer.Length) { return(buffer); } } else { short bytes = (short)length; byte[] data = new byte[bytes]; byte requestType = CyConst.DIR_FROM_DEVICE + CyConst.REQ_VENDOR + CyConst.TGT_DEVICE; int ret = MonoUsbApi.ControlTransfer(monoDeviceHandle, requestType, reqCode, (short)value, (short)index, data, bytes, TIMEOUT); if (ret == data.Length) { return(data); } } return(null); }
public static bool SendVendorRequest(CyUSBDevice usbDevice, MonoUsbDeviceHandle monoDeviceHandle, byte reqCode, byte[] data, ushort value = 0, ushort index = 0) { if (data == null) { data = new byte[0]; } if (usbDevice != null) { CyControlEndPoint ctrlEpt = usbDevice.ControlEndPt; ctrlEpt.TimeOut = TIMEOUT; ctrlEpt.Direction = CyConst.DIR_TO_DEVICE; ctrlEpt.ReqType = CyConst.REQ_VENDOR; ctrlEpt.Target = CyConst.TGT_DEVICE; ctrlEpt.ReqCode = reqCode; ctrlEpt.Value = value; ctrlEpt.Index = index; int bytes = data.Length; ctrlEpt.XferData(ref data, ref bytes); return(bytes == data.Length); } else { short bytes = (short)data.Length; byte requestType = CyConst.DIR_TO_DEVICE + CyConst.REQ_VENDOR + CyConst.TGT_DEVICE; int ret = MonoUsbApi.ControlTransfer(monoDeviceHandle, requestType, reqCode, (short)value, (short)index, data, bytes, TIMEOUT); return(ret == data.Length); } }