Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

READING information from PORTS COM1, COM2 & COM3

Status
Not open for further replies.

qweas

Programmer
Feb 12, 2002
42
GB
Is it possible to read information from ports to C++ and if so how can this be done, please give a step by step guide.
Thank you
 
#include <conio.h>

HANDLE hCOM=CreateFile(&quot;COM1&quot;,GENERIC_READ ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if (hCOM!=INVALID_HANDLE_VALUE){
dcb.DCBlength = sizeof ( DCB ) ;
dcb.BaudRate = 9600 ;
dcb.fBinary = TRUE ;
dcb.fParity = 0;
dcb.fOutxCtsFlow = 0; // CTS output flow control
dcb.fOutxDsrFlow = 0; // DSR output flow control
dcb.fDtrControl = 1; // DTR flow control type
dcb.fDsrSensitivity = 0; // DSR sensitivity
dcb.fTXContinueOnXoff = 0; // XOFF continues Tx
dcb.fOutX = 1; // XON/XOFF output flow control
dcb.fInX = 1; // XON/XOFF input flow control
dcb.fErrorChar = 0; // enable error replacement
dcb.fNull = 0; // enable null stripping
dcb.fRtsControl = 1; // RTS flow control
dcb.fAbortOnError = 0; // abort reads/writes on error
dcb.XonLim = 2048; // transmit XON threshold
dcb.XoffLim = 512; // transmit XOFF threshold
dcb.ByteSize = 8; // number of bits/byte, 4-8
dcb.Parity = NOPARITY; // 0-4=no,odd,even,mark,space
dcb.StopBits = ONESTOPBIT; // 0,1,2 = 1, 1.5, 2
dcb.XonChar = 17; // Tx and Rx XON character
dcb.XoffChar = 19; // Tx and Rx XOFF character
dcb.ErrorChar = 0; // error replacement character
dcb.EofChar = 0; // end of input character
dcb.EvtChar = 0; // received event character

SetCommState(hCOM, &dcb));
char buffer[30];
DWORD nb;
OVERLAPPED ov;
ReadFile(hCOM,buffer,sizeof(buffer),&nb,&ov);
CloseHandle(hCOM);
}
 
See thread222-210585, thread222-211360, or thread222-212155 Anything is possible, the problem is I only have one lifetime.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top