QSerialDevice

Qt Components

Source (link to git-repo or to original if based on someone elses unmodified work): Add the source-code for this project on opencode.net

13
7.9
Description:

So, announces release: QSerialDevice 2.0

QSerialDevice – cross-platform library for serial devices based on Qt4.

Release 2.0 will be the last for the library QSerialDevice.

Recently the project (2.0 branch) has been accepted into Qt as an addon (renamed to QtSerialPort), therefore, the current Gitorious repository is no longer used, and his development frozen. Ie do not send more here merge requests, etc., his repository works only in r/o mode.

The new repository is now available here (only available to registered developers):

git clone ssh://codereview.qt-project.org:29418/playground/qtserialport.git

More see: http://qt-project.org/wiki/QtSerialPort

In the future, after the stabilization of the code will create a public repository QtSerialPort, which is an addon for Qt (LGPL + commercial).

Version history:
v 0.4.0 (Outdated)
v 0.3.0 (Outdated)
v 0.2.0 (Outdated)
v 0.1.0 (Outdated)
Last changelog:

9 years ago

More changes.

tony1tf

9 years ago

Hi Kuzulis again

I found the reason for the "too many files" error was because of the space in the file name - you had added <space>2 to the Qserial-device application.
So now I can compile, but cannot get the test apps to run - QT is asking for an executable and run environment, and then I get the error message "Failed to start program. Path or permissions wrong?" or if I tell it to start in a terminal window it cant start xterm. Then from time to time I get another error message in a pop up window in QT "The file serialport.pro.user has changed outside Qt Creator. Do you want to reload it?"
So no success yet.
Tony

Report

C

kuzulis

9 years ago

I have everything working.

For example, a test application: qserialdevice-qserialdevice\tests\guiapp\guiapp.pro

I opened a QtCreator, compile and run without problems.

Report

tony1tf

9 years ago

Hi
I'm sorry - I cannot follow what you do. Please tell me what your setup is. If I try and compile and run I get a whole stack of errors as I have stated before. What environment are you setting up - "Shadow build" etc etc.
Tony

Report

9

peer

9 years ago

I using QSerialDevice 0.4.0 in my Qt program in Linux. It work great when I connect my device to com port in my computer. But when I using the USB adapter the sending work fine, but receiving get wrong data.

In property:
port->setCharIntervalTimeout(5000);//5 msec
When is set 5000 I get:
+0.,+

1Yp|vr


#697


1

6

xml v





60px;

I want get from rs232 encoder pulses and that look like this:
#789 (on the end value is 0x17)

#974

#857


When I change to 1000
port->setCharIntervalTimeout(1000);
the received data look better but it don't look like I want:
4*
15


#
781



#75




#1
6+



#799




#79



#798




#80
6



#80
3



#803

¾


#8
0


#7
3


#8
2G


Adapter work good in two rs232 terminal (cutecom and QSerialPortTerminal) using it I get from rs232 good data. The problem is in QSerialDevice lib.

Please help.

Report

C

kuzulis

9 years ago

Use version of v2.0.

Click Version Control Link (in the header of the this page).

Report

9

peer

9 years ago

OK I fixed :)

First at all I had to set port->setCharIntervalTimeout(900);//0.9 msec
If I set more the data sometimes was wrong.

Next the data from USB adapter is reading often without synchronization so I gave timer to wait, and buffer for data.

Now it works correctly :D

Report

C

kuzulis

9 years ago

Again, you used the wrong version.
The new version 2.0 here:
http://gitorious.org/qserialdevice/qserialdevice/trees/2.0

Report

9

peer

9 years ago

I did as you said. Clone this git://gitorious.org/qserialdevice/qserialdevice.git and change libs in my project.

Effect is the same, what I wrote above. In port com in my computer work great, but using adapter USB I get wrong data from device. On rs232 terminals when I using adapter USB work fine.

Report

9

Krozac

9 years ago

