Ir para o conteúdo

Tipos de Dados

Declaracion de una Variable:

La declaración de variables en CODESYS ó TwinCAT incluirá:

  • Un nombre de variable
  • Dos puntos
  • Un tipo de dato
  • Un valor inicial opcional
  • Un punto y coma
  • Un comentario opcional

1
2
3
4
( <pragma> )*
<scope> ( <type qualifier> )?
      <identifier> (AT <address> )? : <data type> ( := <initial value> )? ;
END_VAR
- 🔗 infosys.beckhoff.com, Declaring variables

1
2
3
4
5
6
VAR
    nVar1   : INT := 12;                    // initialization value 12
    nVar2   : INT := 13 + 8;                // initialization value defined by an expression of constants
    nVar3   : INT := nVar2 + F_Fun(4);      //initialization value defined by an expression that contains a function call; notice the order!
    pSample : POINTER TO INT := ADR(nVar1); //not described in the standard IEC61131-3: initialization value defined by an adress function; Notice: the pointer will not be initialized during an Online Change
END_VAR

🔗 Tipos de Datos:

Las ventajas de las estructuras de datos.

  • La principal aportación de las estructuras de datos y los tipos de datos creados por el usuario es la claridad y el orden del código resultante.

Estructuras de datos: (STRUCT)

Datos de usuario:UDT (User Data Type):

Los UDT (User Data Type) son tipos de datos que el usuario crea a su medida, según las necesidades de cada proyecto.


When programming in TwinCAT, you can use different data types or instances of function blocks. You assign a data type to each identifier. The data type determines how much memory space is allocated and how these values are interpreted.

The following groups of data types are available:

Standard data types

TwinCAT supports all data types described in the IEC 61131-3 standard.

  • BOOL
  • Integer Data Types
  • REAL / LREAL
  • STRING
  • WSTRING
  • Time, date and time data types
  • LTIME

Extensions of the IEC 61131-3 standard

  • BIT
  • ANY and ANY_
  • Special data types XINT, UXINT, XWORD and PVOID
  • REFERENCE
  • UNION
  • POINTER
  • Data type __SYSTEM.ExceptionCode

User-defined data types

Note the recommendations for naming objects.

  • POINTER
  • REFERENCE
  • ARRAY
  • Subrange Types User-defined data types that you create as DUT object in the TwinCAT PLC project tree:

  • Structure

  • Enumerations
  • Alias
  • UNION

Further Information

  • BOOL
  • Integer Data Types
  • Subrange Types
  • BIT
  • REAL / LREAL
  • STRING
  • WSTRING
  • Time, date and time data types
  • ANY and ANY_
  • Special data types XINT, UXINT, XWORD and PVOID
  • POINTER
  • Data type __SYSTEM.ExceptionCode
  • Interface pointer / INTERFACE
  • REFERENCE https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2529458827.html&id=
  • ARRAY
  • Structure
  • Enumerations
  • Alias
  • UNION

  • 🔗 Special data types XINT, UXINT, XWORD and PVOID