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.
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:
Code:
//In the constructor of my class
connect(lineEdit, SIGNAL(clicked()),this, SLOT(sendCommand()));
connect(&sock, SIGNAL(readyRead()), this, SLOT(receiveData()));
//Custom Slots
void FindDialog::sendCommand()
{
sock.write(str);
sock.write("\r");
qDebug() << " Wrote: " << str;
}
void FindDialog::receiveData()
{
ba = sock.readAll();
display->setText(ba);
qDebug() << " Received: " << ba;
}
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
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.
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
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.
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
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):
then execute netcat:
Code:
nc -o hex.log -i 3 -w 10 host port < commands.txt
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:
Code:
< 00000000 32 32 30 2d 69 70 6d 61 69 6c 30 37 2e 61 64 6c # 220-ipmail07.adl
< 00000010 32 2e 69 6e 74 65 72 6e 6f 64 65 2e 6f 6e 2e 6e # 2.internode.on.n
< 00000020 65 74 20 45 53 4d 54 50 0d 0a 32 32 30 20 45 53 # et ESMTP..220 ES
< 00000030 4d 54 50 3b 20 70 70 70 31 31 38 2d 32 30 38 2d # MTP; ppp118-208-
< 00000040 31 30 31 2d 31 37 30 2e 6c 6e 73 32 30 2e 62 6e # 101-170.lns20.bn
< 00000050 65 34 2e 69 6e 74 65 72 6e 6f 64 65 2e 6f 6e 2e # e4.internode.on.
< 00000060 6e 65 74 20 5b 31 31 38 2e 32 30 38 2e 31 30 31 # net [118.208.101
< 00000070 2e 31 37 30 5d 20 69 6e 20 4d 54 41 27 73 20 49 # .170] in MTA's I
< 00000080 4e 53 49 44 45 69 6e 74 65 72 6e 6f 64 65 3b 20 # NSIDEinternode;
< 00000090 64 72 69 76 69 6e 27 20 69 6e 74 6f 20 74 68 65 # drivin' into the
< 000000a0 20 73 75 6e 73 65 74 0d 0a # sunset..
> 00000000 48 45 4c 4f 20 6e 65 77 74 6f 6e 0a # HELO newton.
< 000000a9 32 35 30 20 69 70 6d 61 69 6c 30 37 2e 61 64 6c # 250 ipmail07.adl
< 000000b9 32 2e 69 6e 74 65 72 6e 6f 64 65 2e 6f 6e 2e 6e # 2.internode.on.n
< 000000c9 65 74 0d 0a # et..
> 0000000c 51 55 49 54 0a # QUIT.
< 000000cd 32 32 31 20 69 70 6d 61 69 6c 30 37 2e 61 64 6c # 221 ipmail07.adl
< 000000dd 32 2e 69 6e 74 65 72 6e 6f 64 65 2e 6f 6e 2e 6e # 2.internode.on.n
< 000000ed 65 74 0d 0a # et..
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:
Code:
< 00000000 43 4d 44 0d 0a # CMD..
< 00000005 73 68 6f 77 20 71 0d 0a 0d 0a 38 37 33 38 62 38 # show q....8738b8
< 00000015 2c 0d 0a 3c 32 2e 32 38 3e 20 # ,..<2.28>
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
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.
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
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
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.