I have this error while compile in linux for arm:
arm-linux-g++ -Wl,-O1 -Wl,-rpath,/usr/local/Trolltech/QtEmbedded-4.7.3-arm/lib -o qserialdevice abstractserial.o abstractserialengine.o abstractserialnotifier.o nativeserialengine.o nativeserialengine_unix.o nativeserialnotifier_unix.o ttylocker.o -L/usr/local/Trolltech/QtEmbedded-4.7.3-arm/lib -lQtGui -L/usr/local/Trolltech/QtEmbedded-4.7.3-arm/lib -lQtNetwork -lQtCore -lpthread
/usr/local/arm/bin/../arm-none-linux-gnueabi//sys-root/usr/lib/crt1.o: In function `_start':
init.c:(.text+0x30): undefined reference to `main'
collect2: ld returned 1 exit status

I have clean all sources from win reference but when I compile it stop here, any suggestions?

Best regards

Report

C

kuzulis

9 years ago

Write to me like you're cross-compiling Qt for the ARM (or give the URL to the description of the build Qt Embedded) and maybe I'll try to repeat your experiment.

Report

C

kuzulis

9 years ago

I have no idea. Can not help you. I Embedded / ARM not working.

Report

wcai

9 years ago

I create
UART = new AbstractSerial(this);// in "TSAApp" thread

and try to delete UART in "main" thread, and the system is crashed at
AbstractSerialEngine::~AbstractSerialEngine()
{
delete d_ptr;
}//crash here, and when I set a breakpoint here, I can see this breakpoint is hit by twice which is abnormal and lead to crash.

See attachement.
Sorry, I don't know how to upload attachement, please check you email.

Report

wcai

9 years ago

Dear Denis,
I am using the QSerialDevice in my project and below is my setting:

UART = new AbstractSerial(this);
UART->setDeviceName("\\\\.\\" + DeviceName);
UART->setBaudRate(AbstractSerial::BaudRate921600);
UART->setDataBits(AbstractSerial::DataBits8);
UART->setFlowControl(AbstractSerial::FlowControlOff);
UART->setParity(AbstractSerial::ParityNone);
UART->setStopBits(AbstractSerial::StopBits1);
UART->flush();
if(UART->open(QIODevice::ReadOnly))
{
}
else
{
IsException = true;
}

And it works well with lower baudrate setting, such as BaudRate115200, but when I try BaudRate921600, there is always some data lost.
And I also found that, under below condition, the system will always pending in readData()
Condition: the external UART is always output data to PC, and I set a breakpoint after opening the UART device and wait for several senconds then continue running, then the system will pending in readData(). Please note that I am using your latest release source code in my project.
When system pending, I 'pause' the application, and found that it pending in below code:
while (readSoFar < bytesToRead) {
const char *ptr = d->readBuffer.readPointer();
int bytesToReadFromThisBlock = qMin(int(bytesToRead - readSoFar),
d->readBuffer.nextDataBlockSize());
memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock);
readSoFar += bytesToReadFromThisBlock;
d->readBuffer.free(bytesToReadFromThisBlock);
}
And I can watch that bytesToReadFromThisBlock is always 0 which lead to pending.

Please help :)

Report

ssaku

9 years ago

Hi, another my problem is to compile the qserialdevice library exactly BuildLibrary.pro. I do this like:
C:\qserial\qserialdevice-qserialdevice\src>c:\qt-everywhere-opensource-src-4.6.2\bin\qmake.exe -tp vc src.pro
C:\qserial\qserialdevice-qserialdevice>c:\qt-everywhere-opensource-src-4.6.2\bin\qmake.exe -tp vc BuildLibrary.pro
To copy to clipboard, switch view to plain text mode
Next in MVS2008 i open BuildLibrary.sln then F7 and .. errorrrrrss
what to change in QserialDevices ?? to build libraries ?
I also try comment in src.pro the enumerator include but it doesn't helps

Report

C

kuzulis

9 years ago

See reply here:
http://www.qtcentre.org/threads/43607-qSerialDevice-and-WINCE-is-it-possible-to-run-it?highlight=qserialdevice

Report

desperatePerson

9 years ago

Hello...
I'm trying to use this class to write a string on the serial port! but whenever run my app it writes nothing on the serial port! I get the code from the exemple writer, and it's like this:

AbstractSerial *port = new AbstractSerial();

port->setDeviceName("/dev/ttyS0");


if (port->open(AbstractSerial::WriteOnly | AbstractSerial::Unbuffered)) {


if (!port->setBaudRate(AbstractSerial::BaudRate115200)) {
qDebug() << "Set baud rate " << AbstractSerial::BaudRate115200 << " error.";
goto label;
};

if (!port->setDataBits(AbstractSerial::DataBits8)) {
qDebug() << "Set data bits " << AbstractSerial::DataBits8 << " error.";
goto label;
}

if (!port->setParity(AbstractSerial::ParityNone)) {
qDebug() << "Set parity " << AbstractSerial::ParityNone << " error.";
goto label;
}

if (!port->setStopBits(AbstractSerial::StopBits1)) {
qDebug() << "Set stop bits " << AbstractSerial::StopBits1 << " error.";
goto label;
}

if (!port->setFlowControl(AbstractSerial::FlowControlOff)) {
qDebug() << "Set flow " << AbstractSerial::FlowControlOff << " error.";
goto label;
}

QByteArray ba; //data to send
ba.clear();
ba.append(ui->lineEdit->text());
qint64 bw = 0; //bytes really writed

/* you can now write device*/

bw = port->write(ba);
if(bw == -1)
qDebug() << "Error";

}
else {
qDebug() << "Error opened serial device " << port->deviceName();
}

label:

port->close();
qDebug() << "Serial device " << port->deviceName() << " is closed";
delete port;
port = 0;
ui->lineEdit->clear();

could anybody help me??

Report

nilavarasan

9 years ago

Is there any working example under linux?

Nilavarasan


Report

C

kuzulis

9 years ago

Why do you ask stupid questions? You download and check it myself.
And then ask what is not clear.

Report

9

woodywoodpecker

9 years ago

I'm tyring to read form serial port and show it with label but my code isn't working properly. For example, if I send from port "gjfklsn" it read "klsn" or "fklsn" or something else but never read full stirng.
I can't figure out how can I fix this...
My code;

QByteArray x;
if (port->bytesAvailable() > 0)
{
x = port->readLine();
ui->label->setText(x);
}

Report

C

kuzulis

9 years ago

To use these methods, you should add (to override) in two methods:
- bool canReadLine() const; [public]
- qint64 readLineData(char *data, qint64 maxlen); [protected]

Take them out of the implementation of source Qt4 (QAbstractSocket) and copy in AbstractSerial.
:)

At a signal readyRead() first calls canReadLine() and if successful have you read the readLine().

PS: Perhaps, too, will have to uncomment the regime Text (which is disabled by default in the library). Look for himself where he is. Although it might not be needed.

Report

9

michaudg

9 years ago

I would like to thank you for your great job !

I use your library on Linux and Windows to communicate with an Arduino device and it works very well.

Report

9

woodywoodpecker

9 years ago

Hi, again,
I'm sorry for wasting your time but I'm new on this and have to finish it until next week so I'm in panic now.
In my project there is no lib or includes directory but in folder where my project in, there are lib and include folder but in include folder there are no header files like them just folders such as; Qt, Qt3support... Also you write
|-/yoursrc
|->your *.cpp/*.h
|->your.pro
but not write anything after that, do I have do something to these files?

Report

9

woodywoodpecker

9 years ago

..\include/abstractserial.h:35: error: ../qserialdevice_global.h: No such file or directory
I did what you said and after first run (just include .h files to my project not use them yet) no error but when I run my project after add some codes about libraries that error showed up :(

Report

C

kuzulis

9 years ago

Yes, and this header too. I forgot about him.

Report

C

kuzulis

9 years ago

But if you're a novice, the easiest way - use a direct connection through the library classes *. pri files (as in the examples /test/guiapp).

Report

9 years ago

More changes.

12345678910
13
product-maker nadir22 Nov 28 2012 9 excellent
product-maker qstring Jul 25 2012 9 excellent
product-maker agnitsarkar Mar 15 2012 9 excellent
product-maker EvilTosha Jan 21 2012 9 excellent
product-maker peer Dec 30 2011 9 excellent
product-maker michaudg Jun 29 2011 9 excellent
product-maker woodywoodpecker Jun 25 2011 9 excellent
product-maker Krozac Apr 25 2011 9 excellent
product-maker bronkopavel Mar 01 2011 9 excellent
product-maker torsen Feb 03 2011 9 excellent
product-maker ilpaso Nov 30 2010 9 excellent
product-maker Chief677 Sep 28 2010 9 excellent
product-maker lit-uriy Sep 21 2010 9 excellent
Be the first to comment
nadir22
Mar 21 2012
iframe777
Mar 17 2012
peer
Feb 01 2012
Krozac
Sep 20 2011
wcai
Sep 05 2011
michaudg
Jun 29 2011
MaX-MoD
Mar 02 2011
lit-uriy
Jan 06 2011
ilpaso
Nov 30 2010
bronkopavel
Nov 14 2010
mariuszekpl
Oct 31 2010
NickGaens
Apr 28 2010
kostya2vntu
Mar 19 2010
File (click to download) Version Description Downloads Date Filesize DL OCS-Install MD5SUM
*Needs pling-store or ocs-url to install things
Pling
0 Affiliates
Details
license
version
2.0
updated Mar 15 2012
added Sep 15 2009
downloads 24h
0
mediaviews 24h 0
pageviews 24h 5
System Tags