DeviceProxy returns float values with wrong byte order
Tango 9.4.1 is compiled on macOS Ventura 13.2 on machine with Apple M1 Pro for both arm64 and x86 using llvm 15.0.7-arm64 and llvm 15.0.7-x86 (via rosetta2).
At Forschungszentrum Jüllich we control our instruments using Tango. Let's assume there is a device with some attribute with some value. I can verify the value because I have physical access to the device. Let's assume I query DeviceProxy::value and this is what I get via x86- and arm64-compiled libraries:
x86 | arm64 | |
---|---|---|
value | 1.54837e-05 | 7.35095e-28 |
byte order | BF 1E 4D 3A 60 3C F0 3E | 60 3C F0 3E BF 1E 4D 3A |
The value obtained for x86 is the true value. The value obtained for arm64 is wrong, but if you output obtained value of type double as byte array you may notice that it is only the sequence of bytes what makes it wrong. String and int value types resulted correctly.
More details. main.cpp:
#include <iostream>
#include <tango/tango.h>
using namespace std;
using namespace Tango;
int main()
{
try {
DeviceProxy *device = new DeviceProxy("tango://tangohost:10000/box/pumps/pump1");
DeviceAttribute att_reply;
att_reply = device->read_attribute("value");
double spr;
att_reply >> spr;
cout << spr << endl;
unsigned char * bytes = (unsigned char *) & spr;
int i;
for (i = 0; i < sizeof (double); i++) {
printf ("%02X ", bytes[i]);
}
printf ("\n");
}
catch (DevFailed &e)
{
Except::print_exception(e);
exit(-1);
}
return 0;
}
CmakeLists.txt for x86:
cmake_minimum_required(VERSION 3.5)
project(untitled LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Paths
set(TANGO_PATH "/Users/kk/my_builds/tango/9.4.1/x86-llvm15")
set(OMNI_PATH "/Users/kk/my_builds/omniORB/4.2.5/x86-llvm15")
set(ZMQ_PATH "/usr/local/Cellar/zeromq/4.3.4")
set(CPPZMQ_PATH "/usr/local/Cellar/cppzmq/4.9.0")
# Libs
find_library(TANGO_LIBRARY NAMES tango PATHS ${TANGO_PATH}/lib NO_DEFAULT_PATH)
find_library(OMNIORB4_LIBRARY NAMES omniORB4 PATHS ${OMNI_PATH}/lib NO_DEFAULT_PATH)
find_library(OMNITHREAD_LIBRARY NAMES omnithread PATHS ${OMNI_PATH}/lib NO_DEFAULT_PATH)
find_library(COS4_LIBRARY NAMES COS4 PATHS ${OMNI_PATH}/lib NO_DEFAULT_PATH)
find_library(OMNIDYNAMIC4_LIBRARY NAMES omniDynamic4 PATHS ${OMNI_PATH}/lib NO_DEFAULT_PATH)
find_library(ZMQ_LIBRARY NAMES zmq PATHS ${ZMQ_PATH}/lib NO_DEFAULT_PATH)
# Includes
include_directories(${TANGO_PATH}/include)
include_directories(${OMNI_PATH}/include)
include_directories(${ZMQ_PATH}/include)
include_directories(${CPPZMQ_PATH}/include)
add_executable(untitled main.cpp)
target_link_libraries(untitled ${TANGO_LIBRARY} ${OMNIORB4_LIBRARY} ${OMNITHREAD_LIBRARY} ${COS4_LIBRARY} ${OMNIDYNAMIC4_LIBRARY} ${ZMQ_LIBRARY})
install(TARGETS untitled
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
CmakeLists.txt for arm64:
cmake_minimum_required(VERSION 3.5)
project(untitled LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Paths
set(TANGO_PATH "/Users/kk/my_builds/tango/9.4.1/arm64-llvm15")
set(OMNI_PATH "/Users/kk/my_builds/omniORB/4.2.5/arm64-llvm15")
set(ZMQ_PATH "/opt/homebrew/Cellar/zeromq/4.3.4")
set(CPPZMQ_PATH "/opt/homebrew/Cellar/cppzmq/4.9.0")
# Libs
find_library(TANGO_LIBRARY NAMES tango PATHS ${TANGO_PATH}/lib NO_DEFAULT_PATH)
find_library(OMNIORB4_LIBRARY NAMES omniORB4 PATHS ${OMNI_PATH}/lib NO_DEFAULT_PATH)
find_library(OMNITHREAD_LIBRARY NAMES omnithread PATHS ${OMNI_PATH}/lib NO_DEFAULT_PATH)
find_library(COS4_LIBRARY NAMES COS4 PATHS ${OMNI_PATH}/lib NO_DEFAULT_PATH)
find_library(OMNIDYNAMIC4_LIBRARY NAMES omniDynamic4 PATHS ${OMNI_PATH}/lib NO_DEFAULT_PATH)
find_library(ZMQ_LIBRARY NAMES zmq PATHS ${ZMQ_PATH}/lib NO_DEFAULT_PATH)
# Includes
include_directories(${TANGO_PATH}/include)
include_directories(${OMNI_PATH}/include)
include_directories(${ZMQ_PATH}/include)
include_directories(${CPPZMQ_PATH}/include)
add_executable(untitled main.cpp)
target_link_libraries(untitled ${TANGO_LIBRARY} ${OMNIORB4_LIBRARY} ${OMNITHREAD_LIBRARY} ${COS4_LIBRARY} ${OMNIDYNAMIC4_LIBRARY} ${ZMQ_LIBRARY})
install(TARGETS untitled
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
Resulted binary has these library dependencies for x86:
otool -L untitled
untitled:
@rpath/libtango.94.dylib (compatibility version 94.0.0, current version 9.4.1)
/Users/kk/my_builds/omniORB/4.2.5/x86-llvm15/lib/libomniORB4.2.5.dylib (compatibility version 0.0.0, current version 0.0.0)
/Users/kk/my_builds/omniORB/4.2.5/x86-llvm15/lib/libomnithread.4.1.dylib (compatibility version 0.0.0, current version 0.0.0)
/Users/kk/my_builds/omniORB/4.2.5/x86-llvm15/lib/libCOS4.2.5.dylib (compatibility version 0.0.0, current version 0.0.0)
/Users/kk/my_builds/omniORB/4.2.5/x86-llvm15/lib/libomniDynamic4.2.5.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/local/opt/zeromq/lib/libzmq.5.dylib (compatibility version 8.0.0, current version 8.4.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.36.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
And for arm64:
otool -L untitled
untitled:
@rpath/libtango.94.dylib (compatibility version 94.0.0, current version 9.4.1)
/Users/kk/my_builds/omniORB/4.2.5/arm64-llvm15/lib/libomniORB4.2.5.dylib (compatibility version 0.0.0, current version 0.0.0)
/Users/kk/my_builds/omniORB/4.2.5/arm64-llvm15/lib/libomnithread.4.1.dylib (compatibility version 0.0.0, current version 0.0.0)
/Users/kk/my_builds/omniORB/4.2.5/arm64-llvm15/lib/libCOS4.2.5.dylib (compatibility version 0.0.0, current version 0.0.0)
/Users/kk/my_builds/omniORB/4.2.5/arm64-llvm15/lib/libomniDynamic4.2.5.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/homebrew/opt/zeromq/lib/libzmq.5.dylib (compatibility version 8.0.0, current version 8.4.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.36.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)