We use status bytes on the RevPi devices to enter multiple functions or information at a defined place in the process image . Status bytes can be read as well as written. Since a byte has eight bits, eight information digits – the so-called status bits – can be included.
Status bytes are read from right to left and the count starts at zero.
You read or write status bytes on the RevPi not in binary but in decimal format. So you have to convert binary to decimal and vice versa.
Mapping of bit and decimal value
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Decimal value |
27=128 |
26=64 |
25=32 |
24=16 |
23=8 |
22=4 |
21=2 |
20=1 |
Examples:
Binary number if bit 1 is set: 00000010
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Binary number |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
Binary number if bit 1 and bit 6 are set: 01000010
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Binary number |
0 |
1 |
0 |
0 |
0 |
0 |
1 |
0 |
Conversion to decimal number if bit 1 and bit 6 are set:
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Binary number |
0 |
1 |
0 |
0 |
0 |
0 |
1 |
0 |
Decimal value |
|
64 |
|
|
|
|
2 |
|
Decimal number |
64 + 2 = 66 |
Tip:
The Windows calculator easily converts binary and decimal numbers. Select “Programmer” in the settings of the calculator.
Example: Writing a status byte on the RevPi Connect
The RevPiLED status byte of the RevPi Connect controls the three LEDs, the watchdog and the relay contact. Bit 0 controls the green LED A1, bit 1 the red LED A1 and so on. Bit 6 controls the relay contact and bit 7 controls the watchdog.
If the LED A1 should light red and the relay contact should be open, you set bit 1 and bit 6 each to 1 (01000010 = 64+2=66) using piTest with the command piTest -w RevPiLED,66
.
Example: Reading a status byte on the RevPi Connect
The status byte RevPiStatus of the RevPi Connect contains some information about the process image. Bit 1, for example, indicates whether an I/O module is connected to the base module.
Using piTest you read the corresponding status byte with the command piTest -r RevPiStatus
.
If piTest outputs the number 3, this corresponds to the binary number 0000 0011 (2+1 = 3). This implies that, bit 1 is set and thus an I/O module is connected.