Nawar
May 23rd, 2006, 10:38 PM
hi ..Im writing a multithreaded program in borland c++ builder 6 that communicate with serial port..readFile function is on a seperate thread and its called ( the thread) by void __fastcall read_thrd::Execute() (which replace the thread function..)..so how can I write a function that reads the serial port automatically when there is something??..(how to get the serial port status(or whatever) and react to it?)
there are some functions like WaitForSingleObject ,SetCommMask and WaitCommEvent, but I dont know how to use them properly(where to use them? in the reading thread or the main thread?and which flag to use?)
Execute() could be controled by Resume() - will resume its execution- and Suspend() - will pause and suspend its execution- and those two functions are the way to communicate with the thread from the main thread -in addition to Terminate() - , so I can write my code in execute() or in other function and then call it.
now my code it as simple as this: (Im using a butten to call resume)
//----------------------------------------------------------------------------------------------
//thread is suspended when created
void __fastcall read_thrd::Execute()
{
FreeOnTerminate = true;
while(!Terminated)
{
ReadFile(Form1->m_hCom, &(Form1->sBuffer), 128, &(Form1->iBytesWritten), &osReader) ;
Suspend();
}
if(Terminated)
{
void __endthread(void);
}
}
//----------------------------------------------------------------------------------------------
I need to replace it ..so I dont have to click the butten to read the comm port..can you help??please?
there are some functions like WaitForSingleObject ,SetCommMask and WaitCommEvent, but I dont know how to use them properly(where to use them? in the reading thread or the main thread?and which flag to use?)
Execute() could be controled by Resume() - will resume its execution- and Suspend() - will pause and suspend its execution- and those two functions are the way to communicate with the thread from the main thread -in addition to Terminate() - , so I can write my code in execute() or in other function and then call it.
now my code it as simple as this: (Im using a butten to call resume)
//----------------------------------------------------------------------------------------------
//thread is suspended when created
void __fastcall read_thrd::Execute()
{
FreeOnTerminate = true;
while(!Terminated)
{
ReadFile(Form1->m_hCom, &(Form1->sBuffer), 128, &(Form1->iBytesWritten), &osReader) ;
Suspend();
}
if(Terminated)
{
void __endthread(void);
}
}
//----------------------------------------------------------------------------------------------
I need to replace it ..so I dont have to click the butten to read the comm port..can you help??please?