본문으로 이동

구조화된 텍스트

위키백과, 우리 모두의 백과사전.

구조화된 텍스트, 구조화 텍스트, 스트럭처드 텍스트(Structured text, 약칭: ST 또는 STX)는 프로그래머블 로직 컨트롤러(PLC)용으로 설계된 IEC 61131-3 표준에서 지원하는 다섯 가지 언어 중 하나이다.[1][2] 이 언어는 블록 구조를 가지며, 기반이 되는 파스칼과 문법적으로 유사한 고급 언어이다.[3] 모든 언어는 IEC61131 Common Elements를 공유한다. 변수 및 함수 호출은 공통 요소에 의해 정의되므로, IEC 61131-3 표준 내의 다른 언어들을 동일한 프로그램에서 사용할 수 있다.

복잡한 문장과 중첩된 명령이 지원된다:

  • 반복 루프 (REPEAT-UNTIL; WHILE-DO)
  • 조건부 실행 (IF-THEN-ELSE; CASE)[3]
  • 함수 (SQRT(), SIN())

샘플 프로그램

[편집]
(* simple state machine *)
TxtState := STATES[StateMachine];

CASE StateMachine OF
   1: ClosingValve();
      StateMachine := 2;
   2: OpeningValve();
ELSE
    BadCase();
END_CASE;

다른 일부 프로그래밍 언어와 달리, CASE 문에는 폴스루가 없다: 첫 번째 일치하는 조건이 실행되고, 해당 문이 실행된 후에는 다른 조건을 확인하지 않고 CASE 블록을 벗어난다.

추가 ST 프로그래밍 예제

[편집]
// PLC configuration
CONFIGURATION DefaultCfg
    VAR_GLOBAL
        b_Start_Stop  : BOOL;         // Global variable to represent a boolean.
        b_ON_OFF      : BOOL;         // Global variable to represent a boolean.
        Start_Stop AT %IX0.0:BOOL;    // Digital input of the PLC (Address 0.0)
        ON_OFF     AT %QX0.0:BOOL;    // Digital output of the PLC (Address 0.0). (Coil)
    END_VAR

    // Schedule the main program to be executed every 20 ms
    TASK Tick(INTERVAL := t#20ms);

    PROGRAM Main WITH Tick : Monitor_Start_Stop;
END_CONFIGURATION

PROGRAM Monitor_Start_Stop          // Actual Program
    VAR_EXTERNAL
        Start_Stop  : BOOL;
        ON_OFF      : BOOL;
    END_VAR
    VAR                             // Temporary variables for logic handling
        ONS_Trig    : BOOL;
        Rising_ONS  : BOOL;
    END_VAR

    // Start of Logic
    // Catch the Rising Edge One Shot of the Start_Stop input
    ONS_Trig    := Start_Stop AND NOT Rising_ONS;

    // Main Logic for Run_Contact -- Toggle ON / Toggle OFF ---
    ON_OFF := (ONS_Trig AND NOT ON_OFF) OR (ON_OFF AND NOT ONS_Trig);

    // Rising One Shot logic
    Rising_ONS := Start_Stop;
END_PROGRAM

함수 블록 예제

[편집]
//=======================================================================
// Function Block Timed Counter :  Incremental count of the timed interval
//=======================================================================
FUNCTION_BLOCK FB_Timed_Counter
    VAR_INPUT
        Execute         : BOOL := FALSE;        // Trigger signal to begin Timed Counting
        Time_Increment  : REAL := 1.25;         // Enter Cycle Time (Seconds) between counts
        Count_Cycles    : INT  := 20;           // Number of Desired Count Cycles
    END_VAR

    VAR_OUTPUT
        Timer_Done_Bit  : BOOL := FALSE;        // One Shot Bit indicating Timer Cycle Done
        Count_Complete  : BOOL := FALSE;        // Output Bit indicating the Count is complete
        Current_Count   : INT  := 0;            // Accumulating Value of Counter
    END_VAR

    VAR
        CycleTimer      : TON;                  // Timer FB from Command Library
        CycleCounter    : CTU;                  // Counter FB from Command Library
        TimerPreset     : TIME;                 // Converted Time_Increment in Seconds to MS
    END_VAR

    // Start of Function Block programming
    TimerPreset := REAL_TO_TIME(in := Time_Increment) * 1000;

    CycleTimer(
        in := Execute AND NOT CycleTimer.Q,
        pt := TimerPreset);

    Timer_Done_Bit := CycleTimer.Q;

    CycleCounter(
        cu := CycleTimer.Q,
        r := NOT Execute,
        pv := Count_Cycles);

    Current_Count := CycleCounter.cv;
    Count_Complete := CycleCounter.q;

END_FUNCTION_BLOCK

각주

[편집]
  1. Bacidore, Mike (2018년 5월 16일). 61131/ “Should I limit programming to ladder logic or use all standards within IEC 61131?” |url= 값 확인 필요 (도움말). 《Control Design》. 
  2. Stevic, Tom (2017년 5월 5일). “A very short history of PLC programming platforms”. 《Control Design》. 
  3. Roos, Nieke. 《Programming PLCs using Structured Text》. Department of Computing Science, University of Nijmegen. CiteSeerX 10.1.1.49.2016.