Azzera filtri
Azzera filtri

how to output answer in elf file on jeston nano?

3 visualizzazioni (ultimi 30 giorni)
HSIU-YUN CHIEN
HSIU-YUN CHIEN il 24 Feb 2021
Risposto: Infinite_king il 8 Mag 2024
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?

Risposte (1)

Infinite_king
Infinite_king il 8 Mag 2024
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.

Categorie

Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by