how to transmit one after another in serialport connection .



  • this program is for transmitting data in bit form, But i need transmit one after another. For example if press key one data has to be transmitted rather than all at at a time. please kindly help me. thanks in advance.

    void SerialConnect::write(const QString datan) {

    unsigned char engine3 = 64;
    unsigned char engine4 = 65;

    QByteArray byteToSend3(1, engine3);

    QByteArray byteToSend4(1, engine4);

    qint64 bytesWritten3 = serial->write(byteToSend3);
    qint64 bytesWritten4 = serial->write(byteToSend4);

    if (bytesWritten3==(-1) && bytesWritten4 ==(-1) ){
    qDebug() << "Error writing data to serial port: " << serial->errorString();
    }
    qDebug() << "SerialConnect::write(QString) Text sent as QByteArray: " << byteToSend3;
    qDebug() << "Number of bytes written: " << bytesWritten3;

            qDebug() << "SerialConnect::write(QString) Text sent as QByteArray: " << byteToSend4;
            qDebug() << "Number of bytes written: " << bytesWritten4;
    

    }



  • Do you think that whole writing as '64 65' it is not a 'one after another' ? o_O
    I dare to assure that it follows as "one after another"! :)



  • @kuzulis
    yes it is not one after another , but need to modify the code as sending one after another. I need a logic to implement it.



  • yes it is not one after another

    Really? Do you think it is sends in parallell? Or by other magic way?

    It seems to me, you do not know what do you need...



  • @kuzulis

    soryy i could not described it properly . Actually i am implementing this program to control the robotic arm . So there are 6 stepper motors in robo .each motor has its own separate actions for being controlled . I need to write a program to control the robotic arm by pressing keyboard buttons or graphical displayed buttons. So whenever i press the button only one required action should be triggered, it means only one action has to be sent . I need a logic place in my code. Please kindly help me.


  • Moderators

    @AnilReddy I think what @kuzulis is trying to tell you is that you can send several bytes at once in one QByteArray, so there is no need to send first, then send second.



  • @jsulm
    ok , But i need to control the flow by pressing keys.



  • @AnilReddy
    Maybe it would help reading some Documentation about QPushButton and to play around with the attached examples to get a feeling how everything works.
    https://wiki.qt.io/How_to_Use_QPushButton

    Buttons and all kinds of stuff can also be created in the WYSIWYG editor named QT Designer, if you don't want to type in all the code yourself.
    http://doc.qt.io/qt-5/qtdesigner-manual.html


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.