Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32

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

  1. #21
    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.

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

    Ethan (24th September 2011)

  3. #22
    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

  4. #23
    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.

  5. #24
    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

    I tried both, with carriage return ('\r') and line feed ('\n') and with only carriage return ('\r'). I also did a netcat (netcat ip port) and what surprised me is that in that case I received the echo, which does not happen with Teraterm pro or Hyperterminal. The support service of the device told me that the connection is just a socket on a port and the devices does not dont echo the remote data packets back to the sender. So, that's odd but I think it has something to do with the carriage return. For now what i am doing is removing the echo when receiving the data (not the best solution...)

    -E

  6. #25
    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

    Firstly I would expect the receiver to take either a lone \n or the \r\n pair (which you haven't tried AFAICT).
    If you see the echo with netcat then this is not a Qt issue.

    Use the -o option of nc to capture a hex dump of the "show q" outbound message and its inbound response. Post it.

  7. #26
    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 ChrisW67,

    Thanks. Although I didnt tell in my previous post, I also tried \n and \r\n, in the first case the device does response, and in the second (\r\n) the response is the same one with only \r, i.e., an echo and after the expected data.

    I tried "nc -o <ip file> <port> but I am not able of capturing my outbound message.

    **Here is what I have so far with netcat:

    I first send "$$$" to enter in command mode and the device answer me with "CMD" as expected (NOTE: $$$ is sent without carrier return or line feed)
    After that, I send "show q" only, although I tried to send carriage return and line feed (i have read it is possible by pressing ctrl+v or ctrl+m, but I am not sure if it that is true). This is what I record in a txt file.

    < 00000000 43 4d 44 0d 0a # CMD..
    < 00000005 73 68 6f 77 20 71 0a # show q.
    < 0000000c 73 68 6f 77 20 71 2e 0a # show q..
    < 00000014 73 73 68 68 6f 6f 77 77 20 71 16 0a # sshhooww q..
    < 00000020 73 68 6f 77 20 71 2e 0a # show q..
    < 00000028 73 68 6f 77 20 71 0a # show q.
    < 0000002f 73 68 6f 77 20 71 0a # show q.
    < 00000036 73 68 6f 77 20 71 0a # show q.
    < 0000003d 73 68 6f 77 20 71 0a # show q.
    < 00000044 73 68 6f 77 20 71 0a # show q.
    < 0000004b 73 68 6f 77 20 71 0a # show q.
    < 00000052 73 68 6f 77 20 71 0a # show q.
    < 00000059 73 68 6f 77 20 71 0a # show q.
    < 00000060 0d 0a 38 37 33 35 38 36 2c 0d 0a 3c 32 2e 32 38 # ..873586,..<2.28
    < 00000070 3e 20 # >
    < 00000072 73 68 6f 77 20 71 0a # show q.


    As you can see, in the third last line I receive the data!

    However, this is the response with Hyperterminal (which is what i wanted to receive with qt, the expected answer, without echo):
    CMD //response to $$$

    show q //command i send




    <2.28> show q //response and I write in this line "show q"
    //response
    //response
    8735c3, //response

    <2.28> show q //i send again show q, <2.28> is also part of the previous response.
    //response
    //response
    873549, //response
    //response
    <2.28> //response

    //response
    873530, //response
    //response
    <2.28> //response



    Thanks,

    -E

  8. #27
    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 log file indicates only inbound traffic, and clearly that contains (mostly broken) echoed commands. This is not a Qt issue.

    To capture a clean run you should put the commands you wish to execute into a file (commands.txt):
    Qt Code:
    1. $$$
    2. show q
    To copy to clipboard, switch view to plain text mode 
    then execute netcat:
    Qt Code:
    1. nc -o hex.log -i 3 -w 10 host port < commands.txt
    To copy to clipboard, switch view to plain text mode 
    The lines will be sent with 3 second delays between to allow any processing time and terminate 10 seconds after the last command. The result should capture everything in and out and give you something to send to the vendor to demonstrate the echo problem. Here is an example from a simple SMTP server connection:
    Qt Code:
    1. < 00000000 32 32 30 2d 69 70 6d 61 69 6c 30 37 2e 61 64 6c # 220-ipmail07.adl
    2. < 00000010 32 2e 69 6e 74 65 72 6e 6f 64 65 2e 6f 6e 2e 6e # 2.internode.on.n
    3. < 00000020 65 74 20 45 53 4d 54 50 0d 0a 32 32 30 20 45 53 # et ESMTP..220 ES
    4. < 00000030 4d 54 50 3b 20 70 70 70 31 31 38 2d 32 30 38 2d # MTP; ppp118-208-
    5. < 00000040 31 30 31 2d 31 37 30 2e 6c 6e 73 32 30 2e 62 6e # 101-170.lns20.bn
    6. < 00000050 65 34 2e 69 6e 74 65 72 6e 6f 64 65 2e 6f 6e 2e # e4.internode.on.
    7. < 00000060 6e 65 74 20 5b 31 31 38 2e 32 30 38 2e 31 30 31 # net [118.208.101
    8. < 00000070 2e 31 37 30 5d 20 69 6e 20 4d 54 41 27 73 20 49 # .170] in MTA's I
    9. < 00000080 4e 53 49 44 45 69 6e 74 65 72 6e 6f 64 65 3b 20 # NSIDEinternode;
    10. < 00000090 64 72 69 76 69 6e 27 20 69 6e 74 6f 20 74 68 65 # drivin' into the
    11. < 000000a0 20 73 75 6e 73 65 74 0d 0a # sunset..
    12. > 00000000 48 45 4c 4f 20 6e 65 77 74 6f 6e 0a # HELO newton.
    13. < 000000a9 32 35 30 20 69 70 6d 61 69 6c 30 37 2e 61 64 6c # 250 ipmail07.adl
    14. < 000000b9 32 2e 69 6e 74 65 72 6e 6f 64 65 2e 6f 6e 2e 6e # 2.internode.on.n
    15. < 000000c9 65 74 0d 0a # et..
    16. > 0000000c 51 55 49 54 0a # QUIT.
    17. < 000000cd 32 32 31 20 69 70 6d 61 69 6c 30 37 2e 61 64 6c # 221 ipmail07.adl
    18. < 000000dd 32 2e 69 6e 74 65 72 6e 6f 64 65 2e 6f 6e 2e 6e # 2.internode.on.n
    19. < 000000ed 65 74 0d 0a # et..
    To copy to clipboard, switch view to plain text mode 

  9. #28
    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

    Definitely, there seems to be an echo. After putting the commands "$$$" and "show q" into a file (commands.txt) and running netcat, my hex.log is as follows:

    Qt Code:
    1. < 00000000 43 4d 44 0d 0a # CMD..
    2. < 00000005 73 68 6f 77 20 71 0d 0a 0d 0a 38 37 33 38 62 38 # show q....8738b8
    3. < 00000015 2c 0d 0a 3c 32 2e 32 38 3e 20 # ,..<2.28>
    To copy to clipboard, switch view to plain text mode 

    The only thing that I dont understand is why I dont see such an echo with Teraterm-pro or Hyperterminal. In any case, the information you have provided me through all this thread is very valuable to me to begin to understand how a socket connection works.

    Thank you very much for your kind help Chrisw67.

    -E
    Last edited by Ethan; 30th September 2011 at 11:32.

  10. #29
    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 hex log doesn't contain any of your outbound transmissions. They are indicated by ">" rather than "<". Have you removed them?

    You can use Wireshark to watch exactly what goes back and forth between HyperTerminal/TeraTerm and the device.

  11. #30
    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

    I didnt remove anything, this is exactly the hex.log recorded with the nc sentence. I thought it is odd that netcat did not record in the .log the outbound transmissions ( maybe version ?, dont know). Yes, I am planning to use wireshark.

    -E

  12. #31
    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

  13. #32
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.