Advertisement

Serial port woes

Started by January 13, 2001 04:38 PM
9 comments, last by Eisen 24 years ago
We use the serial port to communicate with embedded devices at work on WinNT (but our stuff''s all Win95 compatible). The method is basically:
HANDLE hComPort = CreateFile ("COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);

If hComPort != INVALID_HANDLE, you''re in business. You can almost treat this exactly like a file.

Now, this is legacy code (i.e. I didn''t write it), so I''m not sure of the reasons, but we do this before each time we read or write:
ClearCommError (hComPort, &error, &comStat);

comStat will give you lots of nifty information about the com port, like if there''s data waiting.

You probably would be able to just open the com port, write your 12 bytes, and just read until you get 12 bytes back in order to make this work. You can get much more involved (setting baud rates, etc.) if you want to, but hopefully this gives you a start.

This topic is closed to new replies.

Advertisement