[Solved]: Two different handler for same ready read signal in serial communication.



  • I am working with USB port as well as D-sub port(both are serial ports) at a time.
    Does anybody knows how to make two handler for same ready read signal in serial communication? May be identifying the ports which generates ready read signals..!!!

    Thanks in advance.



  • I just started working on it (Linux), and I am using "QtSerialPort":http://qt-project.org/wiki/QtSerialPort.
    also "getting it to work":http://qt-project.org/forums/viewthread/23839/



  • I am using qextserialport (third party library) for serial communication.


  • Moderators

    Why don't you have one slots per port (connected to one read-ready signa)l. Those extract the data from the port and put it into a QByteArray which is then handed over to another method that does the actual processing?



  • That's exactly my point. How will I come to know that which port has generated the ready read signal?

    Actually, I am using USB port for some modules and D-sub port for to connect another industrial PC (same as normal computer) and I have to use both at a time. Now to work with both serial ports at a time, How to differentiate both? so that I can identify port which has generated ready read signal and can use appropriate handler.

    Thanks for you reply.


  • Moderators

    You connect the one object's readReady signal to one slot and the other object's readReady signal to another one. I am afraid I do not understand the question:-)



  • Mine agenda was to use only one object for serial communication as I have developed few common functions like OpenPort(), WriteData()...
    If I use more objects then there is no use of my common functions as I have to check weather perticular port is opened or not..!!!
    e.g
    @
    qint64 SerialPort::WriteData(QString message)
    {
    if(port->isOpen())
    {
    QByteArray msg_ascii = message.toAscii();
    qint64 total=port->write(msg_ascii,msg_ascii.length());
    port->flush();
    }
    else
    return 0;
    }
    @
    [edit, code tags added, koahnig]


  • Moderators

    I guess you are confusing class and object in your posting.
    [quote]
    A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions.

    An object is an instantiation of a class. In terms of variables, a class would be the type, and an object would be the variable.[/quote] This is copied from "here":http://www.cplusplus.com/doc/tutorial/classes/

    What you want to do is having a common class definition with a method handling in both cases the readyRead signal.

    You could have something similar to this:
    @
    class MySerialClass : public QExtSerialPort
    {
    public slots:
    void sltReadyReadHandling (...);
    };
    @

    In your application you may have then:
    @
    MySerialClass UsbPort;
    MySerialClass DSubPort;

    ....
    @



  • Thanks kohnig,

    I solved the problem as well as confusion..!!!


Log in to reply
 

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