-
December 31st, 2012, 01:56 AM
#1
Please Guide me abt Thread concept
Hi,
I'm very bad in thread concept.I searched Google and got lot of examples about thread. But in my knowledge i couldn't understand B'cos the process was very heavy.
Pls give any simple examples about thread.
I'm using VC 2003 Dialog based MFC Application. I'm using serial communication using RS232(Comport 6) & RS485(Comport 4). I created a thread like below.
Code
****
BOOL CXRayFIDlg::OnInitDialog()
{
CDialog::OnInitDialog();
PTSobj.BoardIntialize(); //RS-232 Machine Interface -> Port initialize Using PSPort.InitPort(6,9600,'E',8,1); // Com6 & Baud Rate 9600
AfxBeginThread(XRayThread,this); //Called Thread
m_comm.put_CommPort(4);
m_comm.put_Settings("9600,N,8,1");
m_comm.put_InputLen(1);
m_comm.put_InputMode(0);
m_comm.put_RTSEnable(TRUE);
m_comm.put_RThreshold(1);
m_comm.put_PortOpen(true);
SetTimer(1,1000,NULL);
return TRUE;
}
UINT CXRayFIDlg::XRayThread(LPVOID XRAYLP)
{
CXRayFIDlg *XRDLG = (CXRayFIDlg *) XRAYLP;
XRDLG->XRayThreadRun();
return true;
}
void CXRayFIDlg::XRayThreadRun()
{
PTSobj.ObjSensor(); //Write method using comport 6
PTSobj.ReadPortFromFrame(); //read method using comport 6
CDialog::KillTimer(1);
CDialog::KillTimer(2);
CDialog::KillTimer(3);
CDialog::KillTimer(4);
CDialog::SetTimer(5,10,NULL);
if(!XRAYThreadStop) //True only when i close my application
AfxBeginThread(XRayThread,this);
else
AppQuitFlag = true;
}
void CXRayFIDlg::OnTimer(UINT nIDEvent)
{
if(nIDEvent == 1)
{//Notify object sensor for every sec like FLT & MON
if(ERROR_CHECK == TRUE && KillTmr == FALSE)
{
InsideTimer = TRUE;
// Process ===> Read & Write process using com port 4
InsideTimer = FALSE;
}
}
if(nIDEvent == 2)
{
// Write process using com port 4
CDialog::KillTimer(2);
CDialog::SetTimer(1,1000,NULL);
}
if(nIDEvent == 3)
{
//Write process using com port 4
CDialog::KillTimer(3);
KillTmr = false;
CDialog::SetTimer(1,1000,NULL);
}
if(nIDEvent == 4)
{
//Write process using com port 4
CDialog::KillTimer(4);
CDialog::SetTimer(1,1000,NULL);
}
if(nIDEvent == 5) // runs Delay
{
//Some Process
CDialog::KillTimer(5);
CDialog::SetTimer(6,100,NULL);
}
if(nIDEvent == 6) //runs Ontime
{
// Some Process
CDialog::KillTimer(6);
CDialog::SetTimer(1,1000,NULL);
}
CDialog::OnTimer(nIDEvent);
}
My application hanged using this single thread with timer concept.
Am i going in the right path?
how can i remove the timer and how can i use multithread process instead of timer?
Regards,
SaraswathiSrinath
-
January 2nd, 2013, 02:42 PM
#2
Re: Please Guide me abt Thread concept
Victor Nijegorodov
-
January 4th, 2013, 12:00 AM
#3
Re: Please Guide me abt Thread concept
Hi Victor,
Thanks for your reply. But the link doesn't open. Only the page was loading from yesterday.
Regards,
SaraswathiSrinath
-
January 4th, 2013, 12:05 AM
#4
Re: Please Guide me abt Thread concept
Link works for me...
Try clearing your browser cache...
Jim
ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII
"The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.
"Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.
-
January 4th, 2013, 07:27 AM
#5
Re: Please Guide me abt Thread concept
Victor Nijegorodov
-
January 5th, 2013, 04:00 AM
#6
Re: Please Guide me abt Thread concept
sorry sir.. i dont known, what is the problem.. but the page was not opening. i will try sir
Regards,
SaraswathiSrinath
-
January 6th, 2013, 11:40 AM
#7
Re: Please Guide me abt Thread concept
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|