Problems with Rs232 under Netcf

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]");
}
 
G

Guest

Yes, in fact I used OpenNetcf to create a simple App to communicate with the
device and it does work but the task I have been given is to migrate existing
code from the desktop to CE with as few changes as possible. The fact is that
the Msdn Rs232 implementation does work except for an occassional (but still
unacceptable) failure. I am trying to understand what could be causing this
effect. One thing that may be involved is that the migrated App has roughly 9
threads running at once whereas the simple App does not.

Again, any suggestions would be appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top