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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does enyone know how to uise serial communi. with borland c++

Status
Not open for further replies.

banash

Programmer
Joined
Oct 27, 2005
Messages
1
Location
BA
I wiii be very grateful if some one help me with serial communication using borlad c++ bilder. Exaple would be very helpful

 
I have written my own component for serial communications using the CreateFile function fom the MS Windows SDK.

Below is the open COM port code

// Open COM Port
bool __fastcall COMThread::OpenCOMPort(COMData *ComPort)
{
//Open the COM port
//Set End_Of_Data_Event Character
cEndOfDataEventChar = ComPort->cEndOfDataEventChar;
//Set Hide Control Character
bHideControlCharacters = cComPortData.bHideControlCharacters;
//Set Translate Control Character
bTranslateControlCharacters = cComPortData.bTranslateControlCharacters;
//If this is not a valid file handle
if((hCommDevice = CreateFile(ComPort->COMPortName.c_str(),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL)) == INVALID_HANDLE_VALUE) {

//Report the error and return
dwLastError = GetLastError();
return false;
}
else {
//Setup the event handler for the component
if(!SetCommCommunications(ComPort)) {
return false;
}
else {
return true;
}
}
}

COMData is a Structure containing info about the COM port as below:

typedef struct COMDATA {
bool bCTS;
bool bDSR;
bool bHideControlCharacters;
bool bTranslateControlCharacters;
bool bXOnXOff;
char cEndOfDataEventChar;
DWORD dwBaudRate;
DWORD dwDataBits;
DWORD dwParity;
DWORD dwStopBits;
String COMPortName;
} COMData;

I had a lot of help from Timothy S. Monk's book "Windows Programmer's Guide to Serial Communications" SAMS Publishing, 1992 but the time spent working on it was worth it.

Hope this starting point helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top