Commit 5f2aa527 authored by Olivier Lantsoght's avatar Olivier Lantsoght
Browse files

[MBysPy] Add a function to read string from C adress that handles NULL adress.

parent 620700c2
......@@ -7,11 +7,11 @@ Summary
Defines the functions that are not specific to a MBS analysis.
Modify the C libraries to get a python compatible behavior.
"""
# MBsysC version : 1.13.0
# Author : Robotran Team
# (c) Universite catholique de Louvain, 2019
from __future__ import print_function
import ctypes
import numpy as np
# importing libraries
......@@ -72,6 +72,31 @@ def str_to_bytes(message):
return message
def str_from_c_pointer(address, default_name=None):
"""Read the string at the provided address.
If the address is 'NULL' ('None' in Python), the default name is returned.
Parameters
----------
address : int
Value of the address.
default_name : str, optional
The default name to return if the adress is invalid (None).
The default is None.
Returns
-------
str
The string at the address, or the default name.
"""
if address is not None:
return bytes_to_str(ctypes.string_at(address))
else:
return str(default_name)
def set_output(value, label):
"""Save a value during time integration.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment