I am trying to connect to RT Box via XML RPC from Python. Please find the code below
import xmlrpclib
import socket
ip = socket.gethostbyname(‘rtbox-20b0f703a3f4’)
print (ip)
server=xmlrpclib.Server(“http://” + ip + “:1080/RPC2”)
with open(“C:Models/boost_converter_codegen/Plant.elf”, “rb”) as f:
print(“Uploading executable”)
print (server)
server.rtbox.start()
print (server)
server.rtbox.load(xmlrpclib.Binary(f.read()))
f.closed
print(“Starting executable”)
#print (server)
server.rtbox.start()
#print(f"IP Address: {ip_address}")
For the abovecode I get the error
“No connection could be made because the target machine actively refused it.”
Should I enable any port from the RT Box side to listen from host? Firewall is disabled .
Hi Hridhya,
The main issue I’m seeing with your code is that your TCP port is incorrect. The RT Box listens to XML-RPC connections on TCP port 9998. I made a few small fixes to your code. The following code should work.
import xmlrpclibimport socketip = socket.gethostbyname(‘rtbox-20b0f703a3f4.local.’)print (ip)server=xmlrpclib.Server(“http://” + ip + “:9998/RPC2”)with open(“C:Models/boost_converter_codegen/Plant.elf”, “rb”) as f: print(“Uploading executable”) server.rtbox.load(xmlrpclib.Binary(f.read()))f.closedprint(“Starting executable”)server.rtbox.start()print(“Real-time simulation running”)
Also, have you checked out the XML Scripting demo model? If you haven’t yet, I recommend you to do so. It is under Window > Demo Models > RT Box Demo Models > XML-RPC Scripting Interface. This demo model is pretty good at explaining this feature step by step, using a simple example.