how to output answer in elf file on jeston nano?
    5 次查看(过去 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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

