Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncated data as the result of getBinary ? #733

Open
filip-42 opened this issue Jan 20, 2025 · 2 comments
Open

Truncated data as the result of getBinary ? #733

filip-42 opened this issue Jan 20, 2025 · 2 comments
Labels

Comments

@filip-42
Copy link

Hi,

I'm using the function getBinary to obtain array data which is represented as uint8_t* in my C-Code. The data of length 8 bytes may contain several zeros at varying indices within this array, e.g. 01 02 03 04 00 06 00 08.

Reading out this data using getBinary yields an instance of class 'bytes' with the data content of 01 02 03 04. Playing around with the position of the zero entries, it seems that the data is truncated before the first occurrence of a zero entry - as I would expect in a zero-terminated string setting.

Indeed, according to the sources of fmi3.py, FMPy uses c_char_p for C-Function to Python binary data passing which is correct for passing a string, but not for a data buffer which may contain several zeros inbetween.

Is this an implementation issue of FMPy or did I miss relevant parts of the FMI 3 specification ?

Thank you in advance.

Best regards
Philippe

@t-sommer
Copy link
Contributor

Can you share an FMU to reproduce the problem?

@t-sommer t-sommer added the bug label Jan 20, 2025
@filip-42
Copy link
Author

Hi Torsten,

thank you for your quick reply. In the binaryTest zip attached, you can find the C-sources that contain the corresponding binary setter and getter methods. Furthermore, you can find an FMU revealing the above mentioned problem. The FMU consists of a binary input and a binary output, where the binary data for the binary output is created on-the-fly in the FMU. And finally, I attached a pyhon script, that sets binary data and gets binary data afterwards.
Setting binary data seems to work, where getting binary data using FMPy seems to be broken. In the example, 8 bytes should be read, but only 5 bytes are returned.
The FMU is compiled on a Windows OS with FMPy version: 0.3.21 installed.

Thank you and best regards
Philippe

testBinary.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants