'Are there global constants specifying the integer ranges in twincat3?
I wonder if there is something like a UINT_MAX (= 65535) define in any of the twincat3 system libraries.
Solution 1:[1]
I've also never seen them. But you could create them easily as follows
PROGRAM MAIN
VAR
number : UINT;
UINT_MAX : UINT;
END_VAR
UINT_MAX := number - 1;
You could also do it with just a single variable UINT_MAX := UINT_MAX - 1;
, but then you have to make sure the 1 only gets subtracted once.
The easiest would be to define them once in a global variable list and make that into a library.
Solution 2:[2]
There does not appear to be anything specific inside of TwinCAT that does what you are looking for. There is something similar however inside of the C layer of objects though.
UINT
There are multiple versions of UINT inside the type system (UINT, UINT24, UINT40, UINT48, UINT56) which are all devoted to the same informational range and values.
When viewed inside of the TMC handling (Datatypes), each of these datatypes has 2 properties:
DisplayMinValue
: #x0000DisplayMaxValue
: #xFFFF
Implementation and access to these properties appears to be limited to access via the C interface and unavailable from inside TwinCAT itself, but they are there.
Solution 3:[3]
Another way around this problem is using the bitwise operator NOT. Define a UINT called UINT_MAX and use the following snippet during the first cycle of the PLC:
UINT_MAX := NOT UINT_MAX;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Roald |
Solution 2 | |
Solution 3 | mackan |