Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

serial communication problem 1

Status
Not open for further replies.

shaunfrs

Programmer
Jun 4, 2003
7
CA
I am trying to do serial communication in pocket pc. Anything I try either gets me a linker error or a runtime error. I've tried overlapped but I get a linker error when I try to use CreateEvent. I've tried non-overlapped but I get a runtime error 120 when it tries to create the handle using CreateFile. I have followed examples on msdn and ended up where I am now. Please help.

Shaun
 
Shaun,

I never use CreateFile for serial comm, but as far as I know you must use FILE_FLAG_OVERLAPPED to create comm handle

-- AirCon --
 
Not sure about differences between PocketPC and Win32, but this works fine for me on Win32:

HANDLE port;

port = CreateFile("COM2", GENERIC_READ | GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
NULL);
 
dlkfjdlkfjdlfkd

I'm not sure myself about the differences.

Ok, I gave the wrong information, let me try again.
using FILE_FLAG_OVERLAPPED is the recommended way to access comm port (I/O). But it also depends on the needs.

If the overlapped flag is not used then the (creator) calling application will get an exclusive use of this I/O. It means that other process (read/write) will have to wait for the first process to complete it's job.

For example:
If there is an incoming, when the calling processing/sending data (WriteFile), the incoming will be block. And wait for the completed signal from the calling process and vice versa

Same thing happen to the caller itself. The calling application will wait for I/O completed signal then it can continue other process. If we send large packet the application will look like "hang" also slow down other application. So we must carefully manage the packet for read/write data because COM speed is very very slow.

That is why I recommend to use overlapped

-- AirCon --
 
Well, it took a few hours but I found the problem. The name of the serial communications ports are NOT "COM1", "COM2", etc. in Win CE and Pocket PC. They are "COM1:", "COM2:", etc. The difference between Win CE and Win32 is a colon (":") after the name. Why? Who knows. But this works in Win CE and Pocket PC:

port = CreateFile("COM1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

Shaun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top