Thread: mscomm for rs232

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    98

    mscomm for rs232

    in visual basic there is a mscomm control for com ports, is there a class in c++ that does the same thing? trying to write to a hardware device connected to a com port. im using ms visual c++

    thanks

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    You can CreateFile to open a handle to the COM port and then you can read and write to the port just as you do with files.

  3. #3
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    There are also rs232 developers kits that have classes for data communications. Do a search at google.
    Blue

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Take a look at MSDN Library and especially at the article called:

    Serial Communications in Win32
    Allen Denver
    Microsoft Windows Developer Support
    December 11, 1995

    By the way, you could use CreateFile like this:

    Code:
    HANDLE hComm;
    hComm = CreateFile( gszPort,  
                        GENERIC_READ | GENERIC_WRITE, 
                        0, 
                        0, 
                        OPEN_EXISTING,
                        FILE_FLAG_OVERLAPPED,
                        0);
    if (hComm == INVALID_HANDLE_VALUE)
       // error opening port; abort

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    98

    mscomm for rs232

    does the 2 zero's there mean comm1?

    and another thing, i have bought $200 worth of books, if i buy another one that tells me how to say hello in dos and how to make databases, i am going to scream lol any ideas on an actual real world programming book?

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    3

    here is a crude class example

    I've had some frustrating experiences with serial communication over the years. I cant say that I can handle it good either, but here you have the source code for my rs232 class, used in an experimental project. I dont assure any level of quality, you have to add error handling as you think appropriate for your application. And, I remember that I mixed some with the timeout values, you may be better of removing that part of the code.
    The Send() function uses a record length, this was a application-specific functionality that you might not need.

    Good Luck!

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    4
    As an addition to this thread, whilst in a TAPI setup, using getLineID, I return a handle to the device, through which a modem is comminucating with a modem (vice versa). This returns a handle which can be used as though called from CreateFile.
    Big problems occur when attempting to readfile, in non-overlapped method.

    Any help?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MSCOMM in VC++
    By fnoyan in forum Windows Programming
    Replies: 1
    Last Post: 10-03-2005, 11:49 AM
  2. Why the data sent is double?
    By ooicheesan in forum C Programming
    Replies: 4
    Last Post: 10-08-2004, 01:17 AM