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

need Help for function CDAB to float32 #7

Open
c0zm0z opened this issue Sep 3, 2018 · 4 comments
Open

need Help for function CDAB to float32 #7

c0zm0z opened this issue Sep 3, 2018 · 4 comments

Comments

@c0zm0z
Copy link

c0zm0z commented Sep 3, 2018

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?

@c0zm0z c0zm0z changed the title need Help need Help for function CDAB to float32 Sep 3, 2018
@SRGDamia1
Copy link
Contributor

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.

@lthquy
Copy link

lthquy commented Feb 28, 2021

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--;
}
*/

}

`

@rtu-dataframe
Copy link

@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

@SRGDamia1
Copy link
Contributor

There response buffer is public. You should be able to access it as modbusMaster::responseBuffer.

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

No branches or pull requests

4 participants