sudheer168
28th August 2008, 08:39
Hi friends,
I have one problem with Qextserialport , that i was unable to read and store the data to database properly.In my program i was able to read and store the data properly for some time only and after that the data was getting corrupted(ie overwriting in port I think).
Here I am receiving huge data from other system through RS232 in which it contains a data frame of 50 channels approximately ,each channel information occupies 2bytes.The data will be 50 data frames per 1sec.when I was reading and storing these channels data into database, channel wise.I am able to insert the data for 2 or 3seconds only and then after the data corrupted. for this i used QTimer to call "receiveMsg()" for every 1millisec.
But since i am new to threads i am still figuring out how to implement it in the program, Can you pls give me any suggestions on how i should implement threads in my program.I don't know how to create the new threads and own classes. I don't know how to implement the threads in my program . Where to declare and where to start the threads.
This is the code I tried with out Threads.
void QT_receive::receiveMsg()
{
QByteArray m ;
QByteArray msg ;
QString ss;
msg.clear();
char buff[2];
if(port->bytesAvailable())
{
int i= port->read(buff, 2);
msg = QByteArray::fromRawData(buff,2);
if (i!= -1)
buff[i] = '\0';
else
buff[0] = '\0';
int d = 0;
while(d<msg.count())
{
m.prepend(msg.at(d));
d++;
}
ss = m.toHex();
QString sq("INSERT INTO Bulkdb values(%1,%2)");
sq = sq.arg(rcount)
.arg("'"+ ss +"'");
m_query.exec(sq);
rcount++;
ss.clear();
m.clear();
}
}
Please Help me to solve this problem
Regards,
Sudheer
I have one problem with Qextserialport , that i was unable to read and store the data to database properly.In my program i was able to read and store the data properly for some time only and after that the data was getting corrupted(ie overwriting in port I think).
Here I am receiving huge data from other system through RS232 in which it contains a data frame of 50 channels approximately ,each channel information occupies 2bytes.The data will be 50 data frames per 1sec.when I was reading and storing these channels data into database, channel wise.I am able to insert the data for 2 or 3seconds only and then after the data corrupted. for this i used QTimer to call "receiveMsg()" for every 1millisec.
But since i am new to threads i am still figuring out how to implement it in the program, Can you pls give me any suggestions on how i should implement threads in my program.I don't know how to create the new threads and own classes. I don't know how to implement the threads in my program . Where to declare and where to start the threads.
This is the code I tried with out Threads.
void QT_receive::receiveMsg()
{
QByteArray m ;
QByteArray msg ;
QString ss;
msg.clear();
char buff[2];
if(port->bytesAvailable())
{
int i= port->read(buff, 2);
msg = QByteArray::fromRawData(buff,2);
if (i!= -1)
buff[i] = '\0';
else
buff[0] = '\0';
int d = 0;
while(d<msg.count())
{
m.prepend(msg.at(d));
d++;
}
ss = m.toHex();
QString sq("INSERT INTO Bulkdb values(%1,%2)");
sq = sq.arg(rcount)
.arg("'"+ ss +"'");
m_query.exec(sq);
rcount++;
ss.clear();
m.clear();
}
}
Please Help me to solve this problem
Regards,
Sudheer