Qt-interest Archive, April 2008
QDataStream intermittent read errors
Message 1 in thread
I am getting intermittent, though sort of regular, read errors using
QDataStream, not sure what is going on. The app writes binary files of
data obtained from real-time data acquisition. The write section of
interest is here, where os is a QDataStream &
sz=TDADataRec::dataSz();
os << sz;
os.writeRawData((char *)&m_bValidPt,sz);
The record being written by the writeRawData is
bool m_bValid;
float m_fRealVal;
float m_fTimeSec;
unsigned m_uADVal;
As far as I can tell, using a Hex reader, this operation is fine. The
error occurs during the read, "is" here is also a QDataStream &
quint32 fsz;
sz=TDADataRec::dataSz();
memset(&m_bValidPt,0,sz);
is >> fsz;
if (fsz<=sz)
{
is.readRawData((char *)&m_bValidPt,sz);
if (GetADVal()>70000)
SetADVal(32767);
}
else
throw BIPSCalException("...");
Every 3.4 sec (that would be 3.4 * 8 * 100 blocks of data, which are 22
bytes wide), the "if (GetADVal()>70000)" loop is entered with a huge
value for m_uADVal (range of these is 0:65535, a 16-bit A/D board). What
is odd, is that these are isolated errors, subsequent blocks of data
come out OK, and all the other data members of this block (m_bValid,
m_fReal, m_fTimeSec) are all OK. It is the isolated m_uADval.
Any clues to an intermittent read error?
--
[ signature omitted ]
Message 2 in thread
Just to finish the thread, an upgrade from 4.2.3 to 4.3.4 fixed this.
Along the way i tried all sorts of things, including a call to peek:
char vbuff[64];
memset(vbuff,0,sizeof(vbuff));
is.device()->peek(vbuff,sz);
float tmp1=*(float*)&vbuff[4];
float tmp2=*(float*)&vbuff[8];
unsigned tad=*(unsigned*)&vbuff[12];
Using peek as written above worked fine to demonstrate the flaky value
was in fact coming in from the read operation, the value "tad" had the
same out-of-range value as m_uADVal. BUT when i changed the peek to look
ahead a bit further, everything went out of kilter, the subsequent read
operations failed and the file read did not complete. This is what clued
me in that it might be a bug in Qt: why would peek() throw things off
unless it was a bug there?
After upgrade to latest Qt, ALL of this worked.
Kenneth Beck wrote:
> I am getting intermittent, though sort of regular, read errors using
> QDataStream, not sure what is going on. The app writes binary files of
> data obtained from real-time data acquisition. The write section of
> interest is here, where os is a QDataStream &
>
> sz=TDADataRec::dataSz();
>
> os << sz;
>
> os.writeRawData((char *)&m_bValidPt,sz);
>
> The record being written by the writeRawData is
> bool m_bValid;
> float m_fRealVal;
> float m_fTimeSec;
> unsigned m_uADVal;
>
> As far as I can tell, using a Hex reader, this operation is fine. The
> error occurs during the read, "is" here is also a QDataStream &
>
> quint32 fsz;
> sz=TDADataRec::dataSz();
> memset(&m_bValidPt,0,sz);
> is >> fsz;
> if (fsz<=sz)
> {
> is.readRawData((char *)&m_bValidPt,sz);
> if (GetADVal()>70000)
> SetADVal(32767);
> }
> else
> throw BIPSCalException("...");
>
> Every 3.4 sec (that would be 3.4 * 8 * 100 blocks of data, which are 22
> bytes wide), the "if (GetADVal()>70000)" loop is entered with a huge
> value for m_uADVal (range of these is 0:65535, a 16-bit A/D board). What
> is odd, is that these are isolated errors, subsequent blocks of data
> come out OK, and all the other data members of this block (m_bValid,
> m_fReal, m_fTimeSec) are all OK. It is the isolated m_uADval.
>
> Any clues to an intermittent read error?
--
[ signature omitted ]