Hello sir this is what i am doing calling this function every 5 milli secs.
void datareceiver::savetodb()
if(port->bytesAvailable())
{
numBytes = port->bytesAvailable();
if(numBytes > sizeof(buff))
numBytes = sizeof(buff);
i = port->read(buff,numBytes);
quint16 r;
//****************** Bit Wise Shift Left and ORing of two Bytes **/
for (int i = 0; i < data.size(); i+=2)
{
r = (((quint16) data.at(i) << 5) |(data.at(i+1)));
char *ptrR = (char*) &r;
result.append(ptrR[1]);
result.append(ptrR[0]);
}
oldat.append(result.toHex());
//******************search for First frame ID and save to db from there*********************/
if(datrow ==0)
{
pos = matcher.indexIn(oldat, pos);
datrow++;
}
for(np = pos; np<oldat.size(); np++)
{
stfram.append(oldat.at(np));
pos++;
}
/********** Saving to db every 2944 i.e one Master Frame**************/
if((stfram.length()>2944) && (stfram.startsWith("03b702200000")))
{
qry.prepare("insert into Bulkdb (Time_Interval, ChannelData) values (?, ?)");
for (npos = 0; npos < stfram.length(); npos += blockLength){
qry.bindValue(0, rcount);
qry.bindValue(1, stfram.mid(npos, blockLength));
qry.exec();
rcount++;
}
}
}
stfram.clear();
npos=0;
}
void datareceiver::savetodb()
if(port->bytesAvailable())
{
numBytes = port->bytesAvailable();
if(numBytes > sizeof(buff))
numBytes = sizeof(buff);
i = port->read(buff,numBytes);
QByteArray data = (QByteArray::fromRawData(buff,numBytes));
quint16 r;
//****************** Bit Wise Shift Left and ORing of two Bytes **/
for (int i = 0; i < data.size(); i+=2)
{
r = (((quint16) data.at(i) << 5) |(data.at(i+1)));
char *ptrR = (char*) &r;
result.append(ptrR[1]);
result.append(ptrR[0]);
}
oldat.append(result.toHex());
//******************search for First frame ID and save to db from there*********************/
if(datrow ==0)
{
QByteArray pattern("03b702200000");
QByteArrayMatcher matcher(pattern);matcher(pattern);
pos = matcher.indexIn(oldat, pos);
datrow++;
}
for(np = pos; np<oldat.size(); np++)
{
stfram.append(oldat.at(np));
pos++;
}
/********** Saving to db every 2944 i.e one Master Frame**************/
if((stfram.length()>2944) && (stfram.startsWith("03b702200000")))
{
QSqlQuery qry;
qry.prepare("insert into Bulkdb (Time_Interval, ChannelData) values (?, ?)");
for (npos = 0; npos < stfram.length(); npos += blockLength){
qry.bindValue(0, rcount);
qry.bindValue(1, stfram.mid(npos, blockLength));
qry.exec();
rcount++;
}
}
}
stfram.clear();
npos=0;
}
To copy to clipboard, switch view to plain text mode
Thank you sir
Bookmarks