ReadArea

Description

This is the main function to read data from a PLC.
With it you can read DB, Inputs, Outputs, Merkers, Timers and Counters.

Declaration

int ReadArea(int Area, uint16_t DBNumber, uint16_t Start,
   
uint16_t Amount, void *pUsrData);

 

Parameters

 

Type

Dir.

Mean

Area

int

In

Area identifier.

DBNumber

uint16_t

In

DB Number if  Area = S7AreaDB, otherwise is ignored.

Start

uint16_t

In

Offset to start

Amount

uint16_t

In

Amount of words to read (1)

pUsrData

Pointer to memory area

In

Address of user buffer. (see remarks)

 

(1)   Note the use of the parameter name “amount”, it means quantity of words, not byte size.

Area table

 

Value

Mean

S7AreaPE

0x81

Process Inputs.

S7AreaPA

0x82

Process Outputs.

S7AreaMK

0x83

Merkers.

S7AreaDB

0x84

DB

S7AreaCT

0x1C

Counters.

S7AreaTM

0x1D

Timers

 

Return value

·         0 : The function was accomplished with no errors.

·         Other values : see the Errors Code List. 

Remarks

As said, every data packet exchanged with a PLC must fit in a PDU, whose size is fixed and is 240 bytes for this implementation of Settimino.

If this data size exceeds the PDU size, the packet is automatically split across more subsequent transfers and your buffer should be large enough to receive the data.

If NULL is passed as pUsrData, the data remains into the PDU buffer and the size requested is trimmed to the max (222 bytes).

This allow to save memory avoiding to supply a further memory buffer if you plan to make only small data transfers.

The parameter Amount is not the size in bytes.

Particularly:

Buffer size (byte) = Word size * Amount

Where:

 

Word size

(E/A/M/DB) - Byte

1

Counter

2

Timer

2