I am trying to query the status from an audio device using the telnetlib in python.
When I send command strings to the device via python script, it responds appropriately (changes inputs, volume, etc).
I am attempting to query the device status by sending the appropriate string, and even though the device responds to the command, I can not seem to get python to show it to me.
(I know the device is responding because the software provided by the mfg has a network monitor window that shows 48 lines from the device upon executing my python script.)
My test program is as follows:
from telnetlib import Telnet
import time
host = "xxx.xxx.xxx.xxx"
port = "####"
timeout = 5
#Status Request
command = [0x01,0x00,0x00,0x00,0x15,0xED,0xAE,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x01,0x19,0x00,0x01]
tn = Telnet(host, port, timeout)
with tn as session:
for byt in command:
byt = byt.to_bytes(1,'big')
session.write(byt)
print(byt) #for testing
time.sleep(1) #thought this might help - it didn't.
try:
while True:
rsp = session.read_until(b'0xF0', timeout=0.1)
if rsp == b'': #if nothing
print("No Data Found")
break
print(rsp)
except EOFError:
print('connection closed')
exit()
The above code prints: "No Data Found" while connected to the device.
I have tried other read options such as read_very_eager(), read_all(), etc, but the result is always the same - blank. I've tried closing the mfg's application, I just can't seem to get it.
Am I "reading" at the wrong time? Is the data already "gone" before I'm reading it?
Help would be much appreciated!
Thank you.
UPDATED MY SCRIPT TO USE SOCKETS... The messages are being received by the device (I am using the device software's network monitor to confirm) but there still appears to be no response that I can pull down with my script.
import socket
import time
host = "xxx.xxx.xxx.xxx"
port = xxxx
timeout = 5
#Request Info Command
command = [0x01,0x00,0x00,0x00,0x15,0xED,0xAE,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x01,0x19,0x00,0x01]
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host,port))
for byt in command:
byt = byt.to_bytes(1,'big')
s.sendall(byt)
print(byt) #for testing
response = b''
try:
while True:
rsp = s.recv(4096)
if not rsp:
print("No Data Found") #this never prints
break
response += rsp
print(rsp) #put this here just to see if I'd see anything.
except socket.timeout:
print("Timed Out")
print(response.decode())
exit()
Also adding a screenshot of the "Network Trace" window from the manufacturer's software. All of the lines below the highlighted line appear upon executing my Python script requesting info from the device
I also put "response += rsp" into an if statement so it would break if no data was received.. it breaks.
if rsp:
response += rsp
else:
break
On another note, I copied a TCP message block from Wireshark and asked BARD if it could analyze it (just for fun) and it responded that "The data you provided is a TCP packet capture. It is a binary file that contains data that was exchanged between two computers over a network... The payload in this packet capture is a HTTP request. The request is for a file called /zones.xml from the server www.example.com. "
Assuming Bard is not totally making things up, I find it interesting that it "found" "zones.xml" - I have found no nothing in the documentation referring to any xml files, but it is a "zone mixer" and it would make sense that the information about each "zone" would be in a file called "zones.xml." I do not believe, however, that the device I'm trying to query would make reference to "www.example.com" so I think Bard may have hallucinated that. Either way, I still can't get Python to find any available bytes :-(