Skip to main content

[archive] Serial communications using Windows API

  • October 25, 2006
  • 1 reply
  • 0 views

[Migrated content. Thread originally posted on 23 October 2006]

I am in the process of moving my serial communications from a DLL to an AcuCOBOL program. Since others have been interested in this in the past I will share my test program.

This program opens a com port, writes a string to the com port, reads a string from the com port with a timeout, and closes the com port. I chose to read characters from the com port one at a time. The reads timeout after so many seconds as stated in the program. In my case, if I do not receive an answer from the weigh scale in a few seconds, I will retry the request.

One down side to moving this to COBOL is the GetLastError does not work as noted elsewhere in the forum (at least as of version 6.2). I have put in some generic error messages to compensate.

If you use this program using the thin client, then you will be accessing com ports on the server.

1 reply

[Migrated content. Thread originally posted on 23 October 2006]

I am in the process of moving my serial communications from a DLL to an AcuCOBOL program. Since others have been interested in this in the past I will share my test program.

This program opens a com port, writes a string to the com port, reads a string from the com port with a timeout, and closes the com port. I chose to read characters from the com port one at a time. The reads timeout after so many seconds as stated in the program. In my case, if I do not receive an answer from the weigh scale in a few seconds, I will retry the request.

One down side to moving this to COBOL is the GetLastError does not work as noted elsewhere in the forum (at least as of version 6.2). I have put in some generic error messages to compensate.

If you use this program using the thin client, then you will be accessing com ports on the server.
I am in the process of moving my serial communications from a DLL to an AcuCOBOL program.


My compliments. An impressive piece of work. Thank you for sharing this with the forum.

For your information I can tell that GetLastError was corrected as of version 7.1.