LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

duplicate data in CmtGetTSQReadPtr

We are using a driver o write data into the queue, which is compiled in Labwindow, we have another thread
compiled in Visual C++ that reads the queue.
Data is duplicated and old if we do not sleep long
0 Kudos
Message 1 of 3
(2,957 Views)
Your program is written incorrectly. There are two ways to read from a thread (or write) safe queue. You can do it by a pointer to the internal queue memory, or you can do it by reading (or writing) a local copy.

You are reading by pointer and then copying to a local copy. You should just read directly with CmtReadTSQData since you want a local copy anyway and read directly into buff1.

If you want to read by pointer, you have to release the pointer with CmtReleaseTSQReadPtr after you are done with the pointer. And you do not need to call CmtFlushTSQ. The queue will automatically remove the data once it has been read off.

So your code should look something like:

int tes=bmQuePtr->getTSQHandle();
int numItems,status,status1,status2,status3,i
tems;
unsigned int *readptr;
unsigned int buff1[5000];

while(1)
{
Sleep(100);

numItems=0;
CmtGetTSQAttribute (tes, ATTR_TSQ_ITEMS_IN_QUEUE, &numItems);

if(numItems != 0)
status=CmtReadTSQData(tes,buff1, numItems, TSQ_INFINITE_TIMEOUT, 0);
}

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 3
(2,957 Views)
Have done more testing, Our queue holds up to 18 seconds of data and we are only looking at the
first couple of seconds of data.
Using read and write ptrs, the ReleaseReadPtr does not work, the write side gets a queue fill condition.That is why we were using the flush cmd.

Instead of using pointers we will try to modify both reader and writer to use your Read and Write data routines instead of the pointer routines.


Any other suggestions would be appreciated.
0 Kudos
Message 3 of 3
(2,957 Views)