A VSCode extension for PLC (Programmable Logic Controller) development, providing syntax highlighting for Structured Text (.st) files and XML export functionality.
Features
1. Syntax Highlighting for .st Files
Keywords: Control keywords (IF, THEN, ELSE, FOR, WHILE, etc.)
Data Types: Basic data types (BOOL, INT, REAL, STRING, etc.)
Constants: Numbers, boolean values (TRUE, FALSE)
Strings: Double-quoted and single-quoted strings
Comments: Single-line comments (//) and block comments (* *)
Operators: Arithmetic, comparison, and logical operators
2. XML Export Functionality
Right-click Menu: Export PLC Open XML from .st files
Customizable Output Directory: Configure where XML files are generated
Automatic Directory Creation: Creates output directory if it doesn't exist
3. Configuration Options
js-plc.xmlOutputDirectory: Directory where XML files will be generated (default: "build")
Installation
Open VSCode
Go to Extensions view (Ctrl+Shift+X)
Search for "JS PLC"
Click Install
Reload VSCode to activate the extension
Usage
Syntax Highlighting
Simply open any .st file and the syntax highlighting will be automatically applied.
Exporting XML
Open a .st file
Right-click in the editor
Select "Export PLC Open XML" from the context menu
The XML file will be generated in the configured output directory
Configuring Output Directory
Open VSCode Settings (File > Preferences > Settings)
Search for "JS PLC"
Modify the "Xml Output Directory" setting
Or use the command palette (Ctrl+Shift+P) and run "Set XML Output Directory"
Supported File Types
.st - Structured Text files
Example
Structured Text File Example
TYPE
DUT_ENUM :
(
GREEN,
BLUE
) := DUT_ENUM#GREEN;
DUT_ALIAS : BOOL := FALSE;
DUT_SUB : INT (0..5) := 2;
DUT_ARR : ARRAY [1..2, 1..2] OF BOOL := 1;
DUT_STRUCT : STRUCT
A : BOOL;
B : DUT_ALIAS;
END_STRUCT;
DUT_UNION : UNION
C : BOOL;
D : BOOL;
END_UNION;
END_TYPE
PROGRAM TEST
VAR
LocalVar0 : INT;
LocalVar1 : BOOL;
LocalVar2 : BOOL;
LocalVar3 : DUT_ALIAS;
LocalVar4 : DUT_SUB;
LocalVar5 : DUT_ENUM;
LocalVar6 : DUT_ARR;
LocalVar7 : DUT_STRUCT;
LocalVar8 : DUT_UNION;
END_VAR
FOR LocalVar0 := 1 TO 128 BY 1 DO
END_FOR ;
LocalVar0 := 11;
END_PROGRAM
CONFIGURATION config
VAR_GLOBAL CONSTANT GVL
GlobalVar0 : BOOL;
END_VAR
VAR_GLOBAL GVL
GlobalVar1 : BOOL;
END_VAR
RESOURCE resource1 ON PLC
TASK NewTask2(SINGLE := GlobalVar0, PRIORITY := 1);
TASK NewTask3(FREEWHEELING := TRUE, PRIORITY := 1);
TASK NewTask(SINGLE := GlobalVar0, PRIORITY := 1);
TASK MainTask(INTERVAL := T#20ms, PRIORITY := 1);
PROGRAM NewTask2_25044_TEST_1 WITH NewTask2 : TEST;
PROGRAM NewTask3_25045_TEST_1 WITH NewTask3 : TEST;
PROGRAM NewTask_25043_TEST_1 WITH NewTask : TEST;
PROGRAM MainTask_23417_TEST_1 WITH MainTask : TEST;
END_RESOURCE
END_CONFIGURATION
Generated XML
The extension will generate XML files compatible with PLC Open standards.