Results 1 to 20 of 32

Thread: QT interface with telnet (hyperterminal) connection. Plotting received data

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Posts
    26
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    Hello Nix,

    Yes, I would be interested in the source code you used. I have to say that I am a little bit surprised that new versions of QT cannot manage a Telnet connection with an ad-hoc network. I "only" need to do something like "telnet 169.254.1.1 2000". With a terminal emulator it works fine, why should not I do this with QT only?

    I think some classes in the Network library can do this, but I am unable to find the way.

    Let me know if you can do the tarball you mentioned. I´ll continue looking for a solution.

    Thanks a lot,

    -E

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    You can do a simple stream of commands trivially with a QTcpSocket and state machine. If you want a full implementation of Telnet (RFC 854) with its interupt handling, and virtual terminal requirements then that is a more complicated and specific problem.

    Qt Code:
    1. #include <QtCore>
    2. #include <QtNetwork>
    3. #include <QDebug>
    4.  
    5. class Example: public QObject {
    6. Q_OBJECT
    7. public:
    8. Example(QObject *p = 0): QObject(p) {
    9. connect(&sock, SIGNAL(connected()), this, SLOT(connected()));
    10. connect(&sock, SIGNAL(disconnected()), this, SLOT(disconnected()));
    11. connect(&sock, SIGNAL(readyRead()), this, SLOT(readyRead()));
    12. }
    13.  
    14. void run() {
    15. sock.connectToHost("www.google.com", 80);
    16.  
    17. }
    18. public slots:
    19. void connected() {
    20. QByteArray ba("GET / HTTP/1.0\r\n\r\n");
    21. sock.write(ba);
    22. qDebug() << "Wrote:" << ba;
    23. }
    24. void disconnected() {
    25. qDebug() << "Disconnected";
    26. qApp->exit();
    27. }
    28. void readyRead() {
    29. QByteArray ba = sock.readAll();
    30. qDebug() << "Read:" << ba;
    31. }
    32.  
    33. private:
    34. QTcpSocket sock;
    35. };
    36.  
    37. int main(int argc, char *argv[])
    38. {
    39. QCoreApplication app(argc, argv);
    40.  
    41. Example e;
    42. e.run();
    43.  
    44. return app.exec();
    45. }
    46. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ChrisW67 for this useful post:

    Ethan (13th July 2011)

  4. #3
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    Exactly, I'm not sure we are really agree with what Telnet is.

    Telnet run usually on port 23, it is a TCP server communicating using a given protocol (can ask you login and give you a shell, interpret some special sequences characters ....).
    If you just want to connect to a port (2000) and send some data of your own you just have to use QTcpSocket that all.

    Please give more detail on what you want to do on the port you used and which commands (actions) you want a run. Or maybe, simply post the data you sent in your hyperterminal to be sure there is no misunderstanding here.

  5. #4
    Join Date
    Jun 2011
    Posts
    26
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    Hello again Nix,

    First of all, thank you for your time. I thought the same as you with regards to the Telnet protocol, it is usually on port 23, but in the case of the device i am trying to communicate the connection is carried out on port 2000.

    I am working with a device from roving networks. What I want to do exactly is in this link: http://www.rovingnetworks.com/Docs/WiFly-RN-UM.pdf

    Pages 6-9 shows what I want to do. It is just to create an ad-hoc connection between the device and my pc, connect to it and sends ASCII commands that provide me some response (for example the value of some digital inputs the device has). By using Teraterm or Hyperterminal emulators I can do this (it is, connect doing a telnet 169.254.1.1 2000 and send ASCII commands) . What I want to do is just the same but through a QT interface that manages this Telnet connection.

    For example, one ASCII command I would like to send is "show q", when writing this in the hyperterminal I can see this answer:

    <2.21> show q
    87377a,
    <2.21>

    Then, with this value I would try to do something in the QT interface, for example a plot. And that is mainly what I want to do, to receive these sort of data by the QT interface.

    As you can read in page 9, what is done is a telnet connection throught wifi, but on port 2000 instead of port 23.

    Thanks a lot,

    -E
    Last edited by Ethan; 13th July 2011 at 15:44.

  6. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    @up: reported to forum staff, advertisements are forbidden

  7. #6
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    Ok, it's just a problem of misunderstanding. They use telnet term in the doc but it's only a classic tcp socket you need. So you have to use QTcpSocket and probably add a state machine too, in order to manage the protocol.
    A good next move will be : read the documentation of QTcpSocket, QAbstractSocket and take a look to Fortune Client Example (in qt sources).

  8. The following user says thank you to nix for this useful post:

    Ethan (13th July 2011)

  9. #7
    Join Date
    Jun 2011
    Posts
    26
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    May I ask why do you know it is not a Telnet protocol ? ChrisW67 answered the same as you. Thanks for the info, I am going to take a look to the documentation you mentioned.

    -E

  10. #8
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    Because when you look at the way your device communicate in the documentation it has nothing to do with telnet standard protocol .

    In fact this is a bit confusing because you can use a command like
    telnet 169.254.1.1 2000
    to communicate with your device but it's just the name of a program and that not mean your are using full Telnet protocol. In your case it's just a socket, telnet programm send the data you give to the other side and display data it received. You can do that easily with QTcpSocket.

  11. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    If you never send anything but ASCII characters and expect them in return then the standard telnet client is just a glorified TCP socket giving a transparent pipe. If you send any of the telnet escape codes (bytes with values 240 - 255) then telnet can diverge from being a transparent pipe.
    Last edited by ChrisW67; 13th July 2011 at 23:42.

  12. #10
    Join Date
    Jun 2011
    Posts
    26
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    The code posted by ChrisW67 works fine for me. In my case, I changed this part:
    Qt Code:
    1. void connected() {
    2. QByteArray ba("GET / HTTP/1.0\r\n\r\n");
    3. sock.write(ba);
    4. qDebug() << "Wrote:" << ba;
    To copy to clipboard, switch view to plain text mode 

    by this one:
    Qt Code:
    1. public slots:
    2. void connected()
    3. {
    4. QByteArray ba("$$$");
    5. sock.write(ba);
    6. qDebug() << "Wrote:" << ba;
    7. }
    To copy to clipboard, switch view to plain text mode 

    And everything seems to work fine, I can see I receive Read: "*Hello*" and Read: "CMD", which means that the device is answering to the command "$$$" I sent. However, what I would like to do is to send another ASCII command and then receive data. I thought about doing this:

    Qt Code:
    1. public slots:
    2. void connected()
    3. {
    4. QByteArray ba("$$$");
    5. sock.write(ba);
    6. qDebug() << "Wrote:" << ba;
    7. QByteArray bb("show q\r");
    8. sock.write(bb);
    9. qDebug() << "Wrote:" << bb;
    10. }
    To copy to clipboard, switch view to plain text mode 

    But this does not work, after sending "show q" in the last variation of the connected method I should receive (appart from Read: "*Hello*" and Read: "CMD") something like "8735b7", however i receive only "Hello", and even I dont receive CMD (which is the response when "$$$" is sent), and that is why i know i am doing something wrong when trying to write two times in the connected method.

    My goal is to send different commands and receive data (send command and receive response, send another command and receive response...). Im planning to do it with a widget, but first I would like to do it just by code or by using the console. Any suggestion?

    Kind regards,

    -E

  13. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    Your code assumes that the write() calls are blocking. This is not the case in Qt. The write() calls queue data to be sent, but it will not actually be sent until the program returns to the event loop. Some time later the data will have been sent and a result (possibly) received. The other end will probably receive your two commands immediately after each other: how it handles that depends on their software. This is why I suggested some sort of state machine. The complexity involved depends on how flexible the script of commands must be and how fault tolerant you need to be.
    Last edited by ChrisW67; 19th September 2011 at 23:37.

  14. The following user says thank you to ChrisW67 for this useful post:

    Ethan (24th September 2011)

  15. #12
    Join Date
    Jun 2011
    Posts
    26
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Post Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    I got what you meant ChrisW67 and I could fix my problem, thanks.

    I restructured my code and I created a small interface with Designer.
    Now I send the "$$$" command and with a QLineEdit widget I can send another commands, the device is answering, but there is yet something strange.

    If I use hyperterminal when sending the "show q" command I receive something like:

    8735db,
    <2.21>

    However, with QT I receive:

    Received:
    " show q
    Received:
    "
    8735db,
    <2.21> "

    So it seems I am receiving an echo which I do not receive with hyperterminal or another program such as UTF-Teraterm. The main parts which are related with this in my QT code are the followings:

    Qt Code:
    1. //In the constructor of my class
    2.  
    3. connect(lineEdit, SIGNAL(clicked()),this, SLOT(sendCommand()));
    4. connect(&sock, SIGNAL(readyRead()), this, SLOT(receiveData()));
    5.  
    6. //Custom Slots
    7. void FindDialog::sendCommand()
    8. {
    9. QByteArray str = lineEdit->text().toLocal8Bit();
    10. sock.write(str);
    11. sock.write("\r");
    12. qDebug() << " Wrote: " << str;
    13. }
    14.  
    15. void FindDialog::receiveData()
    16. {
    17. ba = sock.readAll();
    18. display->setText(ba);
    19. qDebug() << " Received: " << ba;
    20. }
    To copy to clipboard, switch view to plain text mode 


    Basically, when pressing a QpushButton I send "show q", and it seems receiveData() is executed twice!! ("received" in Qdebug appears two times when pressing the pushbutton). I am thinking it has something to do with the ReadyRead().

    I am almost 100 (because it does not happen with hyperterminal and UTF-Teraterm and customer support of the device answered me that it does not echo the remote data packets back to the sender) sure the device does not make echo of what I send, so which can be the reason of this behaviour? Am I missing something with the socket connection?.

    Kind regards,

    -E

  16. #13
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    This is odd. Anything professing to do TELNET should default to no echo over the wire. There is a mechanism to negotiate echo but I think this is probably not where you want to go.

    Are you sure that the remote end is expecting a carriage return ('\r') without a line feed ('\n') at line 11 ? Perhaps the echo is an error indication. What is the character before the "show q" is the response? You might need to dump the incoming byte array as hex to see.

  17. #14
    Join Date
    Aug 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    Hi Ethan ,
    Can you please tell how you control telnet through QT GUI. I am getting Hostname not found error while trying to connect using QtTcpSocket..

    Can you plese share how you do it.

    Nitish

  18. #15
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT interface with telnet (hyperterminal) connection. Plotting received data

    "Hostname not found" means that the host name you gave whatever program issued that error message could not be resolved into an address. This is either a bad name on your part, or a bad DNS or hosts file. I fail to see what this has to do with Qt.

Similar Threads

  1. Telnet connection does not establish...
    By gentlesea in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2011, 09:54
  2. Methods to display received data
    By pupqt in forum Qt Programming
    Replies: 3
    Last Post: 18th April 2011, 09:50
  3. Plotting socket data
    By catto in forum Qwt
    Replies: 4
    Last Post: 6th March 2011, 08:01
  4. Replies: 2
    Last Post: 6th November 2010, 05:06
  5. Widget for data plotting
    By Benjamin in forum Qt Programming
    Replies: 3
    Last Post: 12th February 2009, 15:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.