Phio Automation Documentation

website·Indexed 30 days ago

https://docs.phioautomation.com/

Documentation for a PLC and automation programming playground, featuring guides on IEC 61131-3 structured text, elementary types (BOOL, POINTER, integers), function blocks (TON, TOF, CTU, CTD, R_TRIG, F_TRIG), and core library functions. Includes syntax references for declarations, conditional statements, loops, and the Phio Highlighter.

Tokens
10.3K
Snippets
88
Records
101
Agent score
50%

What's inside Phio Automation

  1. Overview of Phio Highlighter architecture

    The Phio Highlighter is a syntax highlighter for the web that uses a Lezer-generated LR parser based on the IEC Structured Text language grammar. Unlike regex-based highlighters, it generates a tree structure to provide more accurate highlighting (similar to an IDE), such as correctly handling underscores in numbers or distinguishing type definitions from general identifiers. It utilizes a highlightCode function to perform highlighting without requiring the full CodeMirror editor.
  2. Overview of phioautomation.com PLC interpreter

    phioautomation.com is a free, open, web-based interpreter for the IEC 61131-3 Structured Text language. It allows users to write, run, and share PLC code without requiring proprietary software installations, expensive licenses, or specific operating systems. The platform uses plain text files and provides a zero-barrier environment for learning and collaborating on automation code.
  3. Overview of the Phio Automation Editor

    The Phio Automation editor is a web-based educational tool designed for learning programming languages without requiring expensive licenses, hardware, or software installations. It functions as a REPL (Read-Eval-Print Loop) that parses input text, checks for syntax errors, and evaluates code. The editor aims for full compliance with the IEC 61131-3 standard and provides built-in code linting for syntax analysis.
  4. Use the print function for code tracing and debugging

    The print function is a non-standard extension (not defined by IEC 61131-3) provided by Phio Automation to allow developers to trace code execution and inspect the results of operations for debugging and educational purposes.
  5. Use Properties in Programs and Function Blocks

    Properties are special members available to Programs and Function Blocks used to encapsulate local variables and control access to the internal state. They provide a mechanism to validate or transform data through getter and setter methods.

    Access levels for properties include:

    • Read-Only: Only a getter method is defined.
    • Write-Only: Only a setter method is defined.
    • Read-Write: Both getter and setter methods are defined.
  6. Use the print function for code tracing and debugging

    The print function is a non-standard utility (not defined by IEC 61131-3) provided by Phio Automation to allow developers to trace code execution and understand the results of operations. It is primarily used as a debugging and educational tool to monitor the internal state and flow of the program.
  7. Use the RETURN statement to exit a call expression early

    The RETURN statement is used to immediately exit the scope of a call expression, such as a Function, Function Block, Method, or Property. Any code following the RETURN statement within that scope will not be executed.
    FUNCTION F_EarlyReturn : INT
    
    F_EarlyReturn := 10;
    
    // End the function early
    RETURN;
    
    F_EarlyReturn := 20; // This line will never be reached
    END_FUNCTION
    
    print(F_EarlyReturn());
  8. Implement Phio Highlighter in plain HTML

    To use the highlighter in a standard HTML document, three requirements must be met:

    1. Include the highlighter script from the Phio Automation CDN.
    2. Include a stylesheet that supports Prism CSS classes (e.g., from cdnjs).
    3. Apply the class language-phioiecst to the pre and code elements that require syntax highlighting.
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <!-- 1. Prism CSS Theme -->
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism-themes/1.9.0/prism-vsc-dark-plus.min.css" />
    </head>
    <body>
        <!-- 2. Highlighter Script -->
        <script src="https://highlighter.phioautomation.com/iecst.js"></script>
    
        <!-- 3. Highlighted Block -->
        <pre class="language-phioiecst"><code class="language-phioiecst">// Your code here!</code></pre>
    
        <!-- 3. Highlighted Inline Code -->
        <p>
            This is an inline piece of code: <code class="language-phioiecst">VAR</code> or <code class="language-phioiecst">END_VAR</code>
        </p>
    </body>
    </html>
  9. Use ELSIF for sequential conditional branching

    The ELSIF clause allows for additional conditions to be tested in sequential order if the preceding IF or ELSIF conditions evaluate to false. Only the first block that evaluates to true is executed.
    a : BOOL := TRUE;
    b : INT := 0;
    
    IF b > 0 THEN
        b := 1;   // Not executed, b is not greater than 0
    ELSIF a THEN
        b := 2;   // a is true, b is assigned to 2
    END_IF;
  10. Iterate using the FOR loop statement

    The FOR statement executes a block of code a specific number of times based on a lower bound, an upper bound, and an increment value. The loop continues to execute until the iterator variable exceeds the defined upper bound.
    i : INT;
    a : INT;
    
    FOR i := 1 TO 10 BY 1 DO
          a := i;
    END_FOR;
    
    print(a);   // a is 10
    print(i);   // i is 10
  11. Define floating-point literals in decimal and scientific notation

    Floating point literals can be defined using decimal or scientific notation. Underscores (_) are supported as digit separators to improve readability.

    Constraints:

    • Comma separators for thousands (e.g., 1,000,000.0) are not supported.
    • International notations using a comma as a decimal separator (e.g., 1,123) are not supported; use a period (.) instead.
    a : REAL;
    
    // Decimal notation
    a := -1.0;
    a := +205.3;
    a := 100.856;
    
    // Scientific notation (case-insensitive 'e')
    a := 1.0e2;
    a := 6.45e+5;
    a := 2.11e-7;
    a := 1.0E2;
    
    // Using underscores for readability
    a := 0.123_456;
    a := 123_456.0;