SensorModbusMaster
SensorModbusMaster copied to clipboard
need Help for function CDAB to float32
Hey, i have used your lib for a long time. I was very happy with it. Now i am looking for a function for float to CDAB Mid-little endian. And other direction from CDAB Mid-little endian to float Can you tell me a small hint for adding this function?
You would need to add the middle endian type(s) to the endianness typedef and then modify the private "sliceArray" and "leFrameFromFrame" functions and use them appropriately to get the endianness right.
Unfortunately, I will not have time to add this feature myself, but I'm willing to review detailed pull requests.
I rewrite function sliceArray to combine float32 from CDAB It change default bigEndian to CDAB format
`
void modbusMaster::sliceArray(byte inputArray[], byte outputArray[],
int start_index, int numBytes, bool reverseOrder)
{
if (reverseOrder)
{
// Reverse the order of bytes to get from big-endian to little-endian
int j = numBytes - 1;
outputArray[j] = inputArray[start_index + 2];
outputArray[j-1] = inputArray[start_index + 3];
outputArray[j-2] = inputArray[start_index + 0];
outputArray[j-3] = inputArray[start_index + 1];
/*
//original code
for (int i = 0; i < numBytes; i++)
{
outputArray[i] = inputArray[start_index + j];
j--;
}
*/
}
`
@SRGDamia1, it's possible to get the raw registers and then do something like that with a union?
union {
uint16_t u[2];
float f = 0;
} vlnData;
modbus.getRegisters(0x03, 0x5000, 2); //reads two registers starting from 0x5000
vlnData.u[1] = responseBuffer[0]
vlnData.u[0] = responseBuffer[1];
float VoltageL1 = vlnData.f
I've tried this approach but i'm not understanding how to access properly the response buffer
There response buffer is public. You should be able to access it as modbusMaster::responseBuffer
.