G
Guest
I am using the Rs232 approach outlined in the Mdsn article "Use P/Invoke to
Develop a .NET Base Class Library for Serial Device Communications" to
connect to an Rs232 device from a WinCe device. I made modifications, some
suggested on this forum. It does connect with the device but occassionaly it
stops communicating. A simplier App that uses the OpenNetCf Port works
reliably.
Since I am migrating a fairly large App from desktop to WinCe I would rather
not change their code more then necessary. The following are the code
snippets that open, write to and read from the Rs232 line.
Could you suggest what I might be doing wrong?
Note that I did remove the overlap from the desktop approach.
hPort = Win32Com.CreateFile("COM1:", 0x80000000|0x40000000, 0,
IntPtr.Zero,Win32Com.OPEN_EXISTING,0, IntPtr.Zero);
if (Win32Com.WriteFile(hPort, tosend, (uint)writeCount, out sent, ptrUWO))
{writeCount -= (int)sent;
}
else
{if (Marshal.GetLastWin32Error() != Win32Com.ERROR_IO_PENDING)
ThrowException("Send failed");
}
if (!Win32Com.ReadFile(hPort, buf, 1, out gotbytes, unmanagedOv))
{int x = Marshal.GetLastWin32Error();
throw new CommPortException("IO Error [004]");
}
Develop a .NET Base Class Library for Serial Device Communications" to
connect to an Rs232 device from a WinCe device. I made modifications, some
suggested on this forum. It does connect with the device but occassionaly it
stops communicating. A simplier App that uses the OpenNetCf Port works
reliably.
Since I am migrating a fairly large App from desktop to WinCe I would rather
not change their code more then necessary. The following are the code
snippets that open, write to and read from the Rs232 line.
Could you suggest what I might be doing wrong?
Note that I did remove the overlap from the desktop approach.
hPort = Win32Com.CreateFile("COM1:", 0x80000000|0x40000000, 0,
IntPtr.Zero,Win32Com.OPEN_EXISTING,0, IntPtr.Zero);
if (Win32Com.WriteFile(hPort, tosend, (uint)writeCount, out sent, ptrUWO))
{writeCount -= (int)sent;
}
else
{if (Marshal.GetLastWin32Error() != Win32Com.ERROR_IO_PENDING)
ThrowException("Send failed");
}
if (!Win32Com.ReadFile(hPort, buf, 1, out gotbytes, unmanagedOv))
{int x = Marshal.GetLastWin32Error();
throw new CommPortException("IO Error [004]");
}