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

Com port

Status
Not open for further replies.

rsch1973

Programmer
Sep 30, 2002
8
GB
Hi,

I would like to realise a string parse of NMEA formated strings to Com1 over RS232. I have not done it before. How can I realise it. Do I have to buy a tool or can I do it with BCB6?

Thank for help.

Regards,
Ronald
 
There are also tools (components) that are available. Some are free (e.g., Turbo Power's Async Pro from and some that co$t. I've used Async Pro. Once I got it installed, it worked very well. There is a thread somewhere in this forum about installing it.

James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
I posted this recently in a different bulletin board about a similar topic. It might help.

To access the LPT or any COM port from C++ Builder, you need to use MFC functions. Use the following concept and functions:

DWORD
Errors,
dwdBytesSent,
dwdBytesRead;

COMSTAT
Status;

COMMTIMEOUTS
time_outs;

DCB
dcb;

char
chrSomeByte,
ptrSomeMultiBytePointer[400];

HANDLE PortHandle = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

GetCommState(PortHandle, &dcb);
SetupComm(PortHandle, 200, 200);

dcb.xxxx = xxxx;
/* Set dcb variables such as baud rate, stop bits, etc */

SetCommState(PortHandle, &dcb);
GetCommTimeouts(PortHandle, &time_outs);

time_outs.xxxx = xxxx;
/* Set comm timeouts for receive and transmit */

SetCommTimeouts(PortHandle, &time_outs);
PurgeComm(PortHandle, PURGE_TXCLEAR | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_RXABORT);
ClearCommError(PortHandle, &Errors, &Status);
ClearCommBreak(PortHandle);

/* Run a separte thread that writes to the port when it's not being read from if you need asynchronous (easy way to do it) */
WriteFile(PortHandle, &chrSomeByte, 1, &dwdBytesSent, NULL);

/* Run a separate thread that reads from the port when it's not being written to (easy way) */
ReadFile(PortHandle, ptrSomeMultiBytePointer, 200, &dwdBytesRead, NULL);

CloseHandle(PortHandle);

This should work. Check out the Microsoft help file included with Borland for further info. Good luck.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top