how to output answer in elf file on jeston nano?

2 ビュー (過去 30 日間)
HSIU-YUN CHIEN
HSIU-YUN CHIEN 2021 年 2 月 24 日
回答済み: Infinite_king 2024 年 5 月 8 日
i use gpu coder write an function to elf file on jeston nano like:
function answer=test1()
tic
a=3;
b=1;
answer = a+b;
toc
end
i want use python to call .elf file and transfer data
How can I return the value of 'answer' back to the python program?

回答 (1 件)

Infinite_king
Infinite_king 2024 年 5 月 8 日
Hi HSIU-YUN CHIEN,
You can use Python's 'subprocess' library to call executables and capture their output. See the template code below,
import subprocess
def run_elf_file(elf_file_path):
try:
# Run the ELF file using subprocess
process = subprocess.Popen(
elf_file_path,
stdout=subprocess.PIPE, # Redirect standard output
stderr=subprocess.PIPE # Redirect standard error
)
# Capture the output and error streams
stdout, stderr = process.communicate()
# Decode the output and error from bytes to string
stdout = stdout.decode('utf-8')
stderr = stderr.decode('utf-8')
# Check the return code to see if the process succeeded
return_code = process.returncode
# Output results
print("Return code:", return_code)
print("Standard Output:\n", stdout)
print("Standard Error:\n", stderr)
except Exception as e:
print("caught exception - ")
print(e)
# Specify the path to the ELF file you want to run
elf_file_path = "/home/user1/Project Data/python testing/test1.elf"
# Run the ELF file and output the results
run_elf_file(elf_file_path)
The output was stored in 'stdout', and the string can be parsed to extract the required information
Refer the following resource to learn more about 'subprocess' library - https://docs.python.org/3/library/subprocess.html
Hope this is helpful.

カテゴリ

Help Center および File ExchangeAI for Signals についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by