Thanks for your reply Kuzulis. I have changed the pro file as you suggested and built the library from the svn. Same build problem.
The SerialComm class was added to my project as a place to put the serial read and write methods - a place to call the library functions from.
I just need to be able to read and write to a serial port on Win, *nix, or MAC OS.
I have included the initial code below - just copied your writer as a starting point.
OS is XP/SP3
INCLUDEPATH += C:\cpp\qt_projects\qtlogger\qserialdevice\src
LIBS += -L"C:\cpp\qt_projects\qtlogger\qserialdevice\src\release"
LIBS += -llibqserialdevice
INCLUDEPATH += C:\cpp\qt_projects\qtlogger\qserialdevice\src
LIBS += -L"C:\cpp\qt_projects\qtlogger\qserialdevice\src\release"
LIBS += -llibqserialdevice
To copy to clipboard, switch view to plain text mode
#ifndef SERIALCOMM_H
#define SERIALCOMM_H
#include <QObject>
#include <QByteArray>
#include "abstractserial.h"
#include "abstractserialengine.h"
#include "datatypes.h"
#include "nativeserialengine.h"
#include "winserialnotifier.h"
{
Q_OBJECT
public:
explicit SerialComm
(QObject *parent
= 0);
signals:
public slots:
};
#endif // SERIALCOMM_H
#ifndef SERIALCOMM_H
#define SERIALCOMM_H
#include <QObject>
#include <QByteArray>
#include "abstractserial.h"
#include "abstractserialengine.h"
#include "datatypes.h"
#include "nativeserialengine.h"
#include "winserialnotifier.h"
class SerialComm : public QObject
{
Q_OBJECT
public:
explicit SerialComm(QObject *parent = 0);
void printDataToHex(const QByteArray &data);
void writeComm(QByteArray);
signals:
public slots:
};
#endif // SERIALCOMM_H
To copy to clipboard, switch view to plain text mode
#include "serialcomm.h"
#include <iostream>
#include <QString>
#include <QDebug>
#include <QByteArray>
#include "abstractserial.h"
#include "abstractserialengine.h"
#include "datatypes.h"
#include "nativeserialengine.h"
#include "winserialnotifier.h"
SerialComm
::SerialComm(QObject *parent
) :{
}
void SerialComm
::printDataToHex(const QByteArray &data
) {
baTmp.clear();
#if QT_VERSION >= 0x040300
baTmp = (data.toHex()).toUpper();
#else
quint8 n=0;
for (int i=0;i<data.size();i++) {
n=data.at(i);
if ((n >
= 0) && (n <
= 15)) baTmp.
append(QByteArray::number(0,
16).
toUpper());
}
#endif
for (int i=0;i<baTmp.size();i+=2) {
qDebug() << "[" << baTmp.at(i) << baTmp.at(i+1) << "]";
}
}
AbstractSerial *MyDevice = new AbstractSerial();
//cout << "Please enter serial device name, specific by OS : ";
//char dn[50];
//cin >> dn;
MyDevice->setDeviceName(dn);
/*!
\warning
\~english To annex "correctly" to work - need to open the device with the flag Unbuffered!
\~russian çтþñы ÿрøûþöõýøõ "úþррõúтýþ" рðñþтðûþ - ýõþñхþôøüþ þтúрыòðть уÑÂтрþùÑÂтòþ Ѡфûðóþü Unbuffered!
*/
qDebug() << "Serial device " << MyDevice->deviceName() << " open in " << MyDevice->openMode();
/*
MyDevice->setDataBits(AbstractSerial::DataBits6);
MyDevice->setParity(AbstractSerial::ParityMark);
*/
qDebug() << "= Defaults parameters =";
qDebug() << "Device name : " << MyDevice->deviceName();
qDebug() << "Baud rate : " << MyDevice->baudRate();
qDebug() << "Data bits : " << MyDevice->dataBits();
qDebug() << "Parity : " << MyDevice->parity();
qDebug() << "Stop bits : " << MyDevice->stopBits();
qDebug() << "Flow : " << MyDevice->flowControl();
qDebug() << "Char timeout, msec : " << MyDevice->charIntervalTimeout();
qint64 bw=0;
while (1) {
qDebug() << "Please enter count bytes for wtitten : ";
bw=0;
//cin >> bw;
qDebug
() <<
"Starting writting " << bw <<
" bytes in time : " <<
QTime::currentTime();
ba.clear();
ba.resize(bw);
for (int i=0;i<bw;i++) { //filling data array
ba[i] = i;
}
bw=MyDevice->write(ba);
qDebug() << "Writed is : " << bw << " bytes";
qDebug() << "Tx : ";
printDataToHex(ba);
}
}
else {
qDebug() << "Error opened serial device " << MyDevice->deviceName();
}
MyDevice->close();
qDebug() << "Serial device " << MyDevice->deviceName() << " is closed";
delete MyDevice;
MyDevice=0;
}
#include "serialcomm.h"
#include <iostream>
#include <QString>
#include <QDebug>
#include <QByteArray>
#include "abstractserial.h"
#include "abstractserialengine.h"
#include "datatypes.h"
#include "nativeserialengine.h"
#include "winserialnotifier.h"
SerialComm::SerialComm(QObject *parent) :
QObject(parent)
{
}
void SerialComm::printDataToHex(const QByteArray &data)
{
QByteArray baTmp;
baTmp.clear();
#if QT_VERSION >= 0x040300
baTmp = (data.toHex()).toUpper();
#else
quint8 n=0;
for (int i=0;i<data.size();i++) {
n=data.at(i);
if ((n >= 0) && (n <= 15)) baTmp.append(QByteArray::number(0,16).toUpper());
baTmp.append(QByteArray::number(n,16).toUpper());
}
#endif
for (int i=0;i<baTmp.size();i+=2) {
qDebug() << "[" << baTmp.at(i) << baTmp.at(i+1) << "]";
}
}
void SerialComm::writeComm(QByteArray ba) {
AbstractSerial *MyDevice = new AbstractSerial();
//cout << "Please enter serial device name, specific by OS : ";
//char dn[50];
//cin >> dn;
QString dn = "COM3";
MyDevice->setDeviceName(dn);
/*!
\warning
\~english To annex "correctly" to work - need to open the device with the flag Unbuffered!
\~russian çтþñы ÿрøûþöõýøõ "úþррõúтýþ" рðñþтðûþ - ýõþñхþôøüþ þтúрыòðть уÑÂтрþùÑÂтòþ Ѡфûðóþü Unbuffered!
*/
if (MyDevice->open(QIODevice::WriteOnly | QIODevice::Unbuffered)) {
qDebug() << "Serial device " << MyDevice->deviceName() << " open in " << MyDevice->openMode();
/*
MyDevice->setDataBits(AbstractSerial::DataBits6);
MyDevice->setParity(AbstractSerial::ParityMark);
*/
qDebug() << "= Defaults parameters =";
qDebug() << "Device name : " << MyDevice->deviceName();
qDebug() << "Baud rate : " << MyDevice->baudRate();
qDebug() << "Data bits : " << MyDevice->dataBits();
qDebug() << "Parity : " << MyDevice->parity();
qDebug() << "Stop bits : " << MyDevice->stopBits();
qDebug() << "Flow : " << MyDevice->flowControl();
qDebug() << "Char timeout, msec : " << MyDevice->charIntervalTimeout();
QByteArray ba;
qint64 bw=0;
while (1) {
qDebug() << "Please enter count bytes for wtitten : ";
bw=0;
//cin >> bw;
qDebug() << "Starting writting " << bw << " bytes in time : " << QTime::currentTime();
ba.clear();
ba.resize(bw);
for (int i=0;i<bw;i++) { //filling data array
ba[i] = i;
}
bw=MyDevice->write(ba);
qDebug() << "Writed is : " << bw << " bytes";
qDebug() << "Tx : ";
printDataToHex(ba);
}
}
else {
qDebug() << "Error opened serial device " << MyDevice->deviceName();
}
MyDevice->close();
qDebug() << "Serial device " << MyDevice->deviceName() << " is closed";
delete MyDevice;
MyDevice=0;
}
To copy to clipboard, switch view to plain text mode
The library headers are visible from my gui application now, but it still won't build.
Just returns: :-1: error: collect2: ld returned 1 exit status
No clue as to why it won't build. Any ideas?
Bookmarks