codesys data type

Published on Jul09, 2021 | Category: data type
Share this article:

data type store value in memory space, each data type have reserved space of memory. When you define data types to a identifier, so data type reserved space for your identifier and show how values are interpreted to identifier.

how to Declare Variables in codesys

data type plays an important role. you can declare variable following method.

img/datatype/autodeclare.webp

codesys variable declaration using AT keyword

codesys Rules for identifiers of variables

codesys BOOL data type

bool data type have only two values either 0 or 1, 0 refers false and 1 refers true. Memory space for bool is 8 bit. bool data type used in NO, NC, coil, Boolean operator(and, or, xor, nand, nor), two states switch, push button, zss, switching devices, status of motor, sensor etc, output of comparison, timer.

img/datatype/bittype.webp

codesys Integer Data Types

integer data types store integer value in memory within range. when you make program so carefully assign data type integer because integer date type only store numeric value without decimal. integer data type allowed value like 8 , -98, 3422, 124 etc but not allowed value like 8.234, 9.1, -6.34. each integer data type have different range of value. BYTE, WORD, DWORD, LWORD, SINT, USINT, INT, UINT, DINT, UDINT, LINT, ULINT are all integer data types. Numeric values can be binary, octal, decimal, and hexadecimal numbers.

img/datatype/notpermit.webp

how to declare integer values in codesys

you can write decimal value directly. but if your value is not decimal than you can use "#" sign, before the # sign declare base of value 2 for binary, 8 for octal, 16 for hexadecimal. for example

integer data type used to store analog value without decimal like position, temperature, etc. Each of the different number types covers a different range of values. Following are integer data type

data type byte

byte store value within range from 0 to 255, and memory space of byte is 8 bit. considered example of byte both input and output is byte data type.

img/datatype/byte.webp

data type word

word store value within range from 0 to 65535 and memory space is 16 bit. value below 0 and above 65535 is not allowed.

img/datatype/wordtype.webp

data type dword

dword range of dword is 0 to 4294967295 and memory space is 32 bit.

img/datatype/dword.webp

codesys data type SINT

SINT signed integer you can store positive as well as negative value within range of -128 to 127 and memory space is 8 bit.

data type USINT

usint unsigned integer you can store only positive value range fir usint is 0 to 255 and memory space is 8 bit.

img/datatype/sintuint.webp

codesys Integer (INT) data type

int range for int is -32768 to -32767 and memory space is 16 bit you can store positive and negative value with in range.

img/datatype/int.webp

codesys unsigned integer data type UINT

UINT unsigned integer value 0 to 65535 and memory space is 16 bit you can store only positive value but not above 65535.

data type DINT

DINT double integer you can store positive and negative value within range of -2147483648 to 2147483647 and memory space is 32bit.

Data type UDINT

UDINT unsigned double integer range of value 0 to 4294967295 and memory space is 32 Bit.

img/datatype/dint.webp

codesys data type REAL/LREAL

REAL and LREAL store floating point (with decimal) value like 10.111, 112.98333. Floating point used in temperature sensor, pid, set point, actual position etc these value gives the good precision because They are required to represent rational numbers. for example by using REAL or LREAL data type you can show temperature value like 12.3333 °C, 1.003483 m, 4.989999 psi.

img/datatype/reallreal.webp

codesys data type STRING

string data type store character , size declare determines how much memory space should be reserved, size(range) of string is 0 to 255. you can declare string like var_1:STRING(5):='admin';
var_string: STRING[4];
in parentheses or brackets you can declare size of string by default 80 character. for example var_string: STRING[4]; so this store only 4 character. The string length basically is not limited in CoDeSys, but string functions only can process strings of 1 to 255 characters.

img/datatype/string.webp

codesys data type Time

for value like time , date, date and time you can use different time data types like Time, TIME_OF_DAY, DATE, DATE_AND_TIME. These are handled internally like DWORD. so the range and memory space for time is same as DWORD. 0 to 4294967295 and memory space is 32 bit.

codesys data type time

time data type store time. time value always start with t or T with "#" sign, so time will be same as T# d:h:m:ms where d stands for days values, h stands for hour, m stands for minute, and ms stand for millisecond. Always made up of an initial "t" or "T" (or "time" or "TIME" spelled out) and a number sign "#".Please note that the time entries must be order of d:h:m:ms according to length, but you are not required to include all time increments. Maximum value: 49d17h2m47s295ms (4194967295 ms).

codesys data type : DATE

data type date store date in memory space. You can then enter any date with format Year-Month-Day. Possible values: 1970-00-00 to 2106-02-06.beginning with a "d#", "D#", "DATE#" or "date#".

img/datatype/date.webp

codesys data type : TIME_OF_DAY

data type TIME_OF_DAY store times of the day. Begin with "tod#", "TOD#", "TIME_OF_DAY#" or "time_of_day#" followed by a time with the format: Hour:Minute:Second. Seconds can be entered as real numbers or you can enter fractions of a second. Possible values: 00:00:00 to 23:59:59.999.

img/datatype/tod.webp

codesys data type : DATE_AND_TIME

data type DATE_AND_TIME store combination of date and the time of day, data type date_and_time begin with "dt#", "DT#", "DATE_AND_TIME#" or "date_and_time#". Place a hyphen after the date followed by the time. Possible values declaration: 1970-00-00-00:00:00 to 2106-02-06-06:28:15.