sanjuchopracool
20th January 2012, 15:43
Qextserialport error QIODevice::read called with maxSize <0
I am using qextserialport to get some data from serial port , everything is working but i am getting
QIODevice::read called with maxSize <0
QIODevice::read called with maxSize <0[/SIZE]
again and again
my files are as
main.cpp is
#include <QtCore/QCoreApplication>
#include"receiveport.h"
//#include<qextserialport.h>
#include<QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QextSerialPort *port =new QextSerialPort ;
port->setBaudRate(BAUD19200);
port->setDataBits(DATA_8);
port->setFlowControl(FLOW_OFF);
port->setStopBits(STOP_1);
port->setParity(PAR_NONE);
if(port->open(QIODevice::ReadWrite))
qDebug()<<"Successfully opened the port";
else
qDebug()<<"Failed";
ReceivePort *myport =new ReceivePort(port);
myport->startReceiving();
myport->start();
return a.exec();
}
receiveport.h is
#ifndef RECEIVEPORT_H
#define RECEIVEPORT_H
#include "files/qextserialport.h"
#include <QMutex>
#include<QDebug>
#include<QThread>
class ReceivePort :public QThread
{
Q_OBJECT
private:
bool stopped ;
QextSerialPort *receiveport ;
QMutex receivemutex ;
public:
ReceivePort(QextSerialPort *port);
void stopReceiving();
void startReceiving();
protected:
void run();
signals:
void BytesReceived_signal(const QByteArray &data);
};
#endif // RECEIVEPORT_H
receiveport.cpp is
#include "receiveport.h"
ReceivePort::ReceivePort(QextSerialPort *port)
{
receiveport = port ;
stopped = false ; //initially the receiving is disabled
}
void ReceivePort::run()
{
int numbytes = 0 ;
char data[1024] ;
QByteArray receivedData ;
while(1)
{
if(stopped)
{
stopped =false ;
break;
}
numbytes = receiveport->bytesAvailable();
if(numbytes)
{
receivemutex.lock();
receiveport->read(data,numbytes);
receivedData =data ;
receivemutex.unlock();
emit BytesReceived_signal(receivedData);
qDebug()<<data;
}
}
}
void ReceivePort::startReceiving()
{
stopped =false ;
}
void ReceivePort::stopReceiving()
{
stopped = true ;
}
Please sort out the problem and tell me how can i avoid it.
I am using qextserialport to get some data from serial port , everything is working but i am getting
QIODevice::read called with maxSize <0
QIODevice::read called with maxSize <0[/SIZE]
again and again
my files are as
main.cpp is
#include <QtCore/QCoreApplication>
#include"receiveport.h"
//#include<qextserialport.h>
#include<QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QextSerialPort *port =new QextSerialPort ;
port->setBaudRate(BAUD19200);
port->setDataBits(DATA_8);
port->setFlowControl(FLOW_OFF);
port->setStopBits(STOP_1);
port->setParity(PAR_NONE);
if(port->open(QIODevice::ReadWrite))
qDebug()<<"Successfully opened the port";
else
qDebug()<<"Failed";
ReceivePort *myport =new ReceivePort(port);
myport->startReceiving();
myport->start();
return a.exec();
}
receiveport.h is
#ifndef RECEIVEPORT_H
#define RECEIVEPORT_H
#include "files/qextserialport.h"
#include <QMutex>
#include<QDebug>
#include<QThread>
class ReceivePort :public QThread
{
Q_OBJECT
private:
bool stopped ;
QextSerialPort *receiveport ;
QMutex receivemutex ;
public:
ReceivePort(QextSerialPort *port);
void stopReceiving();
void startReceiving();
protected:
void run();
signals:
void BytesReceived_signal(const QByteArray &data);
};
#endif // RECEIVEPORT_H
receiveport.cpp is
#include "receiveport.h"
ReceivePort::ReceivePort(QextSerialPort *port)
{
receiveport = port ;
stopped = false ; //initially the receiving is disabled
}
void ReceivePort::run()
{
int numbytes = 0 ;
char data[1024] ;
QByteArray receivedData ;
while(1)
{
if(stopped)
{
stopped =false ;
break;
}
numbytes = receiveport->bytesAvailable();
if(numbytes)
{
receivemutex.lock();
receiveport->read(data,numbytes);
receivedData =data ;
receivemutex.unlock();
emit BytesReceived_signal(receivedData);
qDebug()<<data;
}
}
}
void ReceivePort::startReceiving()
{
stopped =false ;
}
void ReceivePort::stopReceiving()
{
stopped = true ;
}
Please sort out the problem and tell me how can i avoid it.