MPC-325 SERIES OPERATION MANUAL – REV. 3.20F (20200303)
(Wintel), so conversion to 32-bit longs will require bit-order reversal (byte swapping) for
Big-Endian platforms (e.g., LabVIEW). The appropriate microstep-to-microns conversion
factor is needed according to the device type being moved (see
Microns/microsteps
conversion factors (multipliers)
table).
Little-Endian bit/byte order environment:
Signature
pos[x]
cpxus
cpyus
cpzus
Big-Endian bit/byte order environment (“pos” is in Little-Endian format):
pos[x]
cpxus
cpyus
cpzus
The following C/C++ code snippets can be used to process the streaming data.
Array for a streamed 12-byte block of data containing current position
unsigned char pos[12];
32-bit variables for current position in microsteps, all initialized to 0 to ensure MSB allows only
positive values
long cpxus, cpyus, cpzus;
cpxus = cpyus = cpzus = 0;
Copy 24-bit (3-byte) position for each axis to 32-bit (4-byte) equivalents. Use the byte position
offsets shown in the diagram above. (“le” means Little Endian; “be” means Big Endian bit/byte
order.)
If in Little-Endian environment (e.g., Windows, Intel-MacOSX), copy all 3 U24 bytes for each axis
to the respective U32 variables.
memcpy(&cpxus[1], &pos[3], 3); // X
memcpy(&cpyus[1], &pos[6], 3); // Y
memcpy(&cpzus[1], &pos[9], 3); // Z
If in Big-Endian environment (e.g., legacy MacOS, LabVIEW), copy U24 to U32 byte at a time (1
st
to 3
rd
, 2
nd
to 2
nd
, & 3
rd
to 1
st
). Note that “pos” is always in Little-Endian bit/byte order.
memcpy(&cpxus[2], &pos[3], 1); // X
memcpy(&cpxus[1], &pos[4], 1);
memcpy(&cpxus[0], &pos[5], 1);
memcpy(&cpyus[2], &pos[6], 1); // Y
memcpy(&cpyus[1], &pos[7], 1);
memcpy(&cpyus[0], &pos[8], 1);
memcpy(&cpzus[2], &pos[9], 1); // Z
memcpy(&cpzus[1], &pos[10], 1);
memcpy(&cpzus[0], &pos[11], 1);