# PDU (protocol data unit)

This is the central part of packets exchanged in S7-Communication. A PDU cosists of:
- A 10 or 12 byte header
- A parameter area
- A data area
Header:

Position | meaning | possible values
--- | --- | ---
0 | allways 0x32
1 | type | 1,2,3 or 7
2,3 | unknown | 0
4,5 | sequence number |
6,7 | length of parameters |
8,9 | length of data |
10,11 | error code |

Parameters:

Position | meaning | possible values
--- | --- | ---
0 | a function number
rest | depends on function number |

Data:

Position | meaning | possible values
--- | --- | ---
rest | depends on function number |

Parameters for read request:

Position | meaning | possible values
--- | --- | ---
0 | function number for read | 4
1 | number of items to read | 1..20
2.. | item adresses, 12 byte each |

Forming the item address:

Position | meaning | possible values
--- | --- | ---
0,1,2 | unknown | allways 0x12, 0x0a, 0x10
3 | transport size or unit size | 1=single bit, 2=byte, 4=word
4,5 | length in byte |
6,7 | number of data block | 0 for ares other than data block
8 | area code | see area
9,10,11 | Start address in bits. | multiples of 8, if unit size is not bits

read response:

Position | meaning | possible values
--- | --- | ---
0 | function number for read | 4
1 | number read items | 1..20
2.. | items, 4 byte "data header" +data each |

Data header:

Position | meaning | possible values
--- | --- | ---
0 | return code | 0xFF means ok, data follows after this header. Other codes give reasons why no data is returned.
1 | transport size or unit size | 4=single bit, 9=byte
2,3 | length in bits |