class ReceiverThread
: public QThread{
Q_OBJECT
public:
ReceiverThread()//(QObject * parent = 0):QThread(parent)
{
rxNotifier=0;
}
~ReceiverThread() {
close(rxfd);
}
private:
double sampleTime;
int rxfd, k;
protected:
virtual void run() {
rxfd = open("/tmp/testfifo", O_RDONLY);
if (rxfd==-1) {qDebug()<<"\nError opening fifo"; }
fcntl(rxfd, F_SETFL, fcntl(rxfd, F_GETFL) | O_NONBLOCK);
startRxNotifier();
exec();
}
void startRxNotifier() {
if(rxfd >= 0) {
if(rxNotifier == 0) {
connect( rxNotifier, SIGNAL(activated(int)), SLOT(rxEvent(int)), Qt::BlockingQueuedConnection );
} else {
// Debug("QSocketNotifier re-enabled!")
rxNotifier->setEnabled(true);
}
}
}
public slots:
void rxEvent(int socket) {
int readret;
int buf[1024];
qDebug()<<"rxEvent()";
readret = read(socket/*rxfd*/, buf, 2*sizeof(double));
qDebug()<<"Received:"<<buf[0]<<", "<<buf[1]<<" read() returns "<<readret;
}
};
class ReceiverThread : public QThread
{
Q_OBJECT
public:
ReceiverThread()//(QObject * parent = 0):QThread(parent)
{
rxNotifier=0;
}
~ReceiverThread() {
close(rxfd);
}
private:
double sampleTime;
int rxfd, k;
QSocketNotifier *rxNotifier;
protected:
virtual void run() {
rxfd = open("/tmp/testfifo", O_RDONLY);
if (rxfd==-1) {qDebug()<<"\nError opening fifo"; }
fcntl(rxfd, F_SETFL, fcntl(rxfd, F_GETFL) | O_NONBLOCK);
startRxNotifier();
exec();
}
void startRxNotifier() {
if(rxfd >= 0) {
if(rxNotifier == 0) {
rxNotifier = new QSocketNotifier(rxfd, QSocketNotifier::Read);//, this);
connect( rxNotifier, SIGNAL(activated(int)), SLOT(rxEvent(int)), Qt::BlockingQueuedConnection );
} else {
// Debug("QSocketNotifier re-enabled!")
rxNotifier->setEnabled(true);
}
}
}
public slots:
void rxEvent(int socket) {
int readret;
int buf[1024];
qDebug()<<"rxEvent()";
readret = read(socket/*rxfd*/, buf, 2*sizeof(double));
qDebug()<<"Received:"<<buf[0]<<", "<<buf[1]<<" read() returns "<<readret;
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks