5.2 - DIO [U12 Datasheet] | LabJack

# 5.2 - DIO [U12 Datasheet]

This commands reads the direction and state of all the digital I/O. If Update Digital = 1, this function also sets the directions and states before reading.

Table 5.2-1.

 Command Byte # Description 0 Bits for D15 through D8 Direction ( 0 = Output, 1 = Input) 1 Bits for D7 through D0 Direction ( 0 = Output, 1 = Input) 2 Bits for D15 through D8 State ( 0 = Low, 1 = High) 3 Bits for D7 through D0 State ( 0 = Low, 1 = High) 4 Bits 7-4: Bits for IO3 through IO0 Direction Bits 3-0: Bits for IO3 through IO0 State 5 01X10111 (DIO) 6 Bits 7-1: XXXXXXX Bit 0: Update Digital 7 XXXXXXXX Response Byte # Description 0 01X10111 (DIO Response) 1 Bits for D15 through D8 State ( 0 = Low, 1 = High) 2 Bits for D7 through D0 State ( 0 = Low, 1 = High) 3 Bits 7-4: Bits for IO3 through IO0 State Bits 3-0: XXXX 4 Bits for D15 through D8 Direction ( 0 = Output, 1 = Input) 5 Bits for D7 through D0 Direction ( 0 = Output, 1 = Input) 6 Bits for D15 through D8 Output Latch States 7 Bits for D7 through D0 Output Latch States

## LabJackPython Example

```  ```
>>> import u12
>>> d = u12.U12(debug=True)
open called
Writing: [0x0, 0x0, 0x0, 0x0, 0x0, 0x57, 0x0, 0x0]
Received: [0x57, 0x0, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0]
>>> d.rawDIO()
Writing: [0x0, 0x0, 0x0, 0x0, 0x0, 0x57, 0x0, 0x0]
Received: [0x57, 0x0, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0]
{
'D7toD0States':
<BitField object: [ D7 = Low (0), D6 = Low (0),
D5 = Low (0), D4 = Low (0),
D3 = Low (0), D2 = Low (0),
D1 = Low (0), D0 = Low (0) ] >,
'IO3toIO0States':
<BitField object: [ IO3 = Low (0), IO2 = Low (0),
IO1 = Low (0), IO0 = Low (0) ] >,
'D15toD8Directions':
<BitField object: [ D15 = Input (1), D14 = Input (1),
D13 = Input (1), D12 = Input (1),
D11 = Input (1), D10 = Input (1),
D9 = Input (1), D8 = Input (1) ] >,
'D7toD0OutputLatchStates':
<BitField object: [ D7 = 0 (0), D6 = 0 (0),
D5 = 0 (0), D4 = 0 (0),
D3 = 0 (0), D2 = 0 (0),
D1 = 0 (0), D0 = 0 (0) ] >,
'D15toD8OutputLatchStates':
<BitField object: [ D15 = 0 (0), D14 = 0 (0),
D13 = 0 (0), D12 = 0 (0),
D11 = 0 (0), D10 = 0 (0),
D9 = 0 (0), D8 = 0 (0) ] >,
'D15toD8States':
<BitField object: [ D15 = Low (0), D14 = Low (0),
D13 = Low (0), D12 = Low (0),
D11 = Low (0), D10 = Low (0),
D9 = Low (0), D8 = Low (0) ] >,
'D7toD0Directions':
<BitField object: [ D7 = Input (1), D6 = Input (1),
D5 = Input (1), D4 = Input (1),
D3 = Input (1), D2 = Input (1),
D1 = Input (1), D0 = Input (1) ] >
}
```
```

### So can we have an example of

So can we have an example of setting a bit high?

### How about the following to

How about the following to set IO0 to output-high and everything else to input:

[0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0x57, 0x01, 0x00]

Note that the U12 does not have a mask feature.  If you are going to update the state or direction of anything you have to do all, so masking must be handled at higher software layers by tracking the current conditions so you can send a command where you leave everything in the current condition except what you want to change.

### Hi, I understand that I have

Hi, I understand that I have to read all states and directions before I can change single bits, having to mask with the previous read. But where do I read the IO3~0 direction bits?

### It is not possible to read

It is not possible to read that from the hardware.  Those 4 digital I/O are on a different chip, and with that chip there is no way to read back the output states or directions.  That is why the function above reads everything for D lines (direction, input states, output states), but for IO lines can only read the input states.

So the only option with the IO lines is to set them to some condition at the beginning of your program and then keep track of their current condition in software.