Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
robotran
mbsysc
Commits
5f2aa527
Commit
5f2aa527
authored
Jan 13, 2021
by
Olivier Lantsoght
Browse files
[MBysPy] Add a function to read string from C adress that handles NULL adress.
parent
620700c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
MBsysC/mbs_interface/MBsysPy/mbs_utilities.py
View file @
5f2aa527
...
...
@@ -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.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment