[Qt-interest] serial communication, RTS and DTR

Yuvraj yuvraj.ragupathi at indieontech.com
Wed Mar 31 15:50:01 CEST 2010


HardMaker wrote:
> Hi, yes, I open the port, the complete code is:
>
> void Dialog::on_btnOpenPort_clicked()
> {
>     serial->setBaudRate(BAUD9600);
>     serial->setFlowControl(FLOW_OFF);
>     serial->setParity(PAR_NONE);
>     serial->setDataBits(DATA_8);
>     serial->setStopBits(STOP_2);
>
>     if(serial->open(QIODevice::ReadWrite|QIODevice::Unbuffered))
>         ui->logList->addItem(new QListWidgetItem ("Open: TRUE"));
>     else
>         ui->logList->addItem(new QListWidgetItem ("Open: FALSE"));
> }
>
> Where logList is a QListWidget where write some text to debug.
> The "serial" was defined in the Dialog class. I have buttons to togle 
> RTS and DTR:
>
> void Dialog::on_rtsOn_clicked()
> {
>     serial->setRts(true);
> }
>
> void Dialog::on_rtsOff_clicked()
> {
>     serial->setRts(false);
> }
>
> void Dialog::on_dtrOn_clicked()
> {
>     serial->setDtr(true);
> }
>
> void Dialog::on_dtrOff_clicked()
> {
>     serial->setDtr(false);
> }
>
> And with other button close the port:
>
> void Dialog::on_btnClosePort_clicked()
> {
>     if(serial->isOpen())
>     {
>       serial->close();
>       if(serial->isOpen())
>       {
>         ui->logList->addItem(new QListWidgetItem ("No cerr?"));
>       }
>       else
>       {
>         ui->logList->addItem(new QListWidgetItem ("Cerro OK"));
>       }
>     }
>     else
>         ui->logList->addItem(new QListWidgetItem ("Not opened!"));
> }
>
>
>
> Denis Akhmetzyanov escribió:
>   
>> Hi,
>> Are you open port before setRts() ?
>>
>>     serial->open(QIODevice::ReadWrite) 
>>
>>
>> 2010/3/30 HardMaker <hardmaker at gmail.com <mailto:hardmaker at gmail.com>>
>>
>>     Hi,
>>     I'm trying to make a serial comunication too and I need to control the
>>     RTS and DTR lines. Not for make a hardware hand shaking, yust I
>>     wan't to
>>     drive this lines and send and recive data trow the serial port as
>>     diferents things.
>>     As you suggest, I try QextSerialPort from google and use this code on
>>     linux to initialize the port:
>>
>>        QextSerialPort serial = new QextSerialPort();
>>        serial->setBaudRate(BAUD9600);
>>        serial->setFlowControl(FLOW_OFF);
>>        serial->setParity(PAR_NONE);
>>        serial->setDataBits(DATA_8);
>>        serial->setStopBits(STOP_2);
>>
>>     but when I press a button to execute this code:
>>
>>      serial->setRts(true);
>>     or
>>      serial->setRts(false);
>>
>>     Nothing happend, I'm using a digital voltimeter conected to RTS and
>>     don't change. But, if use other applications  it's ok  (the
>>     hardware work).
>>     Can helpme?
>>
>>     Thank's
>>
>>     Sergio
>>
>>     Yuvraj escribió:
>>     > Denis Akhmetzyanov wrote:
>>     >
>>     >> Hi,
>>     >> I suggest you to try
>>     >> QextSerialPort http://code.google.com/p/qextserialport/ instead
>>     of the
>>     >> native calls. It is a convenient class implements QIODevice and
>>     >> supports signal/slot technology and asynchronous calls.
>>     >>
>>     >>
>>     >> 2010/3/30 Yuvraj <yuvraj.ragupathi at indieontech.com
>>     <mailto:yuvraj.ragupathi at indieontech.com>
>>     >> <mailto:yuvraj.ragupathi at indieontech.com
>>     <mailto:yuvraj.ragupathi at indieontech.com>>>
>>     >>
>>     >>      Hi ,
>>     >>
>>     >>     Here i am opening the serial communication device file and
>>     writing
>>     >>     some data, in other hand i am not getting the data due to enter
>>     >>     key( "/r/n")
>>     >>
>>     >>     my code is
>>     >>
>>     >>      file_descriptor = open("/dev/ttyS0",O_RDWR);
>>     >>         if(file_descriptor > 0)
>>     >>         {
>>     >>              timer = new QTimer;
>>     >>             timer1 =new QTimer;
>>     >>
>>     >>    
>>     QObject::connect(timer,SIGNAL(timeout()),this,SLOT(browser_append()));
>>     >>
>>     >>    
>>     QObject::connect(timer1,SIGNAL(timeout()),this,SLOT(on_send_clicked()));
>>     >>             timer->start(1);
>>     >>             timer1->start(10);
>>     >>         }
>>     >>         else
>>     >>         {
>>     >>             QMessageBox::information(0,"","Connection failed");
>>     >>         }
>>     >>
>>     >>
>>     >>     void  window::on_send_clicked()
>>     >>     {
>>     >>          int file_id;
>>     >>        char send_data[150]= "Hi Hello\r\n";
>>     >>         if(file_descriptor > 0)
>>     >>         {
>>     >>            file_id= write(file_descriptor,send_data,15);
>>     >>            ui->send_text->clear();
>>     >>            ui->send_text->setFocus();
>>     >>            if(file_id > 0)
>>     >>            {
>>     >>                qDebug()<<"Data successfully written \n";
>>     >>            }
>>     >>
>>     >>
>>     >>         }
>>     >>
>>     >>     }
>>     >>
>>     >>     any  ideas?
>>     >>
>>     >>     Thanks
>>     >>
>>     >>     Yuvaraj R
>>     >>
>>     >>
>>     >>     _______________________________________________
>>     >>     Qt-interest mailing list
>>     >>     Qt-interest at trolltech.com
>>     <mailto:Qt-interest at trolltech.com>
>>     <mailto:Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>>
>>     >>     http://lists.trolltech.com/mailman/listinfo/qt-interest
>>     >>
>>     >>
>>     >>
>>     > There itself i am facing  same issue (key enter )
>>     >
>>     > Thanks
>>     > Yuvaraj
>>     > _______________________________________________
>>     > Qt-interest mailing list
>>     > Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>>     > http://lists.trolltech.com/mailman/listinfo/qt-interest
>>     >
>>     >
>>
>>
>>
>>     _______________________________________________
>>     Qt-interest mailing list
>>     Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>>     http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>>
>>     
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>   
Hi ,

I want receive the data from RS 232  continuously. I tried with while 
loop and timer, but my GUI is hanging.

Any other way to receive the data continuously?


Thanks

Yuvraj




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100331/15233c72/attachment.html 


More information about the Qt-interest-old mailing list