General information on data types

Một phần của tài liệu Hans berger automating with SIMATIC s7 1200 configuring programming (Trang 93 - 96)

4.3.1 Overview of data types

Data types define the properties of tags, basically the representation of the contents and the permissible ranges. STEP 7 provides predefined data types. The data types are globally available and can be used in any block. A distinction is made between:

b Elementary data types which are predefined and can have a width of up to one long word (64 bits)

b Structured data types, comprising a combination of elementary data types b Parameter types for transfer of block parameters to functions and

function blocks

b PLC data types whose structure is defined by the user,

b System data types with a fixed structure and defined in STEP 7, and b Hardware data types defined by the hardware configuration

When linking tags, e.g. when comparing or adding, or when supplying block parameters, the tags involved must have the same or a comparable data type. The block attribute IEC check governs the test for a comparable data type: If it is acti- vated, the test is stricter. The block attribute Optimized block access can also play a Table 4.2 Assignment of the AREA and DBNUMBER parameters

Operand area Assignment of the AREA parameter

Assignment of the DBNUMBER parameter

Inputs B#16#81 0

Outputs B#16#82 0

Bit memory B#16#83 0

Data B#16#84 Data block number

role in the application of data types. Further details can be found in the section

“Attributes” on page 129 of Chapter 5.3.2 “Editing block properties”.

The data types of tags can be converted. This may happen automatically with the implicit data type conversion or with functions for (explicit) data type conversion (see Chapter 11.6 “Conversion functions (Conversion of data type)” on page 376).

4.3.2 Implicit data type conversion

The implicit data type conversion occurs automatically when a function is executed if the data types of the involved tags are compatible. It always applies during implicit data type conversion that the bit length of the source data type must not exceed that of the destination data type. For example, a tag with data format DWORD (source data type) cannot be applied to a block parameter which expects data type WORD (destination data type). The programmed bit length must agree with the expected bit length for an in-out parameter. The scope of implicit data type conversion depends on the block attribute IEC check (see Table 4.3).

For LAD and FBD, the implicit conversion from a smaller data width to a larger data width is indicated with a gray symbol at the function inputs and outputs. To improve clarity, implicit data type conversion can also be programmed with SCL.

The statement is Source data type_TO_Destination data type, for example

#var_word := BYTE_TO_WORD(#var_byte);

Where an implicit conversion is possible, the bit pattern of the source tags is trans- ferred unchanged and right-justified to the target tag. Any free bit positions are filled with zeros. For a possible implicit conversion to a floating-point data type, the format is transformed (from “–1” to “–1.0”).

4.3.3 Overlaying tags (data type views)

A tag can be “overlaid” by a further data type. It is then possible to address the con- tents of tags completely or partially using various data types.

You overlay a tag with a further data type using the keyword AT. You can overlay several data type definitions over a tag which are differentiated by different names.

A default setting with fixed values (initialization) is not possible.

Example: You declare an input parameter in the block interface with Station as the name and STRING[12] as the data type. You can overlay this input parameter with an additional STRUCT data type with the name Length and the components maximal and actual, each with the data type USINT (Fig. 4.7). You can now address the cur- rent length of the tags #Station with #Length.actual in the block program.

You can only program the overlaying with further data types in the interface of logic blocks. In addition, the block attribute Optimized block access must be deactivated.

The memory requirements of the overlaying data type definition must not be greater than the “original” tag (the new data type must “fit” into the tag).

You use a overlaying data type definition like any other tag, but only locally in the block. In the example, the calling block writes a string into the input parameter

Table 4.3 Implicit data type conversion to

from BOOL BYTE WORD DWORD USINT UINT UDINT SINT INT DINT REAL LREAL TIME TOD DATE DTL CHAR STRING

BOOL

BYTE x x O O O KF O O O

WORD x O O KF O O

DWORD O KF O O

USINT O O O x x x x x x

UINT O O x x x x O

UDINT O x O

SINT KF x x x x

INT S KF x x x

DINT S S KF x O

REAL x

LREAL

TIME O O

TOD O O

DATE O O

DTL

CHAR O x

STRING

Implicit data type conversion is possible: X Independent of attribute IEC check O With deactivated attribute IEC check

KF only with LAD and FBD with deactivated attribute IEC check S only with SCL with deactivated attribute IEC check

Fig. 4.7 Example of declaration of a “overlaid” data type

#Station; the superimposing data type definition as a USINT structure is not acces- sible to it.

No overlaying with data types is possible for an organization block, because the Optimized block access attribute is always active.

Only the tags in the temporary local data can be overlaid with additional data types in an FC block.

In a function block, the tags with additional data types can be overlaid in all decla- ration subsections of the block interface. If the in-out parameter has an elementary data type, overlaying is only possible with an elementary data type. If the in-out parameter has a structured data type, overlaying is only possible with a structured data type.

Một phần của tài liệu Hans berger automating with SIMATIC s7 1200 configuring programming (Trang 93 - 96)

Tải bản đầy đủ (PDF)

(577 trang)