当程序是.net3.5时,我有一个FTDI写函数,但是我一直在更新它,所以它现在在.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的值中。我的问题是是什么导致了这件事,以及我如何解决它。
发布于 2015-02-04 11:58:34
在dotnet3.5到4.0中,它们会为这类设备更改计时器和设置,首先请将计时器设置为您想要的,但是不要使用变容表、getter和setter,因为它们将无法工作,因为窗口使用它们的方式使用常量和uint,并确保您给出足够的时间进行读和写(读通常比写长)--记住时间是在毫秒内完成的--这应该是我做开关时遇到的相同问题。
所以要点设置读和写超时
不要使用getter和setter。
确保他们是康斯坦丁
https://stackoverflow.com/questions/28317284
复制相似问题