|
Hi Alok
Thanks a lot for your quick response.
#####assigns the handle to a CFile object.
Are you calling Corressponding CFile::Detach() as you must be calling CFile::Attach to attach File Handle.
#####
Is this required since a CFile::Open would return a handle to the file object. Could you please tell me what is the hidden functionality involved in CFile::Detach()/Attach().
$$$$$
Have you checked the thread Stop gracefully without any problem before second time play button hit!.
$$$$$
Is there any method for it? Any way I think we can use the concept of critical sections for making sure that all the resources alloted to the thread has been returned back before it is terminated. But this did not solve my problem still. Is there any tool to analyze the thread process so that I could see the resource leaks inside the thread?
And again I have an FTDI USB driver installed in the system where I am reading and writing to USB. We are able to read and write the flat file contents in the system to the USB. But when I try to write a single character (say 'C'), I get a block.
The application is for a Solid State Cockpit Voice Recorder where we have an MPU player attached to the system via a USB and speakers attached to MPU. The system writes data to the USB and the controller in the USB handles the data and transfers it to the four voice channels connected to speakers. When user presses the pause button the application suspends the write thread acting on the USB. When the user presses the same pause button again, he sends a character 'P' to the USB and the controller acknowledges the command by returning the same character. We have a condition check in the application to ensure that the pause command worked properly. It is this write which creates all the trouble. I think you got it.
The same application has another module which downloads data from flash memory cards connected to the SSCVR and this data rounds to about 400MB. We have no problem as said above in handling this bulk of data, but the single character acknowledgement fails quite too often.
That's the project on.
Please read the mail in detail and your suggestions are very valuable not only for me but for the entire codeproject world.
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Hi SreeKanth!
Look like lot's responsibility are on your Shoulder!
Anyway let's get back to your problem:-
Sreekanth Muralidharan wrote:
this required since a CFile::Open would return a handle to the file object. Could you please tell me what is the hidden functionality involved in CFile::Detach()/Attach().
actually you have mentioned that you are opening the file and passing the handle to CFile, so I make a guess you must be calling CFile::Attach File handle and CFile::Detach to detach file handle.
Sreekanth Muralidharan wrote:
any tool to analyze the thread process so that I could see the resource leaks inside the thread?
Process Viewer supplied with MS Visual Studio will help you track Thread opening/closing.
Sreekanth Muralidharan wrote:
We have no problem as said above in handling this bulk of data, but the single character acknowledgement fails quite too often.
As you very well know, Every HARDWARE device work on a well defined Set of commands.I had programmed hardware device only once i.e. Smartcards using Serial port communication. Try sending "C" instead of 'c' may be it's required NULL character to End Communication.
Sreekanth Muralidharan wrote:
Please read the mail in detail and your suggestions are very valuable not only for me but for the entire codeproject world.
That's a Great compliment, but i am stillin phase of learning. You can consider me beginner to Visual C++ world. you urself have more than 4 times exp then me
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hello Alok
Thanks a lot for the immediate response.
******
That's a Great compliment, but i am stillin phase of learning. You can consider me beginner to Visual C++ world. you urself have more than 4 times exp then me
******
Yaar, my experience well doesn't count and could not match your in depth knowledge of Windows programming, I really feel.
Regards,
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Sreekanth Muralidharan wrote:
my experience well doesn't count and could not match your in depth knowledge of Windows programming, I really feel
That's greatest compliment I ever got and too from a programming GURU!. Well there is no alternative for EXPERIENCE atleast in INDIA!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi Alok
And one more thing to ask for.
I have a USB driver from FTDI. And the FTDI library functions and the user manual are very useful for calling the driver functions in your application. In the so called driver library, everything is ported to a DLL which is loaded at run time by the application. The exported DLL functions are ported individually by the application viz., write, read and blah blah blah... I have a pointer to all the functions loaded in the application. Using the pointer I am calling the functions. One of the pointers return a handle to the USB driver and the handle is used for read and write operations.
When I click STOP, I do not close the driver handle. When I click play again, I use the same handle to write to the file and it annoyingly blocks and I am into trouble.
Can you find out a solution to this?
Regards
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
HI Sreekanth,
Due to CodeProject Script Error, I have to write my reply third time
Anyways Please Check that Driver Handle is Still Valid after you call STOP.
Secondly, As you have mentioned that your program only get halt when you send single character to DRIVER otherwise it's work well with BULK DATA/String. May FTDI Library fails to add END of Command Character to the character, which help Driver determine that's it's receieved complete command and it can proceed execution.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi Alok.
I have a thread which is the only one thread in the application. The thread is started at a PLAY button click event and it continues till STOP button is pressed. A PAUSE button suspends the thread at a point. The PAUSE button next time resumes the thread from where it stopped. While the thread is running, can we inform the thread of the PAUSE event so that the thread can be suspended very fast without corrupting the data the thread is handling. The particular data the thread handles is very vital for the consistent operation of the application.
Please extend your invaluable help. The other problems are almost solved now.
||| SREEKANTH MURALIDHARAN |||,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Sreekanth Muralidharan wrote:
While the thread is running, can we inform the thread of the PAUSE event
There are two ways of doing this! but first let me know which type thread's are you using, i.e. UI based Thread (thread derived from CWinThread ) or Simple Worker thread created from _BeginThread or CreateThread or AfxBeginthread Function!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi Alok
I am using a worker thread created from AfxBeginThread which returns a CWinThread pointer.
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
HI Sreekanth!
here a small piece of code that will help you in PAUSING you application
CYourDlg
{
public:
--- your function---
--- your variable---
BOOL isStop;
BOOL isPause
}
CYourDlg::OpenThread()
{
this->isStop=FALSE;
this->isPause=FALSE;
AfxBeginThread(&yourWorkerThread,reinterpret_cast<LPVOID>(this));
}
UINT yourWorkerThread(LPVOID lpParam)
{
CYourDlg *m_Dlg=( CYourDlg *)lpParam;
while(!m_Dlg->isStop)
{
while(m_Dlg->isPause)
Sleep(20);
----Do you reading writing blah blah-------
}
return 0;
}
Tthis is just sample logic, you can use waitable Timer to get more accurate result!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi Alok
Thanks a lot for the prompt response. Will try testing your code and will revert back. If success, we will open BOTTLES !!!, Okay ?
Regards
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Sreekanth Muralidharan wrote:
we will open BOTTLES !!!,
Sorry,I like to stay away from BOTTLES! but thanks for Invitation!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
No probs !!
Regards,
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Hi Alok
I think we have become real friends by now. Please help me again. How can you write a handler which is called when a thread is terminated? This is required to clean up things properly.
Regards
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Hi SreeKanth,
Sreekanth Muralidharan wrote:
I think we have become real friends by now
Offcourse
Sreekanth Muralidharan wrote:
How can you write a handler which is called when a thread is terminated?
Let me demonstrate whole logic using above sample code ok!
HANDLE g_hThreadWaitHandle;
CYourDlg {
public:
--- your function---
--- your variable---
BOOL isStop;
BOOL isPause
}
CYourDlg::OnPLAY()
{
this->isPause=FALSE;
g_hThreadWaitHandle=CreateEvent(0,FALSE,FALSE,"SREEKANTH");
AfxBeginThread(&yourWorkerThread,reinterpret_cast(this));
}
CYourDlg::OnPAUSE()
{
this->isPause!= this->isPause;
}
CYourDlg::OnSTOP()
{
this->isSTOP= TRUE;
WaitForSingleObject(g_hThreadWaitHandle,INFINITE);
}
UINT yourWorkerThread(LPVOID lpParam)
{
CYourDlg *m_Dlg=( CYourDlg *)lpParam;
while(!m_Dlg->isStop)
{
while(m_Dlg->isPause)
Sleep(20);
----Do you reading writing blah blah-------
}
SetEvent(g_hThreadWaitHandle);
return 0;
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi Alok
Thanks again for your valuable suggestion. I will try this part and give you the result.
By the way, are you working anywhere now? I think you my be having good experience in Windows programming domain, if I am not wrong.
Regards,
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Sreekanth Muralidharan wrote:
Thanks again for your valuable suggestion.
Mention Not!!
Sreekanth Muralidharan wrote:
I will try this part and give you the result
Yeah i am waiting for that!
Sreekanth Muralidharan wrote:
are you working anywhere now?
Offering me A JOB
Sreekanth Muralidharan wrote:
I think you my be having good experience in Windows programming domain
You have to decide that!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi Alok
Offering me A JOB
Will see to it !!!
You have to decide that!
I know how you felt when I said that.
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Sreekanth Muralidharan wrote:
I know how you felt when I said that.
if Hurt , I am sorry!
Sreekanth Muralidharan wrote:
Will see to it !!!
Yeah That will be Nice
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi Alok
Interested to relocate to Hyderabad?
Regards
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Sreekanth Muralidharan wrote:
Interested to relocate to Hyderabad?
Depend on Condition!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi Alok
What I feel from our earlier conversations was, if you are not employed now in software related to VC++, you will get a great opportunity soon. If you are employed now, I think, this is not enough for you as per my opinion. You SHOULD get a very good chance elsewhere. Your skills and knowledge in VC++ is an excellent proof for that. There are great opportunities for people working on system side VC++. You SHOULD get a very good break by now.
Regards,
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Sreekanth Muralidharan wrote:
You SHOULD get a very good break by now.
Pray to god for me regarding that!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi Alok.
Sorry for the trouble again.
Suppose you have a file having block of data in the following pattern:
<br />
Chan: No 1 2 3 4 1 2 3 4<br />
Data X X Y D H J K L
This is the data handled by the thread. This thread is started when you press play. The controller in the device sends data to the 4 CODECs. Data corresponding to channel no 1 is sent to CODEC1, 2 to CODEC2 and so on.
In case the file pointer reaches the data(Y) corresponding to 3rd channel. The user presses a PAUSE here. The thread is suspended here.But suppose the thread takes some time to suspend itself, maybe of the order of milliseconds. But this may be quite large a time for the file pointer to move at least one point forward and settle down. The trouble may start from here. The user presses PAUSE again. The thread is resumed. The controller sees this point as a pointer to CODEC4 but it is for CODEC5. The data for CODEC4 is played on CODEC5. Channel is interchanged !! Any solutions to this deadly problem?
Regards
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
How Much data it's bring at time
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|