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.

Build plecs file in python

0 votes
21 views
Hi,

Is it possible to create .elf file for a plecs model using python, instead of opening the model in plecs and using coder options?
asked Feb 19 by k123123 (12 points)

1 Answer

0 votes

Yes you can use an XML-RPC script that connects to the PLECS application. Assuming you are using PLECS Standalone, refer to the "XML-RPC Interface in PLECS Standalone" section of the PLECS documentation.  The XML-RPC command to generate code is plecs.codegen() and is separately mentioned in the "Code Generation" portion of the manual. The convention is plecs.codegen('path', optStruct, 'outputDir'), where path is a model name or a subsystem path. The parameters optStruct and outputDir are optional.

Below is an example script.  There are a few points to note.

  1. The *.plecs model must be opened first via the plecs.load('mdlFile') command.  'mdlFile' must be an absolute path to the model file.
  2. Code is generated by the plecs.codegen('path') where 'path' is the path to the desired subsystem.  Path is constructed by model_name/subsystem and model_name doesn't include the *.plecs extension.
import xmlrpc.client as xmlrpclib
import os

model_path = "C:/[path]/PLECS_RT_Box/demos/boost_converter/" #absolute path
model_name ="boost_converter_1rtbox"
subsystem_name = "Plant + Controller"
model_file = os.path.join(model_path,model_name+".plecs") 

server = xmlrpclib.Server("http://localhost:1080/RPC2")  

server.plecs.load(model_file) #absolute path
server.plecs.codegen(model_name+"/"+subsystem_name)

answered Feb 19 by Bryan Lieblick (474 points)
edited Feb 19 by Bryan Lieblick
...