Results 1 to 8 of 8
Hi all,
i have an application in which in am calling rtlinux program(back end) from GUI based application(QT-front end ).
I am capturing some data in my rtlinux code in ...
- 12-07-2007 #1Just Joined!
- Join Date
- Feb 2007
- Posts
- 15
Problem in Capturing data through RTLINUX
Hi all,
i have an application in which in am calling rtlinux program(back end) from GUI based application(QT-front end ).
I am capturing some data in my rtlinux code in a thread and send it to front end through reat time FIFO. In front end i am reading the FIFO in a thread and diplay the data in the Editbox.
Now my problem is that when i am displaying the data in the front end my rtl program misses few data and i am not able to get the exact no of data count.
However if i just read the data in the front end without displaying it, i get the correct count of the data.
Is my GPOS thread is not giving enough time to my rtl thread???????????
hope i am clear with my problem.
Plz any one can help me in this
Regards
- 12-08-2007 #2Just Joined!
- Join Date
- Feb 2007
- Posts
- 15
pLz if anyone can help me in this problem.
i am really stuk and unable to proceed further with my project
- 12-11-2007 #3Just Joined!
- Join Date
- Feb 2007
- Posts
- 15
regarding rtl problem
hi,
i am looking for some solution to this problem
can any one provide me some

- 12-11-2007 #4
It's difficult for us to get a handle on what the problem is.
My suggestion for a first step:
Make a toy copy of the program. Then take this toy program and start removing things from it. Remove as much as you can and still have a program that misbehaves. If you can get it down to 50 lines or fewer, then post that whole program here and we can take a look at it.
When you do post it here, make it easy for us to read your program. To do so, after you've done a copy/paste into the editing window, highlight the whole program with your mouse and click the "#" icon just above the editing window.
Hope to hear from you again.--
Bill
Old age and treachery will overcome youth and skill.
- 12-13-2007 #5Just Joined!
- Join Date
- Feb 2007
- Posts
- 15
sample code
Hi thnx for the reply,
as per your suggestion i have prepared a sample code.This is the min code i can provide.
It consist of Front End(QT) thread and Back End(rtl) thread.
The back end is reading data and send it to front end through two fifos (fd1 & fd2).
The front end reads the fifo and if data is there it writes the data in a file & displays the data in Edit box.
However on doing this my rtl thread is not read the exact no of data.
hope i am clear with the problem.if any doubt plz reply
////////////////////////////////////Front End in QT //////////////////////////////
void DisplayEnggData :: onCaptureData()
{
ExitButton->setEnabled(FALSE);
StopButton->setEnabled(TRUE);
pthread_create(&thread1,NULL,thread_function1, (void *)NULL);
}
void *thread_function1(void *arg)
{
S_32bit iRetVal ,i ;
/* reading the captured data and writting it into file in binary mode*/
while(TRUE)
{
usleep(1000);
iRetVal = read(fd1,&strMsgRes1,sizeof(DPIP5532_MT_MSG)); // fd1&fd2 are handlers for fifo
if(iRetVal > 0) // strMsgRes1 is a structure
{
iBus1Cnt++;
fwrite(&strMsgRes1,sizeof(DPIP5532_MT_MSG),1,fp1);
szBus1Cnt = szBus1Cnt.setNum(iBus1Cnt,10);
Bus1MsgCnt->setText(szBus1Cnt); //Bus1MsgCnt is lineEdit box
}
iRetVal = read(fd2,&strMsgRes2,sizeof(DPIP5532_MT_MSG));
if(iRetVal > 0)
{
iBus2Cnt++;
fwrite(&strMsgRes2,sizeof(DPIP5532_MT_MSG),1,fp2);
szBus2Cnt = szBus1Cnt.setNum(iBus2Cnt,10);
Bus2MsgCnt->setText(szBus2Cnt);
}
}
}
void DisplayEnggData::onStop()
{
pthread_cancel(thread1);
pthread_join(thread1,0);
}
///////////////////////Back end in RTLINUX////////////////////////////////////////////////////////
void *bus1(void *arg1) //back end thread
{
int siRetVal;
while ( run!=0 )
{
rtl_usleep(1000);
siRetVal = rtl_read(g_iFifoHandle[0],&strMsgRes1,sizeof(DPIP5532_MT_MSG));//reading the data
if(siRetVal > 0)
{
rtl_write(fd1,&strMsgRes1,sizeof(DPIP5532_MT_MSG)) ;//writting data to fifo fd1 for front end
}
siRetVal = rtl_read(g_iFifoHandle[1],&strMsgRes2,sizeof(DPIP5532_MT_MSG));
if(siRetVal > 0)
{
rtl_write(fd2,&strMsgRes2,sizeof(DPIP5532_MT_MSG)) ;//writting data to fifo fd2 for front end
}
}
}
- 12-13-2007 #6
I don't have a complete solution for you (and might never have), but I'll give it my best shot.
What I really would like is a complete, compilable 50-line program. For example, it should include the #include lines so it can compile, and it should include all statements that open pipes and everything else (so we can see what flags, if any, you used on the statements that opened those pipes and other entities), and it should include any calls to the pthread library besides the ones you show us.
But for now, don't bother to do that. I have a couple of comments.
First, if the only reason you are using pthreads is to fire up separate front end and back end threads, and the only way those threads communicate with each other is through the named pipes, I strongly recommend that you use fork() instead (after opening the pipes). Otherwise, you share the same heap space for both threads, and if one of them has a bug that unexpectedly stomps on some data in the heap, your first clue might be in the other thread, even though that other thread is behaving properly, and that clue would mislead you.
Second, if you get fewer bytes than you expect from a single read on a pipe, particularly if the buffer size is large, don't give up; just go back and read more bytes and put those bytes after the ones you've read so far. Lather, rinse, and repeat until you have all the bytes.
Does this advice help you start solving your problem?--
Bill
Old age and treachery will overcome youth and skill.
- 12-14-2007 #7Just Joined!
- Join Date
- Feb 2007
- Posts
- 15
hi
thnx very much for responding.
Actually i have to store the data in a file and that is the reason i am having front end & back end as separate because i cannot perform file operation in rtl program which have to capture the data.
also i will try with your suggestion of using fork(). but i am not that much aware with this so m not sure.
Also as you told that i can always go back and read the left data, but i cannot do this because i am getting the exact data what my back end is sending to front end but the problem as i told before is that this Captured data itself is less. when my front end is using this data to write into file & display in LineEdit box it takes(i believe) to long.
and so my rtl thread dosen't get enough time and cant get the exact data
Hope m clear?????
Regards
- 12-14-2007 #8
Somehow I don't think that it's a matter of the back end thread not getting enough "time". Somehow the data is being shortened or something. Could you consider putting debugging print statements in your program to figure out exactly how and when the data gets shortened? It's not clear to me exactly how that's happening.
--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote