how to output answer in elf file on jeston nano?
조회 수: 2 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 AI for Signals에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!