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

How I can control incoming data from RS232 using C++ Builder

Status
Not open for further replies.

hazlie

Technical User
Oct 1, 2006
2
GB
Dear All,

I really need help/advice on my problem.
The objective of my project is to display a real time measurement of voltage waveform on to the PC. In this project I used ComPort component to receive data using Rs232 communication since Builder does not support Rs232 communication anymore. While, for displaying the waveform, I used TChart Component. A microntroller from microchip (PIC) is used as the data acquisition device to change the analog data to digital form and to transmit the data to the PC.


I only managed to receive and display the data once. When I need to display the next data I need to execute the program again. Thus, the process is not continues and some time not all the data receive correctly by the PC. My question is how to receive the data continuously and also displaying the data in the form of graph continuously?

I’m looking forward to get feedback from anybody. Thank you so much.








 
It sounds like you need to create seperate threads, one for the COM port and one for the TChart.

I have a program that receives data from a PLC and stores it into a database (and allows the user to manipulate it among other things). I used TurboPower's Async Pro since it is threaded. Works like a charm.



James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Dear Mr James,

Thank you for you reply, but I not really understand the meaning of 'separate threads', which you suggested. Are you means that I need to separate the program, one for receiving and store the data and another one for displaying purposes? Hope you can explain a bit details. Sorry for my further question since I new in this type of work.

 
In Windows, programs can be "threaded." That means one part of the program runs at the same time as another part of the program. This makes the program act like two programs. See faq101-1286 for an example.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Hi

I wrote an application to read / write data from a handheld terminal that communicated via RS232 port. My code is now very specialized within the app but essentially my starting block was this :

void __fastcall TForm1::Button1Click(TObject *Sender)
{
HANDLE hCom = CreateFile("COM1",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL );

if(hCom)
{

DCB dcb;
ZeroMemory(&dcb, sizeof(dcb));
dcb.DCBlength = sizeof(dcb);

dcb.BaudRate = 57600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY; // NOPARITY and friends are
dcb.StopBits = ONESTOPBIT; // #defined in windows.h

// Set the port properties and write the string out the port.
if(SetCommState(hCom,&dcb))
{
DWORD ByteCount;
const char *msg = "Hello world!";
WriteFile(hCom,msg, strlen(msg),&ByteCount,NULL);
}
CloseHandle(hCom);
}
}


Again you need to use threads to do the actual reading and writing to the port.




Hope this helps!

Regards

BuilderSpec
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top