From twincat-mcp-agent
Use this skill when the user asks about data types, arrays, structures (STRUCT), enumerations (ENUM), pointers (POINTER), references (REFERENCE), or dynamic memory allocation (NEW/DELETE). It also contains critical rules for memory alignment (pack_mode) to minimize padding bytes.
How this skill is triggered — by the user, by Claude, or both
Slash command
/twincat-mcp-agent:tc-datatypes-memoryThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
| Category | Type | Size | Range / Notes |
| Category | Type | Size | Range / Notes |
|---|---|---|---|
| Boolean | BOOL | 8 bit | TRUE (1), FALSE (0). |
| Bit String | BYTE | 8 bit | 0 to 255 |
WORD | 16 bit | 0 to 65535 | |
DWORD | 32 bit | 0 to 4294967295 | |
LWORD | 64 bit | 0 to 2^64-1 | |
| Signed Integer | SINT | 8 bit | -128 to 127 |
INT | 16 bit | -32768 to 32767 | |
DINT | 32 bit | -2147483648 to 2147483647 | |
LINT | 64 bit | 64-bit signed integer | |
| Unsigned Integer | USINT | 8 bit | 0 to 255 |
UINT | 16 bit | 0 to 65535 | |
UDINT | 32 bit | 0 to 4294967295 | |
ULINT | 64 bit | 64-bit unsigned integer | |
| Floating Point | REAL | 32 bit | IEEE 754 single precision |
LREAL | 64 bit | IEEE 754 double precision | |
| String | STRING(n) | n+1 bytes | Default 80 chars, max 255. |
WSTRING | 2*(n+1) bytes | Unicode string. | |
| Time | TIME | 32 bit | T#0ms to T#49d17h2m47s295ms |
LTIME | 64 bit | High-resolution time. | |
| Date | DATE | 32 bit | D#1970-01-01 format. |
TIME_OF_DAY (TOD) | 32 bit | TOD#00:00:00 format. | |
DATE_AND_TIME (DT) | 32 bit | DT#1970-01-01-00:00:00 format. |
| Type | Syntax | Notes |
|---|---|---|
| ARRAY | ARRAY [lo..hi] OF <type> | 1D, 2D, 3D supported. Max 9 dimensions via nesting. |
| STRUCT | TYPE ST_Name : STRUCT ... END_STRUCT END_TYPE | 8-byte alignment (TwinCAT 3). Order by descending size to minimize padding. Unpacked structs inside packed structs are not allowed (error 3850). |
| ENUM | TYPE E_Name : ( val1, val2, ... ); | Always use {attribute 'strict'} + {attribute 'qualified_only'}. Access: E_Name.eValue. |
| ALIAS | TYPE T_Name : <base_type>; END_TYPE | Supports default init and subrange combination. |
| SUBRANGE | TYPE T_Name : INT (lo..hi); END_TYPE | Only on integer types. |
| POINTER | POINTER TO <type> | Check <> 0 before dereferencing with ^. Use ADR() to get address. |
| REFERENCE | REFERENCE TO <type> | Assign with REF=. Check with __ISVALIDREF(). |
| INTERFACE | I_Name | Check <> 0 before use. Convert with __QUERYINTERFACE(). |
nHex := 16#FF; (* Hexadecimal *)
nOct := 8#77; (* Octal *)
nBin := 2#1010_1010; (* Binary, underscores for readability *)
nVal := SINT#127; (* Explicit type prefix *)
fVal := REAL#3.14;
tDelay := T#100ms;
tLong := T#2h30m;
dToday := D#2026-02-20;
todNow := TOD#18:30:00;
dtStamp := DT#2026-02-20-18:00:00;
sText := 'Hello World';
sEscape := '$N'; (* Newline escape *)
| Operator | Effect |
|---|---|
refA REF= value | refA now points to value (address assignment) |
refA := value | Writes value to location referenced by refA (value copy) |
refInt REF= nMyInt;
refInt := 42;
bValid := __ISVALIDREF(refInt);
ipSample := fbSample;
IF ipSample <> 0 THEN
nResult := ipSample.Add(3, 6);
END_IF;
bOk := __QUERYINTERFACE(iBase, iDerived);
{attribute 'qualified_only'}
{attribute 'strict'}
TYPE E_Color :
(
eRed,
eYellow,
eGreen := 10,
eBlue
) UINT := E_Color.eRed;
END_TYPE
eMyColor := E_Color.eBlue; (* Always qualified *)
TwinCAT 3 uses 8-byte alignment (vs. 1-byte in TC2 x86).
MIN(data_type_size, pack_mode).MIN(largest_member_size, pack_mode).MEMCMP).TYPE ST_Optimal : (* 16 bytes total — minimal padding *)
STRUCT
fValue : LREAL; (* 8 bytes at offset 0 *)
nCount : DINT; (* 4 bytes at offset 8 *)
bFlag : BOOL; (* 1 byte at offset 12 + 3 padding *)
END_STRUCT
END_TYPE
TYPE ST_Wasteful : (* 24 bytes total — bad ordering *)
STRUCT
bFlag : BOOL; (* 1 byte + 7 padding *)
fValue : LREAL; (* 8 bytes *)
nCount : DINT; (* 4 bytes + 4 padding *)
END_STRUCT
END_TYPE
(* Tip: order members by descending size to minimize padding *)
{attribute 'pack_mode' := '1'} (* 1-byte — no padding *)
TYPE ST_Packed :
STRUCT
bFlag : BOOL;
nValue : DINT; (* immediately follows bFlag, no padding *)
END_STRUCT
END_TYPE
| pack_mode value | Alignment |
|---|---|
'0' | 8-byte (default TwinCAT 3) |
'1' | 1-byte (no padding) |
'2' | 2-byte |
'4' | 4-byte |
FBs/DUTs require {attribute 'enable_dynamic_creation'}.
VAR
pFB : POINTER TO FB_Dynamic;
END_VAR
pFB := __NEW(FB_Dynamic);
IF pFB <> 0 THEN
nResult := pFB^.DoWork(nParam := 42);
END_IF;
__DELETE(pFB); (* releases memory, sets pFB to 0, calls FB_exit *)
__NEW allocates from router memory pool. Must pair with __DELETE to avoid leaks.__DELETE releases memory and sets pointer to 0.FB_exit call.VAR
exc : __SYSTEM.ExceptionCode;
END_VAR
__TRY
nResult := nA / nB;
__CATCH(exc)
IF exc = __SYSTEM.ExceptionCode.RTSEXCPT_DIVIDEBYZERO THEN
bError := TRUE;
END_IF;
__ENDTRY
Warning:
F_RaiseException()outside a__TRYblock stops the controller.
TYPE U_Convert :
UNION
nValue : DWORD;
aBytes : ARRAY [0..3] OF BYTE;
END_UNION
END_TYPE
DWORD).{attribute 'pack_mode' := '1'} to remove padding when overlaying I/O data.| Type | Description |
|---|---|
PVOID | Untyped pointer; size matches platform pointer width (4 bytes on 32-bit, 8 bytes on 64-bit). Recommended return type of ADR(). |
XINT / UXINT | Platform-native signed/unsigned integer (32-bit on x86, 64-bit on x64). |
XWORD | Platform-native bit-string. |
BIT | Single bit (only valid as struct member, packed into bytes). Cannot use ADR — use BITADR. |
Use these to write code that compiles unchanged on both 32-bit and 64-bit TwinCAT runtimes.
FUNCTION F_Sum : DINT
VAR_IN_OUT
aData : ARRAY [*] OF DINT; (* Bounds resolved at call site *)
END_VAR
VAR
i, nLow, nHigh : DINT;
END_VAR
nLow := LOWER_BOUND(aData, 1);
nHigh := UPPER_BOUND(aData, 1);
FOR i := nLow TO nHigh DO
F_Sum := F_Sum + aData[i];
END_FOR;
npx claudepluginhub techindustryx/twincat-agent --plugin twincatProvides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.