I am trying to send a series of commands and read responses from a Microprocessor using and Telnet connection. The commands are sent to the microprocessor through a ethernet to serial connection passing through a Lantronix XPort (XP1001000-05R). The command I am using to test if the connection is working is *idn?, when sent using PuTTY the response is:
Flann 625-03V2 PVRA
Serial Number 000000
Hardware Version V1.0
System Version V1.0
Motor Version unknown
I’ve tried using socket:
import socket
TCP_IP = '10.1.5.126'
TCP_PORT = 10001
BUFFER_SIZE = 1024
MESSAGE = bytes("*IDN?"+"n", 'ansi')
#MESSAGE = "Hello, World!"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send(MESSAGE)
data = s.recv(BUFFER_SIZE)
s.close()
print ("received data:", data)
The response I get from the print is:
received data: b'xffxfbx01xffxfbx03xffxfa,j`xffxf0'
I’ve also tried using the telnet library:
import telnetlib
# Connect to the Telnet server
tn = telnetlib.Telnet("10.1.5.126", 10001)
# Send a command to the server
tn.write(b"*idn?n")
# Read the output from the server
output = tn.read_all()
# Print the output
print(output)
tn.close()
But this seems to get stuck on the output read.all line
Gareth Tanner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.