• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

Win98:Serial Communications Functions,Classes, etc.

I am in need of a basic set of serial port functions to send/receive data from the com ports.  I have looked through many books and have only found MSComm, the Active X control, and a few other incomplete libraries.  I would be satisfied with MSComm (I believe) if I could find some C++ documentation on it (all I find is VB).  SO:  I am looking for a good serial solution.  The soln must have basic readChar, writeChar, readBlock, writeBlock functionality.  That's it.  No error checking or anything else.  Any ideas?
0
SoundsFishy
Asked:
SoundsFishy
1 Solution
 
ToronadoCommented:
Hi SoundsFishy,

Here is some code I'm use myself. It is simple and has not much error checking.

May be I should wrap it in some class ones.

HANDLE hComHandle;

hComHandle = CreateFile ("\\\\.\\COM1", GENERIC_READ | GENERIC_WRITE,
            0,
            NULL,
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL,
            NULL);

if (hComHandle != INVALID_HANDLE_VALUE)
{
 DCB dcb;
// Initialise serial communication
 if (GetCommState(hComHandle, &dcb))
 {
// Set the serial communicaton options
  dcb.BaudRate      = CBR_9600;
  dcb.Parity      = NOPARITY;
  dcb.ByteSize      = 8;
  dcb.StopBits      = ONESTOPBIT;

  if (!SetCommState(hComHandle, &dcb))
  {
// Now you can use the ReadFile and WriteFile function as if hComHandle is a normal file.
   
  }

It should work for the paralel port also.

Regards,
 Toronado.
0
 
jkrCommented:
Take a look at http://msdn.microsoft.com/library/techart/msdn_serial.htm ("Serial Communications in Win32") - this article describes in-depth how to use COM ports.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now