It seems that Python does not support single precision floating point as a language specification, but since it was necessary to input and output the setting value of the hardware to which the script is linked with single precision fixed decimal point, convert it through NumPy. I made it.
For the time being, make a note so that you do not forget it.
Because it uses NumPy
import numpy
Assign each 4-byte float32 value (12 bytes in total) contained in the string s to the variable
nums = numpy.fromstring(s, dtype=float32, count=3) self.param1 = nums[0] self.param2 = nums[1] self.param3 = nums[2]
Outputs a total of 12 bytes from the float32 value (4 bytes each) 3 for the value contained in the variable.
params = numpy.array([self.param1, self.param2, self.param3], dtype=float32) return params.tostring()
Recommended Posts