0
$\begingroup$

When using the Yaskawa Smart Pendant SDK API (Java client), it is possible to set multi-byte I/O values via:

controller.setOutputGroups(outNum, 2, value16bits);

controller.setOutputGroups(outNum, 4, value32bits);

However, sometimes the byte ordering is wrong. Depending on the product vendor or if using Ethernet/IP or IOLink, multi-byte values can be big-endian or little-endian.

How can I swap the ordering?

$\endgroup$
1
$\begingroup$

The API doesn't have any direct support for endian conversion / byte-swapping. However, there are some Java functions that can handle it:

Short.reverseBytes(short i16)
Integer.reverseBytes(int i32)
Long.reverseBytes(long i64)

So, the calls in the question would become:

controller.setOutputGroups(outNum, 2, Short.reverseBytes(value16bits));
controller.setOutputGroups(outNum, 4, Integer.reverseBytes(value32bits));
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.