osi-sensor-model-packaging icon indicating copy to clipboard operation
osi-sensor-model-packaging copied to clipboard

Get OSMPSensorViewIn binary variables in python

Open oskr1709 opened this issue 3 years ago • 0 comments

Describe the problem

I want to get OSMPSensorViewIn.base.lo , OSMPSensorViewIn.base.hi and OSMPSensorViewIn.base.size from the serialization:

bytes_buffer = sensorview.SerializeToString()
result = struct.pack("<L", len(bytes_buffer))

That is in order to be the input of an dummy sensor fmu.

Describe what you have already tried

I´m working with this example: https://opensimulationinterface.github.io/open-simulation-interface/ and then got the binary variables in this way:

OSMPSensorViewIn_base_lo = int.from_bytes(result, byteorder='little') OSMPSensorViewIn_base_hi = int.from_bytes(result, byteorder='big') OSMPSensorViewIn_size = len(bytes_buffer)

it gives me an error that the python int it too long for C long or it crashed in the OSMPDummySensor line: data.ParseFromArray(buffer,integer_vars[FMI_INTEGER_SENSORVIEW_IN_SIZE_IDX]);

Describe your research

As I mention, I tried with int.from_bytes (https://docs.python.org/3/library/stdtypes.html) and len of bytes buffer I have no found similar problem or approach in any other page.

Ask your question

So my basic question is, how do I Get OSMPSensorViewIn binary variables in python to set for dummy sensor fmu?

Does anybody know the correct procedure to do this in python please? @pmai could be possible to help me with this procedure please? Thanks in advance for your help

oskr1709 avatar Oct 28 '22 13:10 oskr1709