|
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
|
|
|
|
|
Hi Alok.
I am writing/reading data according to the following thread code:
thread()<br />
{<br />
char buffer[1024];<br />
<br />
<br />
Read(fileHandle,buffer,&retbytes);<br />
Write(m_ftHandle,buffer,&retbytes);<br />
}
Regards
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
and at a time how many threads are active!
"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
The thread which plays back the file is the only thread other than the parent process which is the application itself.
Regards
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Sreekanth Muralidharan wrote:
The thread which plays back the file is the only thread other than the parent process which is the application itself.
Then in that CASE, i believe there is no confliction/ DATA loss as you mentioned in your post!.
AFAIK, No Doubt thats is only method to do PAUSE AND PLAY perfectly!.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|