The GetCommState function retrieves the current control settings for a specified communications device.
BOOL GetCommState( HANDLE hFile, LPDCB lpDCB )
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
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; } }
file::Open, file::GetHandle, SetCommState
mscomm.h