I have a FTDI write function that was working when the program was .net3.5, but I have been updating it so it now runs on .net 4.0 and now my FTDI write function doesn't return after entering.
private FT_HANDLE portHandle = 0;
public unsafe int Write(byte[] buffer, int offset, int count)
{
if (portHandle == 0)
{
throw new IOException("Port Closed");
}
try
{
uint bytesWritten = 0;
Status status = Status.FT_OTHER_ERROR;
byte[] data = new byte[count];
for (int i = 0; i < count; i++)
{
data[i] = buffer[i + offset];
}
fixed (byte* pBuffer = data)
{
status = FT_Write(portHandle, pBuffer, (uint)count, ref bytesWritten);// the line that never returns
}
if (status == Status.FT_OK)
{
return (int)bytesWritten;
}
throw new IOException("Failed To Write: " + status.ToString());
}
catch (DllNotFoundException ex)
{
throw new NotSupportedException("Driver not installed", ex);
}
}
portHandle
doesn't get caught in the equivalent to 0 if check.
My questions is what could be causing this and how could I fix it.