5.1 - General Protocol [U3 Datasheet] | LabJack

# 5.1 - General Protocol [U3 Datasheet]

Following is a description of the general U3 low-level communication protocol. There are two types of commands:

Normal: 1 command word plus 0-7 data words.

Extended: 3 command words plus 0-125 data words.

Normal commands have a smaller packet size and can be faster in some situations. Extended commands provide more commands, better error detection, and a larger maximum data payload.

Table 5.1-1. Normal command format

 Byte 0 Checksum8: Includes bytes 1-15 1 Command Byte: DCCCCWWW Bit 7: Destination Bit: 0 = Local, 1 = Remote. Bits 6-3: Normal command number (0-14). Bits 2-0: Number of data words. 2-15 Data words.

Table 5.1-2. Extended command format:

 Byte 0 Checksum8: Includes bytes 1-5 1 Command Byte: D1111WWW Bit 7: Destination Bit: 0 = Local, 1 = Remote. Bits 6-3: 1111 specifies that this is an extended command Bits 2-0: Used with some commands. 2 Number of data words. 3 Extended command number. 4 Checksum16 (LSB) 5 Checksum16 (MSB) 6-255 Data words.

Checksum calculations:

All checksums are a “1’s complement checksum”. Both the 8-bit and 16-bit checksum are unsigned. Sum all applicable bytes in an accumulator, 1 at a time. Each time another byte is added, check for overflow (carry bit), and if true add one to the accumulator.

In a high-level language, do the following for the 8-bit normal command checksum:

1. Get the subarray consisting of bytes 1 and up.
2. Convert bytes to U16 and sum into a U16 accumulator.
3. Divide by 28 and sum the quotient and remainder.
4. Divide by 28 and sum the quotient and remainder.

In a high-level language, do the following for an extended command 16-bit checksum:

1. Get the subarray consisting of bytes 6 and up.
2. Convert bytes to U16 and sum into a U16 accumulator (can’t overflow).

Then do the following for the 8-bit extended checksum:

1. Get the subarray consisting of bytes 1 through 5.
2. Convert bytes to U16 and sum into a U16 accumulator.
3. Divide by 28 and sum the quotient and remainder.
4. Divide by 28 and sum the quotient and remainder.

Destination bit:

This bit specifies whether the command is destined for the local or remote target. This bit is ignored on the U3.

Multi-byte parameters:

In the following function definitions there are various multi-byte parameters. The least significant byte of the parameter will always be found at the lowest byte number. For instance, bytes 10 through 13 of CommConfig are the IP address which is 4 bytes long. Byte 10 is the least significant byte (LSB), and byte 13 is the most significant byte (MSB).

Some functions have mask parameters. The WriteMask found in some functions specifies which parameters are to be written. If a bit is 1, that parameter will be updated with the new passed value. If a bit is 0, the parameter is not changed and only a read is performed.

The AINMask found in some functions specifies which analog inputs are acquired. This is a 16-bit parameter where each bit corresponds to AIN0-AIN15. If a bit is 1, that channel will be acquired.

The digital I/O masks, such as FIOMask, specify that the passed value for direction and state are updated if a bit 1. If a bit of the mask is 0 only a read is performed on that bit of I/O.

Binary Encoded Parameters:

Many parameters in the following functions use specific bits within a single integer parameter to write/read specific information. In particular, most digital I/O parameters contain the information for each bit of I/O in one integer, where each bit of I/O corresponds to the same bit in the parameter (e.g. the direction of FIO0 is set in bit 0 of parameter FIODir). For instance, in the function ControlConfig, the parameter FIODir is a single byte (8 bits) that writes/reads the direction of each of the 8 FIO lines:

• if FIODir is 0, all FIO lines are input,
• if FIODir is 1 (20), FIO0 is output, FIO1-FIO7 are input,
• if FIODir is 5 (20 + 22), FIO0 and FIO2 are output, all other FIO lines are input,
• if FIODir is 255 (20 + … + 27), FIO0-FIO7 are output.

### normal lenght field of extended commands

What should the normal length field (byte 1, bits 0-2) be set to in an extended command?

### Re: normal length field of extended commands

There was a mistake in the table. Byte 1, bits 0-2 should read "Used in some commands". The section for each of the extended commands will tell you what that byte should be set to. For example, in ConfigU3 (Section 5.2.2) the byte should be 0xF8.

The table has been corrected.

### For the Extended Format field

For the Extended Format field Checksum8 (Byte 0), I believe the table should indicate "Includes bytes 1-5."

You are correct.

### For the Normal command format

For the Normal command format byte 1, the docs above indicated D bit is indicated as ignored on U3 but the StreamStart and StreamStop command byte specify this bit as set (0xA8 and 0xB0 respectively). It seems this bit isn't ignored and maybe should be specified as a C bit...?

### The destination bit only has

The destination bit only has meaning on the UE9 where there is more than one processor that may need to execute to the command. The U3 assumes that all commands are for its one processor, so the state of the destination bit is ignored.