Made a test script in Python3 that connects to FG, sets a property and reads it. Might be something to start from:
- Code: Select all
import telnetlib
HOST="localhost"
PORT=5401
eol="\r\n".encode('ascii') #EOL characters
tn=telnetlib.Telnet(HOST, PORT)
tn.write(eol) #Gets telnet prompt
tn.write("set /tmp/test 1".encode('ascii')+eol) #Sets a propery
tn.read_until(eol) #Reads and discards reply
tn.write("get /ai/models/count".encode('ascii')+eol) #Gets a property
#Reads gotten reply strips EOL and splits into list
got=tn.read_until(eol).decode('ascii').strip().split()
print(" ".join(got[1:4])) #Prints property = value
tn.write("quit".encode('ascii')+eol) #Shuts down FG telnet conection
All the encode('ascii') are because Python3 uses unicode as string standard and telnet ascii.
wil wrote:reading other forums posts that said there were problems when interfacing arduino and flight gear directly on serial
Could you be more specific? Bidirectional serial
does not work but are there problems using serial for only inputs as you plan? Avoiding the middle man (snake) and two different communication protocols would be better if possible IMO.
* Edited as I found two bugs in the code.