GetCommState

 

Description

The GetCommState function retrieves the current control settings for a specified communications device.

Syntax

BOOL GetCommState( HANDLE hFile, LPDCB lpDCB )

Parameters

hFile
Handle to the communications device.
lpDCB
Pointer to a DCB structure that receives the control settings information.

Return

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

Examples

EX1

#include <Origin.h>
#include <mscomm.h>
BOOL Get_Comm_State()
{
        file ff;

        //Open comm port
        if (!ff.Open("COM1:",  file::modeReadWrite ))
        {
                ASSERT(FALSE);
                return FALSE;
        }

        UINT hCom = ff.GetHandle();

        if (hCom == file::hFileNull ) 
        {
                ASSERT(FALSE);
                return FALSE;
        }

        DCB dcb;

        if (!GetCommState((HANDLE)hCom, &dcb)) 
        {
                ASSERT(FALSE);
                return FALSE;
        }

        //dcb parameters for user
        dcb.BaudRate = CBR_9600;          // set the baud rate
        dcb.ByteSize = 8;               // data size, xmit, and rcv
        dcb.Parity = NOPARITY;            // no parity bit
        dcb.StopBits = ONESTOPBIT;        // one stop bit

        //dcb fixed parameters 
        dcb.fBinary=1; 
        dcb.fParity=0; 
        dcb.fOutxCtsFlow=0; 
        dcb.fOutxDsrFlow=0; 
        dcb.fDtrControl=0; 
        dcb.fDsrSensitivity=0; 

        dcb.fTXContinueOnXoff=0; 
        dcb.fRtsControl=0;

        if (!SetCommState((HANDLE)hCom, &dcb)) 
        {
                ASSERT(FALSE);
                return FALSE;
        }

        //...

        if( !ff.Close() ) // Close() function will happen automatically by the file class destructor.
        {
                ASSERT(FALSE);
                return FALSE;
        }
}

Remark

See Also

file::Open, file::GetHandle, SetCommState

Header to Include

mscomm.h

Reference