Click here to Skip to main content
15,908,254 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: _inp and _outp Pin
eggie521-May-04 11:01
eggie521-May-04 11:01 
GeneralRe: _inp and _outp Pin
21-May-04 12:29
suss21-May-04 12:29 
GeneralRe: _inp and _outp Pin
Prakash Nadar21-May-04 16:45
Prakash Nadar21-May-04 16:45 
GeneralRe: _inp and _outp Pin
eggie521-May-04 18:17
eggie521-May-04 18:17 
GeneralStrFormatByteSize() Pin
DanYELL21-May-04 9:29
DanYELL21-May-04 9:29 
GeneralRe: StrFormatByteSize() Pin
Michael Dunn21-May-04 12:57
sitebuilderMichael Dunn21-May-04 12:57 
GeneralRe: StrFormatByteSize() Pin
DanYELL21-May-04 15:20
DanYELL21-May-04 15:20 
QuestionCorrect Usage of WaitCommEvent? Pin
AnotherProgrammer21-May-04 8:31
AnotherProgrammer21-May-04 8:31 
Hello...

I'm currently writing a program that has to read in data from the serial port and then process it. But I thought before I tackle that part, I should write a small sample one to test to see that I can actually receive data.

I got this sample program off the MSDN website and made a couple of minor changes (original can be found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/monitoring_communications_events.asp ) to reflect the fact that it's supposed to look for any characters received.

// used square brackets to make libraries show up here - actual code contains
// greater than and less than signs
#include [windows.h]
#include [assert.h]
#include [conio.h]
#include [iostream]
void main()
{
    HANDLE hCom;
    OVERLAPPED o;
    BOOL fSuccess;
    DWORD dwEvtMask;

    hCom = CreateFile( "COM1",
        GENERIC_READ,
        0,    // exclusive access
        NULL, // default security attributes
        OPEN_EXISTING,
        FILE_FLAG_OVERLAPPED,
        NULL
        );

    if (hCom == INVALID_HANDLE_VALUE)
    {
        // Handle the error.
        return;
    }

    // Set the event mask.

    fSuccess = SetCommMask(hCom, EV_CTS | EV_DSR);

    if (!fSuccess)
    {
        // Handle the error.
        return;
    }

    // Create an event object for use by WaitCommEvent.

    o.hEvent = CreateEvent(
        NULL,   // default security attributes
        FALSE,  // auto reset event
        FALSE,  // not signaled
        NULL    // no name
		);


    // Intialize the rest of the OVERLAPPED structure to zero.
    o.Internal = 0;
    o.InternalHigh = 0;
    o.Offset = 0;
    o.OffsetHigh = 0;

    assert(o.hEvent);

    if (WaitCommEvent(hCom, &dwEvtMask, &o))
    {
        if (dwEvtMask & EV_RXCHAR)
        {
				cout << "received!";
        }

        if (dwEvtMask & EV_CTS)
        {
            // To do.
        }
    }
    getch();
}


This program, when compiled, does not output "received!", even though I know there is data being sent to the serial port (COM1). Any suggestions as to why? Is there a better way to monitor for the reception of characters through the serial port? Any help is appreciated.

Thanks in advance.
AnswerFurthermore... (another question - about ReadFile this time) Pin
AnotherProgrammer21-May-04 8:40
AnotherProgrammer21-May-04 8:40 
AnswerRe: Correct Usage of WaitCommEvent? Pin
Antti Keskinen23-May-04 0:08
Antti Keskinen23-May-04 0:08 
GeneralSubclassed ActiveX control Pin
BlackDice21-May-04 7:01
BlackDice21-May-04 7:01 
GeneralRe: Subclassed ActiveX control Pin
Antti Keskinen21-May-04 7:44
Antti Keskinen21-May-04 7:44 
GeneralRe: Subclassed ActiveX control Pin
BlackDice21-May-04 7:58
BlackDice21-May-04 7:58 
GeneralWTL links Pin
aej21-May-04 5:33
aej21-May-04 5:33 
QuestionHow to retrieve UNIT of a scroll bar Pin
fotoONE21-May-04 5:10
fotoONE21-May-04 5:10 
AnswerRe: How to retrieve UNIT of a scroll bar Pin
David Crow21-May-04 5:14
David Crow21-May-04 5:14 
AnswerRe: How to retrieve UNIT of a scroll bar Pin
vladfein21-May-04 6:58
vladfein21-May-04 6:58 
GeneralCStrings Pin
Anonymous21-May-04 5:09
Anonymous21-May-04 5:09 
GeneralRe: CStrings Pin
David Crow21-May-04 5:16
David Crow21-May-04 5:16 
GeneralRe: CStrings Pin
Michael Dunn21-May-04 5:17
sitebuilderMichael Dunn21-May-04 5:17 
Generalvalidity of HTREEITEM Pin
Paolo Vernazza21-May-04 4:49
Paolo Vernazza21-May-04 4:49 
GeneralRe: validity of HTREEITEM Pin
vladfein21-May-04 6:54
vladfein21-May-04 6:54 
GeneralRe: validity of HTREEITEM Pin
peterchen21-May-04 22:53
peterchen21-May-04 22:53 
GeneralRe: validity of HTREEITEM Pin
Paolo Vernazza21-May-04 23:37
Paolo Vernazza21-May-04 23:37 
Questionhow to connect mysql database with mfc? Pin
Chooikw21-May-04 4:14
Chooikw21-May-04 4:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.