|
hi,
I am a beginner in C++. now I was writing the MFC( dialog based)program for the RFID interfacing. My existing program is upon clicking the start button, it will send the command to the reader and receive the response from it by using serial commnunication within for loop and serial port will disconnect by clicking stop button at the end of 'for' loop. If I click the stop button while program running half way, the program will hang. So, I wanted to implement it that upon clicking start button, my program will start interfacing with reader continuously until I clicked the stop button.So, how can i do it and can support me the sample source code for this similar program?
thanks,
Thinn
This is a part of my existing program
void CTry2Dlg::OnStart()
{
// TODO: Add your control notification handler code here
// ***
char c[40],bcch;
int bcc,ent=0;
int h=0,count=0;
com = new Tserial();
com->connect("COM2", 9600, spEVEN);
char command[15] = {0x02,0x30,0x30,0x52,0x44,0x4D,0x54,0x41,0x41,0x30,0x30,0x30,0x31,0x03};// multi
bcc=com->bcc(command); // obtain BCC
bcch=bcc;
for(int n=0;n<10;n++)
{
GetTime();
for(int i=0;i<15;i++) // send command
{
if(i==14)
{
com->sendChar(bcch);
}
else
{
com->sendChar(command[i]);
}
}
GetDlgItem(IDC_Status)->SetWindowText(command);
GetDlgItem(IDC_Status)->UpdateWindow();
// Sleep(100);
count=0;
do // read response frame
{
h=0;
c[h] = com->getChar();
while(c[h]!=0x03) // to detect ETX of reponse frame
{
h++;
c[h] = com->getChar();
}
// if(c[h]==0x03)
// {
count++;
// }
c[h] = com->getChar(); // BCC
if(c[6]==0x37 && c[7] ==0x32) // check for end of detection
{
ent=1; // endofTx
// if(count>1)
// {
count--;
// }
}
else // more to come ...
{
ent=0;
//cout<<endl<<"uid =="" ";
char="" temp[16];
for(int="" k="8;k<24;k++)
{
temp[k-8]=c[k];
}
CString" appendtext;
getdlgitem(idc_tag)-="">GetWindowText(appendText);
appendText += temp;
appendText += "\r\n";
GetDlgItem(IDC_Tag)->SetWindowText(appendText);
GetDlgItem(IDC_Tag)->UpdateWindow();
}
}while(ent==0); // reading
CString text;
text.Format("%d", count);
GetDlgItem(IDC_Counter)->SetWindowText(text);
GetDlgItem(IDC_Counter)->UpdateWindow();
Sleep(2000);
Clear();//clear the edit boxes
}
}
void CTry2Dlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CTry2Dlg::OnStop()
{
com->disconnect();
CString text=" ";
GetDlgItem(IDC_Counter)->SetWindowText(text);
GetDlgItem(IDC_Counter)->UpdateWindow();
GetDlgItem(IDC_Tag)->SetWindowText(text);
GetDlgItem(IDC_Tag)->UpdateWindow();
GetDlgItem(IDC_Status)->SetWindowText(text);
GetDlgItem(IDC_Status)->UpdateWindow();
}
--
|
|
|
|
|
yah, i got your problem.
but before answering it, i want you to advice that, you donot need to paste the whole code here, because, most of the readers donot prefer read such a big posts. your post should be as simple as possible, and reflecting your actual problem.
and to your question, since, you have defined all your port related code in a single function, i.e. button, your screen (dialog) will not get the focus until the function gets completed.
so the solution is, you have to define this code in a thread, start the thread in the start button and kill it in the stop button.
any more doubts,
you are welcome.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
I'm rather new to this forum,thx for ur advice and i will take note on that. i am new to C++ and i have tried to read through the "instuction to create threading" but i still find it hard to understand. So i greatly appreciate ur help
Thx alot for ur help. =)
--
|
|
|
|
|
Thinn Nwe Han wrote: ...upon clicking start button, my program will start interfacing with reader continuously until I clicked the stop button.
Does the RFID continuously send data to the PC? If not, why waste CPU time asking the RFID for data that does not exist? Instead, let the PC sit idle while waiting on the serial port to notify when data becomes available.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thx for your reply. For my case, the RFID reader does constantly send data back to the PC but i do not know how to write a UI thread to stop my program by clicking stop button.
--
|
|
|
|
|
Thinn Nwe Han wrote: ...i do not know how to write a UI thread to stop my program by clicking stop button.
See here for "shutdown" solutions.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
For the buttons on my dialog based application I need to have an implementation of the OnLButtonDown and OLButtonUp methods so that I know when the mouse is in different 'click' states. Looking at the available control events these aren't availble (only available for the actual dialog).
Is there a way to do this?
TIA,
Andy
|
|
|
|
|
Derive a class from CButton and attach it to the buttons in the dialogs OnInitDialog function (or use DDX_Control to do it in DoDataExchange but you'll have to add the DDX_Control manually outside of AFX_DATA_MAP or use the class wizard to create a member variable for the button using CButton and then move them out of AFX_DATA_MAP and modify the declaration from CButton to CMyButton if you use class wizard to derive CMyButton then class wizard actually recognizes it as a valid variable type I didnt know this), then you can add WM_LBUTTONUP/DOWN handlers to your CMyButton class.
-- modified at 6:42 Monday 15th October, 2007
|
|
|
|
|
Hi, thanks for your reply, I'm having a bad start to the day so could you post a link to an article (or explain) how I can overload the CButton class?
cheers,
|
|
|
|
|
A simple article search for "deriving from cbutton" returned this[^] as the 1st article found
|
|
|
|
|
thanks again for your help (used every word for the search apart from 'deriving'! )
|
|
|
|
|
Use ClassWizard (Ctrl+W). In the Base class combobox, select CButton .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
'class' type redefinition
this is the error i'm getting .. eventhougyh i havent definied it anywhere before in pgm . .. any solution plzzz
|
|
|
|
|
If you put a bit of relevant code, people will be able to help better.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
in the header file which defines your class, put the fillowing aroung your file content :
#if !defined(__A_UNIQUE_MACRO_NAME_FOR_YOUR_FILE__)
#define __A_UNIQUE_MACRO_NAME_FOR_YOUR_FILE__
#endif //__A_UNIQUE_MACRO_NAME_FOR_YOUR_FILE__
|
|
|
|
|
Don't forget to put include guards in your header files:
#ifndef MYFILE_H<br />
#define MYFILE_H<br />
<br />
<br />
#endif
Or you can also use the #pragma directive.
|
|
|
|
|
use #pragma once
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
suganforu wrote: ...eventhougyh i havent definied it anywhere before in pgm.
Obviously you have, or the compiler would not be complaining. Use the #define and #pragma once directives in your class definition file.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can anyone suggest any book for working VC++ with Flash 8
Thanks in advance
sai
|
|
|
|
|
Hi,
A client ask to me a program to work on a simple database.
It looks quite easy for me, but not everything!
He asked to me something that I haven't do before, so before accept the job I want to understand how complex is this, and, after that, of course, I'll have to study it:
1 Store the DB on a server(or simply on a pc more important than the other), every other client-pc asks to this server (local network) some info before send to it a new valid item of the DB. of course somethimes the client have to ask to the server the complete DB to draw it.
2 Prepare a Microsoft-Word document filling somewhere the page using some info from an item of the DB. Is it a possible solution use the word-macros? Any sample?
I haven't any idea on how solve this two features. Is it an hard task?
Have you got some keywords/article/sample to look at?
If needed I can explain more in deeper this features.
Thank you very much for every help
Russell
|
|
|
|
|
How to remove a directory and it's sub directory/files? Api RemoveDirectory only operates on empty directories.
|
|
|
|
|
You need to write a recursive function to walk down the folder tree and start deleting things from the bottom up.
For a given directory enumerate the contents, for each sub directory call your directory delete function again and then delete the directory when it returns
|
|
|
|
|
You could try experimenting with SHFileOperation() setting the wFunc member to FO_DELETE and NOT including FOF_NORECURSION in the fFlags member. I have used it to delete all files in a folder in one operation but havent actually tried the recursive delete that is implied by the FOF_NORECURSION flag.
|
|
|
|
|
|
Please Note: _rmdir The directory must be empty, and it must not be the current working directory or the root directory.
|
|
|
|