Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

No connection could be made because the target machine actively refused it

0 votes
51 views
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 .
asked May 4 by Hridhya (16 points)

1 Answer

+1 vote

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 xmlrpclib
import socket
ip = 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.closed
print("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.

answered May 13 by Manu Parimi (187 points)
...