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.
data type plays an important role. you can declare variable following method.
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.
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.
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
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.
word store value within range from 0 to 65535 and memory space is 16 bit. value below 0 and above 65535 is not allowed.
dword range of dword is 0 to 4294967295 and memory space is 32 bit.
SINT signed integer you can store positive as well as negative value within range of -128 to 127 and memory space is 8 bit.
usint unsigned integer you can store only positive value range fir usint is 0 to 255 and memory space is 8 bit.
int range for int is -32768 to -32767 and memory space is 16 bit you can store positive and negative value with in range.
UINT unsigned integer value 0 to 65535 and memory space is 16 bit you can store only positive value but not above 65535.
DINT double integer you can store positive and negative value within range of -2147483648 to 2147483647 and memory space is 32bit.
UDINT unsigned double integer range of value 0 to 4294967295 and memory space is 32 Bit.
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.
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.
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.
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).
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#".
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.
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.