Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, February 2007
Problem with SerialPort Connection when using Qextserial


Message 1 in thread

Dear all,

I try to use qextserial for an application that should communicate over
rs232 on windowsxp.

I already found the qextserial classes and the example from sourceforge. I
also can compile everything (msvc express) and get no error messages. I made
a very small test program that just sends a few char characters to another
computer that has hyperterminal to receive the signals. But so far nothing
arrived on the other side.

I also tested the communication by using hyperterminal also to send data and
it works just fine.

So can anybody of you give me some example code that is working for shure in
order to test the communication? Maybe i just forgot to add something :(

Thx a lot in advance.

Best regards,

Joachim

Message 2 in thread

Joachin,

> So can anybody of you give me some example code that is 
> working for shure in order to test the communication? Maybe i 
> just forgot to add something :( 

Use this version, not the out of date SourceForge version:
    http://wil.linux.krakow.pl/~doctor/1.0.0d.zip 

Apply this patch to prevent a random crash/memory corruption:

--- was ---
bool Win_QextSerialPort::open(OpenMode mode)  {
	unsigned long confSize;
-----------

-- should be ---
bool Win_QextSerialPort::open(OpenMode mode)  {
	unsigned long confSize = sizeof(COMMCONFIG);
	Win_CommConfig.dwSize = confSize;
---------------- 


Try something like this:

    serial = new QextSerialPort();
    serial->setBaudRate(BAUD4800); 
    serial->setParity(  PAR_NONE); 
    serial->setDataBits(DATA_8); 
    serial->setStopBits(STOP_1);
    serial->setPortName(QString("COM%1").arg(portNumber));

    if( serial->open(QIODevice::ReadOnly) ) {
		.. read stuff
    }

The above is for read-only.  Writing is much the same
except changing the QIODevice parameter. The rest is as
per QIODevice. For example, to read:

    const qint64 available = serial->bytesAvailable(); 
    if( available > 0) { 
        buffer += serial->read(available);
	.. etc
    }




Regards,

Stuart

--
 [ signature omitted ] 

Message 3 in thread

Hi Stuart,

thank you a lot for your reply. Unfortunately I am not able to download from
the link you provided. Is this server currently online?

Looking forward to test it :) Is this version also QT4.2.2 compatible and
thread-safe? I just ask, because in the final version of my app i need to
exchange data with two serial ports at the same time and i want to realise
this with threads.

Best regards,

Joachim

2007/2/18, Stuart Nixon <Stuart@xxxxxxxxxxxx>:
>
> Joachin,
>
> > So can anybody of you give me some example code that is
> > working for shure in order to test the communication? Maybe i
> > just forgot to add something :(
>
> Use this version, not the out of date SourceForge version:
>     http://wil.linux.krakow.pl/~doctor/1.0.0d.zip
>
> Apply this patch to prevent a random crash/memory corruption:
>
> --- was ---
> bool Win_QextSerialPort::open(OpenMode mode)  {
>         unsigned long confSize;
> -----------
>
> -- should be ---
> bool Win_QextSerialPort::open(OpenMode mode)  {
>         unsigned long confSize = sizeof(COMMCONFIG);
>         Win_CommConfig.dwSize = confSize;
> ----------------
>
>
> Try something like this:
>
>     serial = new QextSerialPort();
>     serial->setBaudRate(BAUD4800);
>     serial->setParity(  PAR_NONE);
>     serial->setDataBits(DATA_8);
>     serial->setStopBits(STOP_1);
>     serial->setPortName(QString("COM%1").arg(portNumber));
>
>     if( serial->open(QIODevice::ReadOnly) ) {
>                 .. read stuff
>     }
>
> The above is for read-only.  Writing is much the same
> except changing the QIODevice parameter. The rest is as
> per QIODevice. For example, to read:
>
>     const qint64 available = serial->bytesAvailable();
>     if( available > 0) {
>         buffer += serial->read(available);
>         .. etc
>     }
>
>
>
>
> Regards,
>
> Stuart
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>

Message 4 in thread

This is thread safe (if you use an instance of a QextSerialPort in a single
thread - I use it in a thread-heavy application), and under 4.2.2

I'll email you the ZIP file in an off-list email

Stuart

  -----Original Message-----
  From: Joachim Zettler [mailto:joachim.zettler@xxxxxxxxxxxxxx]
  Sent: Sunday, 18 February 2007 8:07 PM
  To: Stuart@xxxxxxxxxxxx
  Cc: qt-interest@xxxxxxxxxxxxx
  Subject: Re: Problem with SerialPort Connection when using Qextserial


  Hi Stuart,

  thank you a lot for your reply. Unfortunately I am not able to download
from the link you provided. Is this server currently online?

  Looking forward to test it :) Is this version also QT4.2.2 compatible and
thread-safe? I just ask, because in the final version of my app i need to
exchange data with two serial ports at the same time and i want to realise
this with threads.

  Best regards,

  Joachim


  2007/2/18, Stuart Nixon <Stuart@xxxxxxxxxxxx>:
    Joachin,

    > So can anybody of you give me some example code that is
    > working for shure in order to test the communication? Maybe i
    > just forgot to add something :(

    Use this version, not the out of date SourceForge version:
        http://wil.linux.krakow.pl/~doctor/1.0.0d.zip

    Apply this patch to prevent a random crash/memory corruption:

    --- was ---
    bool Win_QextSerialPort::open(OpenMode mode)  {
            unsigned long confSize;
    -----------

    -- should be ---
    bool Win_QextSerialPort::open(OpenMode mode)  {
            unsigned long confSize = sizeof(COMMCONFIG);
            Win_CommConfig.dwSize = confSize;
    ----------------


    Try something like this:

        serial = new QextSerialPort();
        serial->setBaudRate(BAUD4800);
        serial->setParity(  PAR_NONE);
        serial->setDataBits(DATA_8);
        serial->setStopBits(STOP_1);
        serial->setPortName(QString("COM%1").arg(portNumber));

        if( serial->open(QIODevice::ReadOnly) ) {
                    .. read stuff
        }

    The above is for read-only.  Writing is much the same
    except changing the QIODevice parameter. The rest is as
    per QIODevice. For example, to read:

        const qint64 available = serial->bytesAvailable();
        if( available > 0) {
            buffer += serial->read(available);
            .. etc
        }




    Regards,

    Stuart

    --
    To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
    List archive and information: http://lists.trolltech.com/qt-interest/




Message 5 in thread

Stuart Nixon wrote:
> This is thread safe (if you use an instance of a QextSerialPort in a single
> thread - I use it in a thread-heavy application), and under 4.2.2
>  
> I'll email you the ZIP file in an off-list email

I'll need to use this relatively soon, and I can't get to the server 
either. Can you please send me a copy too.

I can host a copy of the patched code if that would be useful?

Thanks,

Richard

--
 [ signature omitted ] 

Message 6 in thread

Hi Stuart,

i have managed to get the qextserial to work pretty well when it comes to
writing.

Now I also need to read from a serial port. The problem is, that i do not
know exactly when i have to read :( Do I need to listen to the port all the
time when somebody wants to send something or is there a buffer that can
store the data until i collect it with read?

Thank you in advance for your help

Best regards,

Joachim

2007/2/18, Stuart Nixon <Stuart@xxxxxxxxxxxx>:
>
> Joachin,
>
> > So can anybody of you give me some example code that is
> > working for shure in order to test the communication? Maybe i
> > just forgot to add something :(
>
> Use this version, not the out of date SourceForge version:
>     http://wil.linux.krakow.pl/~doctor/1.0.0d.zip
>
> Apply this patch to prevent a random crash/memory corruption:
>
> --- was ---
> bool Win_QextSerialPort::open(OpenMode mode)  {
>         unsigned long confSize;
> -----------
>
> -- should be ---
> bool Win_QextSerialPort::open(OpenMode mode)  {
>         unsigned long confSize = sizeof(COMMCONFIG);
>         Win_CommConfig.dwSize = confSize;
> ----------------
>
>
> Try something like this:
>
>     serial = new QextSerialPort();
>     serial->setBaudRate(BAUD4800);
>     serial->setParity(  PAR_NONE);
>     serial->setDataBits(DATA_8);
>     serial->setStopBits(STOP_1);
>     serial->setPortName(QString("COM%1").arg(portNumber));
>
>     if( serial->open(QIODevice::ReadOnly) ) {
>                 .. read stuff
>     }
>
> The above is for read-only.  Writing is much the same
> except changing the QIODevice parameter. The rest is as
> per QIODevice. For example, to read:
>
>     const qint64 available = serial->bytesAvailable();
>     if( available > 0) {
>         buffer += serial->read(available);
>         .. etc
>     }
>
>
>
>
> Regards,
>
> Stuart
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>

Message 7 in thread

Hi,

On Sunday 18 February 2007 11:35, Joachim Zettler wrote:
> I already found the qextserial classes and the example from sourceforge.

I'm using the single class Qt 4 version from sourceforge. (Checked out via cvs 
from sf.net).
It's working quite well on my linux box but on the mac I only can read the 
first bytes (around 500) and then read stop's working:

bytesAvailable() will report the buffer is filling with up to 1020 bytes but
buffer += serialPort.read(available);
doesn't append anything to the buffer.

I'm using it as in the example given in this thrad:
http://lists.trolltech.com/qt-interest/2006-11/thread00450-0.html

I noticed that in QextSerialPort::readData()
deviceRead = Posix_File->read( data, maxSize )
returns 0 although bytesAvailable reports bytes available for being read.

I also tried the multiple classes version with the same result. 
Has anyone used this library succussfully on OSX?
I'll investigate further.

Cheers

Meinhard

P.S.
There seem to float around quite a couple of different sources of QextSerial.
Wouldn't it be good to provide Stefan with necessary patches to be 
incorporated in the sf.net version? Assuming it's still developed and 
maintained activly.

--
 [ signature omitted ] 

Message 8 in thread

Hi,

On Sunday 18 February 2007 15:53, M. Ritscher wrote:
> Has anyone used this library succussfully on OSX?
> I'll investigate further.
seems like I have found a solution but no explanation though.

> I noticed that in QextSerialPort::readData()
> deviceRead = Posix_File->read( data, maxSize )
> returns 0 although bytesAvailable reports bytes available for being read.
>
In the single class version I replaced Posix_File from being a QFile instance 
to being an int.
Then replacing
	- all Posix_File->handle() with Posix_File;
	- Posix_File->open( QIDevice::ReadWrite|....
	  with Posix_File = ::open(Name.toAscii().data(), O_RDWR | O_NONBLOCK)
	- Posix_File->read(data, maxSize) 
	  with ::read(Posix_File, data, maxSize)
	- Posix_File->write( data, size)
	  with ::write(Posix_File, data, size)
	- remove delete Posix_File statements
and add 
#include <fcntl.h>

I might have forgotten something, but you got the hang of it I suppose.

With theese changes it still works on my linux box too. Still I "ifdef"ed all 
with Q_OS_MACX just to make sure.

I'm not entirely sure why but it boils down to that QFile.read() fails getting 
more data after the first call.
So if someone could enlighten me, I'd be very grateful.

Cheers,

Meinhard


--
 [ signature omitted ] 

Message 9 in thread

You need to check bytesAvailable and read data whenever it is available
(bytesAvailable returns the number of bytes available). :)
 
Sandor
 

-----Original Message-----
From: Joachim Zettler [mailto:joachim.zettler@xxxxxxxxxxxxxx]
Sent: 27/02/2007 14:46
To: Stuart@xxxxxxxxxxxx
Cc: qt-interest@xxxxxxxxxxxxx
Subject: Re: Problem with SerialPort Connection when using Qextserial


Hi Stuart,

i have managed to get the qextserial to work pretty well when it comes to
writing. 

Now I also need to read from a serial port. The problem is, that i do not
know exactly when i have to read :( Do I need to listen to the port all the
time when somebody wants to send something or is there a buffer that can
store the data until i collect it with read? 

Thank you in advance for your help

Best regards,

Joachim


2007/2/18, Stuart Nixon < Stuart@xxxxxxxxxxxx <mailto:Stuart@xxxxxxxxxxxx>
>: 

Joachin,

> So can anybody of you give me some example code that is
> working for shure in order to test the communication? Maybe i
> just forgot to add something :(

Use this version, not the out of date SourceForge version: 
     http://wil.linux.krakow.pl/~doctor/1.0.0d.zip
<http://wil.linux.krakow.pl/~doctor/1.0.0d.zip> 

Apply this patch to prevent a random crash/memory corruption:

--- was ---
bool Win_QextSerialPort::open(OpenMode mode)  { 
        unsigned long confSize;
-----------

-- should be ---
bool Win_QextSerialPort::open(OpenMode mode)  {
        unsigned long confSize = sizeof(COMMCONFIG);
        Win_CommConfig.dwSize = confSize; 
----------------


Try something like this:

    serial = new QextSerialPort();
    serial->setBaudRate(BAUD4800);
    serial->setParity(  PAR_NONE);
    serial->setDataBits(DATA_8);
    serial->setStopBits(STOP_1);
    serial->setPortName(QString("COM%1").arg(portNumber));

    if( serial->open(QIODevice::ReadOnly) ) {
                .. read stuff
    }

The above is for read-only.  Writing is much the same 
except changing the QIODevice parameter. The rest is as
per QIODevice. For example, to read:

    const qint64 available = serial->bytesAvailable();
    if( available > 0) {
        buffer += serial->read(available); 
        .. etc
    }




Regards,

Stuart

--
 [ signature omitted ] 

Message 10 in thread

Ah ok...thanks a lot. With this method it works quite fine.

Best regards,

Joachim

2007/2/27, Hadas Sandor <Sandor.Hadas@xxxxxxxx>:
>
>  You need to check bytesAvailable and read data whenever it is available
> (bytesAvailable returns the number of bytes available). :)
>
> Sandor
>
>
> -----Original Message-----
> *From:* Joachim Zettler [mailto:joachim.zettler@xxxxxxxxxxxxxx]
> *Sent:* 27/02/2007 14:46
> *To:* Stuart@xxxxxxxxxxxx
> *Cc:* qt-interest@xxxxxxxxxxxxx
> *Subject:* Re: Problem with SerialPort Connection when using Qextserial
>
> Hi Stuart,
>
> i have managed to get the qextserial to work pretty well when it comes to
> writing.
>
> Now I also need to read from a serial port. The problem is, that i do not
> know exactly when i have to read :( Do I need to listen to the port all the
> time when somebody wants to send something or is there a buffer that can
> store the data until i collect it with read?
>
> Thank you in advance for your help
>
> Best regards,
>
> Joachim
>
> 2007/2/18, Stuart Nixon <Stuart@xxxxxxxxxxxx>:
> >
> > Joachin,
> >
> > > So can anybody of you give me some example code that is
> > > working for shure in order to test the communication? Maybe i
> > > just forgot to add something :(
> >
> > Use this version, not the out of date SourceForge version:
> >     http://wil.linux.krakow.pl/~doctor/1.0.0d.zip<http://wil.linux.krakow.pl/%7Edoctor/1.0.0d.zip>
> >
> > Apply this patch to prevent a random crash/memory corruption:
> >
> > --- was ---
> > bool Win_QextSerialPort::open(OpenMode mode)  {
> >         unsigned long confSize;
> > -----------
> >
> > -- should be ---
> > bool Win_QextSerialPort::open(OpenMode mode)  {
> >         unsigned long confSize = sizeof(COMMCONFIG);
> >         Win_CommConfig.dwSize = confSize;
> > ----------------
> >
> >
> > Try something like this:
> >
> >     serial = new QextSerialPort();
> >     serial->setBaudRate(BAUD4800);
> >     serial->setParity(  PAR_NONE);
> >     serial->setDataBits(DATA_8);
> >     serial->setStopBits(STOP_1);
> >     serial->setPortName(QString("COM%1").arg(portNumber));
> >
> >     if( serial->open(QIODevice::ReadOnly) ) {
> >                 .. read stuff
> >     }
> >
> > The above is for read-only.  Writing is much the same
> > except changing the QIODevice parameter. The rest is as
> > per QIODevice. For example, to read:
> >
> >     const qint64 available = serial->bytesAvailable();
> >     if( available > 0) {
> >         buffer += serial->read(available);
> >         .. etc
> >     }
> >
> >
> >
> >
> > Regards,
> >
> > Stuart
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
> >
> >
>