i got a program which needs to send a byte array via a serial communication. And I got no clue how one can make such a thing in python. I found a c/c++/java function which creates the needed byte array:
byte[] floatArrayToByteArray(float[] input)
{
int len = 4*input.length;
int index=0;
byte[] b = new byte[4];
byte[] out = new byte[len];
ByteBuffer buf = ByteBuffer.wrap(b);
for(int i=0;i<input.length;i++)
{
buf.position(0);
buf.putFloat(input[i]);
for(int j=0;j<4;j++) out[j+i*4]=b[3-j];
}
return out;
}
but how can I translate that to python code. edit: the serial data is send to a device. where I can not change the firmware. thanks