Hi,
Help! i wrote a new USBLIB.dll using CyUSB.dll by C#, there's an erro during my program perform InterruptOutEndPt.XferData(ref DataBuf, ref Len) method, it's show "shut down safe handle"
below is my code:
public int iDeviceCount;
USBDeviceList usbDeviceList;
CyFX2Device[] myDevice = new CyFX2Device[4];
public CUSB()
{
usbDeviceList = new USBDeviceList(CyConst.DEVICES_CYUSB);
iDeviceCount = usbDeviceList.Count;
if (iDeviceCount != 0)
{
for (int i = 0; i < iDeviceCount; i++)
{
myDevice[i] = usbDeviceList[i] as CyFX2Device;
}
}
}
public ErrFlag GPIOCTRL(int device,byte PortSel, byte PinSel, bool HighLow)
{
byte[] DataBuf = new byte[4];
int Len = 4;
DataBuf[0] = 0x00; //command code
DataBuf[1] = PortSel;
DataBuf[2] = PinSel;
if (HighLow)
DataBuf[3] = 0x01;
else
DataBuf[3] = 0x00;
if (!myDevice[device].InterruptOutEndPt.XferData(ref DataBuf, ref Len))
return ErrFlag.ErrIntOut;
if (Len < 4)
return ErrFlag.ErrIntOut;
return ErrFlag.NoErr;
}
|