我有一个FTDI写入功能,当程序是.net3.5时工作,但我一直在更新它,所以它现在在.net 4.0上运行,现在我的FTDI写入功能在进入后没有返回。
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
不等同于0。
我的问题是可能导致这种情况的原因,我该如何解决它。
答案 0 :(得分:1)
在dot net3.5到4.0中,他们改变这些设备的定时器和设置首先将你的定时器设置为你想要的,但不要使用varaiables和getter和setter,因为它们不会工作,因为windows使用它们的方式使用常量和uint,并确保你有足够的时间进行读写(读取通常比写入更长)记住时间以毫秒为单位这应该可以正常工作,因为我在切换时遇到了同样的问题
所以主要的点设置读写超时
不要使用getter和setter
确保它们是常量