From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Possible bug in ToLittleEndian32 in CVI 2009

Solved!
Go to solution

Hello,

 

I ran the following sample code:

 

//////////////////////////

OutboundMsg.Header.Msg_ID = ToBigEndian32(FOO_MSG_ID);

 

DebugPrintf(“FOO_MSG_ID:        %d”,   FOO_MSG_ID);

DebugPrintf(“NATIVE:            %08X”, FOO_MSG_ID);

DebugPrintf(“BIG ENDIAN:        %08X”, OutboundMsg.Header.Msg_ID);

DebugPrintf(“LITTLE ENDIAN:     %08X”, ToLittleEndian32(OutboundMsg.Header.Msg_ID));

DebugPrintf(“LITTLE ENDIAN???   %08X”, ToBigEndian32(OutboundMsg.Header.Msg_ID));

///////////////////////////////

 

And here is the output:

 

FOO_MSG_ID:           30

NATIVE:               0000001E

BIG ENDIAN:           1E000000

LITTLE ENDIAN:        1E000000

LITTLE ENDIAN???      0000001E

 

The line in red shows that the call to ToLittleEndian32 did no byte swapping.  Instead, only ToBigEndian32 actually did any byte swapping.  CVI says that a failed call to these endian functions will return 0.  It should not return exactly what was passed into it, as I’m seeing here. 

 

Or am I missing something?

 

Thanks!

Tim O'Leary

0 Kudos
Message 1 of 2
(2,718 Views)
Solution
Accepted by topic author jtocwru

Functions dealing for endianness are located in toolbox instrument, whose code is distributed so you can check them by yourself.

 

As you can see here:

unsigned int CVIFUNC ToLittleEndian32(unsigned int n)
{
    if (HostIsLittleEndian())
        return n;
    return ToOtherEndian32(n);
}

 the function tests for system endianness and returns original number if the system is already little endian, which appears to be your case. This appears a correct behaviour to me.

The only condition for returning 0 is that ToOtherEndian32 () cannot discriminate system endianness; in every other case a number is returned.

 

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 2
(2,713 Views)