Features

AI Code Generation

Use natural language to generate Structured Text code

AI Code Generation

PLC Studio AI's code generation feature lets you describe what you want in plain English, and the AI writes the Structured Text code for you.

Using the AI Chat

The AI chat is your primary interface for code generation. You'll find it in the right panel of the PLC Studio AI interface.

Basic Usage

  1. Select a POU in the project explorer (or create a new one)
  2. Type your request in the chat
  3. Review the generated code in the diff view
  4. Accept or modify the changes

Example Prompts

Here are some effective prompts to get you started:

Creating a new function block:

Create a function block called FB_MotorControl with:
- Input: bStart (BOOL), bStop (BOOL), rSpeed (REAL)
- Output: bRunning (BOOL), bError (BOOL)
- Logic: Start sets running, stop clears it, error if speed > 100

Adding functionality:

Add a timer that delays the motor start by 2 seconds after bStart goes TRUE

Implementing algorithms:

Implement a PID controller with configurable Kp, Ki, and Kd parameters

Generating boilerplate:

Create the state machine structure for a 5-step sequence control

Understanding AI Responses

When you send a request, the AI will:

  1. Analyze your request - Understanding what you want to achieve
  2. Consider context - Looking at existing code and project structure
  3. Generate code - Writing Structured Text that meets your requirements
  4. Explain changes - Providing a summary of what was generated

The generated code appears in the diff view, where you can review it before accepting.

Tips for Better Results

Be Specific About Data Types

// Less effective
"Create a variable for temperature"

// More effective
"Create a REAL variable called rTemperature with initial value 20.0"

Reference Existing Code

// The AI knows your project context
"Add error handling to the FB_Pump function block similar to FB_Motor"

Break Down Complex Requests

// Instead of one large request, break it down:
1. "Create the basic structure for FB_ConveyorControl"
2. "Add the speed control logic with ramping"
3. "Add the emergency stop handling"

Ask for Explanations

"Explain what this code does: [paste code]"
"Why did you use a TON timer instead of TOF?"

Code Generation Modes

Generate New Code

Create entirely new POUs, variables, or code sections:

"Create a new function block FB_ValveControl for a 3-way valve"

Modify Existing Code

Update or enhance existing code:

"Add input validation to the current function"
"Refactor this to use a CASE statement instead of IF-ELSE"

Complete Code

Let AI finish what you started:

"Complete this function block based on the interface I've defined"

Limitations

The AI code generation has some limitations:

  • Structured Text only - Other IEC 61131-3 languages are view-only
  • No hardware access - AI cannot directly interact with your PLC
  • Context window - Very large projects may not fully fit in context
  • No real-time data - AI doesn't have access to live PLC values

Best Practices

  1. Always review generated code - AI can make mistakes
  2. Test thoroughly - Generated code should be tested like any other code
  3. Start simple - Begin with small requests and build up
  4. Provide context - The more context you give, the better the results
  5. Iterate - Don't expect perfection on the first try

Next Steps

On this page