CX-Programmer
 * 태스크
- 태스크 동작
태스크의 종류
1. 싸이클 실행 태스크
2. 인터럽트 태스크 (사용시 고유 Unit (INT01) 장작시 사용가능)

- 태스크 사용방법

태스크 기동(TKON) / 대기(TKOF) 명령사용

태스크 생성


태스크를 생성하고 생성한 태스크의 오른쪽 마우스를 눌러 속성에 들어간다.


이름은 사용하고 싶은 이름을 작성하면 됨

태스크 유형은 사이클릭 태스크 번호 또는 인터럽트 태스크를 선택할수 있다.

작업시작은 처음 PLC RUN시 한번 이 태스크를 실행한다.

 
- 태스크 설계의 지침

다음과 같은 지침을 토대로 태스크를 설계할 것을 추천합니다.

1. 태스크 분할은 다음기준으로 검토해 주십시오.

  1) 기동 / 대기의 조건을 명확히 해 정리한다.

  2) 외부 입출력의 유무로 정리한다.

  3) 기능으로 정리한다.
시퀀스제어, 아나로그 제어, 맨머신계 처리, 이상처리 등 가능한한 태스크 간의 데이터 교환을 적게한다. (독립성을 높인다)

  4) 실행우선순위로 정리한다.

통상태스크 / 인터럽트 태스크로 나눈다.


2. 태스크는 기본적으로 독립성을 높이고 태스크간의 데이터의 교환이 가능한한 적게 프

로그램을 분할설계해 주십시오.


3. 기본적으로는 전체관리(태스크 제어)용 태스크에 의해 각 태스크의 실행 / 대기를 제어

하도록 해 주십시오.

4. 싸이클 실행 태스크 중에서 우선순위가 높은 태스크에는 작은 태스크 No.를 할당해 주

십시오.

5. 우선순위가 높은 인터럽트태스크에는 작은 인터럽트 태스크 No.를 할당해 주십시오.

6. 태스크는 한번 기동하면 자신 또는 다른 태스크에의해 대기로 되지 않는한 다음의 싸이

클 이후 실행가능 상태로 됩니다. 조건에의한 태스크 분기처리를 행할 때 다른 태스크

에 대한 TKOF(태스크 대기) 명령을 잊지 말고 삽입해 주십시오.

7. 태스크 실행시의 이니셜 처리를 행할 때, 태스크 초회기동 플래그 (A20015)를 그 입력

조건에 사용해 주십시오. 태스크 초회기동 플래그는 해당 태스크가 처음으로 기동될 때

ON 합니다. 속성에서 작업시작 메뉴를 체크해도 같은 실행되는것 같다.

8. 태스크(프로그램) 공통으로 사용하는 I/O 메모리와 각 태스크 내만으로 사용하는 I/O

메모리를 분류하여 각 태스크 내만으로 사용하는 I/O 메모리의 범위를 각 태스크로 정

리해 확보해 둡니다.


* CX-Programmer
로직 작성방법은 콘트론 사이트 들어가 CX-P_조작법 메뉴얼을 보는것이 좋다^^

* A/D041-V1 (아날로그) 카드

- DM 메모리 영역 파라메타 설정 방법 (고정 데이터 설정)


- CIO 메모리 영역 사용 방법


* ETN21(이더넷) 카드

기본 설정은 콘드론 사이트에 ETN_간이_메뉴얼을 보고 설정

- TCP/IP Socket 통신 방법 (로직 작성 방법)

Open 로직

파라마터값 설정하는 부분후에

TCP Passive Open Request Switch (1519.01) Set 할때

TCP Active Open Request Switch (1519.02) 으로 Set 해야 이더넷 카드의 TCP 램프가 On.


Close 로직


Send 로직


Receive 로직

 

파라메타 설정은 콘트론 사이트에 ETN21 네트워크의 구조 메뉴얼을 보고 설정


* FB ST
문법

IF Statement Examples


IF expression1 THEN statement-list1

[ ELSIF expression2 THEN statement-list2 ]

[ ELSE statement-list3 ]

END_IF;


The expression1 and expression2 expressions must each evaluate to a boolean value. The statement-list is a list of several simple statements e.g. a:=a+1; b:=3+c; etc.

The IF keyword executes statement-list1 if expression1 is true; if ELSIF is present and expression1 is false and expression2 is true, it executes statement-list2; if ELSE is present and expression1 or expression2 is false, it executes statement-list3. After executing statement-list1, statement-list2 or statement-list3, control passes to the next statement after the END_IF.
There can be several ELSIF statements within an IF Statement, but only one ELSE statement.

IF statements can be nested within other IF statements (Refer to example 5).


Example 1

IF a > 0 THEN

b := 0;

END_IF;


Example 2

IF a THEN

b := 0;

END_IF;


Example 3

IF a > 0 THEN

b := TRUE;

ELSE

b := FALSE;

END_IF;


Example 4

IF a < 10 THEN

b := TRUE;

c := 100;

ELSIF a > 20 THEN

b := TRUE;

c := 200;

ELSE

b := FALSE;

c := 300;

END_IF;


Example 5

IF a THEN

b := TRUE;

ELSE

IF c>0 THEN

d := 0;

ELSE

d := 100;

END_IF;

d := 400;

END_IF;


WHILE Statement Examples


WHILE expression DO

statement-list;

END_WHILE;


The WHILE expression must evaluate to a boolean value. The statement-list is a list of several simple statements.

The WHILE keyword repeatedly executes the statement-list while the expression is true. When the expression becomes false, control passes to the next statement after the END_WHILE.


Example 1

WHILE a < 10 DO

a := a + 1;

b := b * 2.0;

END_WHILE;


Example 2

WHILE a DO

b := b + 1;

IF b > 10 THEN

a:= FALSE;

END_IF;

END_WHILE;


Example 3

WHILE (a + 1) >= (b * 2) DO

a := a + 1;

b := b / c;

END_WHILE;


Example 4

WHILE (a - b) <= (b + c) DO

a := a + 1;

b := b * a;

END_WHILE;


REPEAT Statement Examples


REPEAT

statement-list;

UNTIL expression

END_REPEAT;


The REPEAT expression must evaluate to a boolean value. The statement-list is a list of several simple statements.

The REPEAT keyword repeatedly executes the statement-list while the expression is false. When the expression becomes true, control passes to the next statement after END_REPEAT.


Example 1

REPEAT

a := a + 1;

b := b * 2.0;

UNTIL a > 10

END_REPEAT;


Example 2

REPEAT

b := b + 1;

IF b > 10 THEN

a:= FALSE;

END_IF;

UNTIL a

END_REPEAT;


Example 3

REPEAT

a := a + 1;

b := b / c;

UNTIL (a + 1) >= (b * 2)

END_REPEAT;


Example 4

REPEAT

a := a + 1;

b := b * a;

UNTIL (a - b) <= (b + c)

END_REPEAT;


Example 5

FOR a := b + c TO d - e BY f DO

g := g + a;

h := h + 1.0;

END_FOR;


CASE Statement Examples


CASE expression OF

case label1 [ , case label2 ] [ .. case label3 ] : statement-list1;

[ ELSE

statement-list2 ]

END_CASE;


The CASE expression must evaluate to an integer value. The statement-list is a list of several simple statements.

The case labels must be valid literal integer values e.g. 0, 1, +100, -2 etc..

The CASE keyword evaluates the expression and executes the relevant statement-list  ssociated with a case label whose value matches the initial expression. Control then passes to the next statement after the END_CASE. If no match occurs within the previous case labels and an ELSE command is present the statement-list associated with the ELSE keyword is executed. If the ELSE keyword is not present, control passes to the next statement after the END_CASE.

There can be several different case labels statements (and associated statement-list) within a CASE statement but only one ELSE statement.


The “,” operator is used to list multiple case labels associated with the same statement-list.

The “..” operator denotes a range case label. If the CASE expression is within that range then the associated statement-list is executed, e.g. case label of 1..10 : a:=a+1; would execute the a:=a+1 if the CASE expression is greater or equal to 1 and less than 10.


Example 1

CASE a OF

2 : b := 1;

5 : c := 1.0;

END_CASE;


Example 2

CASE a + 2 OF

-2 : b := 1;

5 : c := 1.0;

ELSE

d := 1.0;

END_CASE;


Example 3

CASE a + 3 * b OF

1, 3 : b := 2;

7, 11 : c := 3.0;

ELSE

d := 4.0;

END_CASE;


Example 4

CASE a OF

-2, 2, 4 : b := 2;

c := 1.0;

6..11, 13 : c := 2.0;

1, 3, 5 : c := 3.0;

ELSE

b := 1;

c := 4.0;

END_CASE;

------------------------------------------------------------------------------------------

Example 1

WHILE a DO

IF c = TRUE THEN

b:=0;EXIT;

END_IF;

IF b > 10 THEN

a:= FALSE;

END_IF;

END_WHILE;

d:=1;


Example 2

a:=FALSE;

FOR i:=1 TO 20 DO

FOR j:=0 TO 9 DO

IF i>=10 THEN

n:=i*10+j;

a:=TRUE;EXIT;

END_IF;

END_FOR;

IF a THEN EXIT; END_IF;

END_FOR;

d:=1;


Example 1

IF a_1*b>100 THEN

c:=TRUE;RETURN;

END_IF;

IF a_2*(b+10)>100 THEN

c:=TRUE;RETURN;

END_IF;

IF a_3*(b+20)>100 THEN

c:=TRUE;

END_IF;


------------------------------------------------------------------------------------------

Array Examples


variable name [subscript index]


An array is a collection of like variables. The size of an array can be defined in the Function Block variable table.

An individual variable can be accessed using the array subscript operator [ ].


The subscript index allows a specific variable within an array to be accessed. The subscript index must be either a positive literal value, an integer expression or an integer variable. The subscript index is zero based. A subscript index value of zero would access the first variable, a subscript index value of one would access the second variable and so on.


Warning

If the subscript index is either an integer expression or integer variable, you must ensure that the resulting subscript index value is within the valid index range of the array. Accessing an array with an invalid index must be avoided. Refer to Example 5 for details of how to write safer code when using variable array offsets.


Example 1

a[0] := 1;

a[1] := -2;

a[2] : = 1+2;

a[3] : = b;

a[4] : = b+1;


Example 2

c[0] := FALSE;

c[1] := 2>3;


Example 3

d[9]:= 2.0;


Example 4

a[1] := b[2];


Example 5

a[b] := 1;

a[b+1] := 1;

a[(b+c) *( d-e)] := 1;


f := (b+c) *( d-e);

IF (f >0) AND (f<5) THEN

a[f] := 1;

END_IF;

Where variable "f" has an INT data type.


Example 6

a[b[1]]:= c;

a[b[2] + 3]:= c;


http://www.contron.co.kr/ <-
콘트론 사이트


* FB
프로그램

- HEX -> ASCII
변환 (4채널 입력)

내부

INT inTemp[4]     -> 입력값 배열로 저장

INT n[35]            -> 천단위값 저장

INT i                   -> FOR 변수

INT j                   -> FOR 변수

INT nMax            -> 자릿수 최대값

INT a                  -> 계산값 배열 저장시 중복저장 방지

------------------------------------------------------------


입력

INT in1                -> #1 입력값

INT in2                -> #2 입력값

INT in3                -> #3 입력값

INT in4                -> #4 입력값

------------------------------------------------------------


출력

INT ch1U             -> #1 ,백 단위 변환 출력

INT ch1D             -> #1 ,일 단위 변환 출력

INT ch2U             -> #2 ,백 단위 변환 출력

INT ch2D             -> #2 ,일 단위 변환 출력

INT ch3U             -> #3 ,백 단위 변환 출력

INT ch3D             -> #3 ,일 단위 변환 출력

INT ch4U             -> #4 ,백 단위 변환 출력

INT ch4D             -> #4 ,일 단위 변환 출력

------------------------------------------------------------


(*
입력값 배열변수에 순차적으로 저장 *)

inTemp[0] := in1;

inTemp[1] := in2;

inTemp[2] := in3;

inTemp[3] := in4;

(* 단위별로 값 산출하여서 배열변수에 순차적으로 저장 *)

FOR i := 0 TO 3 DO 

     nMax := 1000;

     a := i * 10;

     FOR j := 0 TO 3 DO

          IF nMax <> 1 THEN

               n[j + a] := inTemp[i] / nMax;

               inTemp[i] := inTemp[i] - n[j + a] * nMax;

               nMax := nMax / 10;

          ELSE

               n[j + a] := inTemp[i];

          END_IF;

     END_FOR;

END_FOR;
(* 단위별로 산출한 값을 아스키로 변환해서 출력 *)

ch1U := (n[0] * 16#0100 + n[1]) + 16#3030;

ch1D := (n[2] * 16#0100 + n[3]) + 16#3030;

ch2U := (n[10] * 16#0100 + n[11]) + 16#3030;

ch2D := (n[12] * 16#0100 + n[13]) + 16#3030;

ch3U := (n[20] * 16#0100 + n[21]) + 16#3030;

ch3D := (n[22] * 16#0100 + n[23]) + 16#3030;

ch4U := (n[30] * 16#0100 + n[31]) + 16#3030;

ch4D := (n[32] * 16#0100 + n[33]) + 16#3030;


- ASCII ->
십진수 변환 (4채널 출력)

내부

INT inTemp[8]     -> 입력값 배열별로 저장

INT tempU[8]       -> 앞에 값을 십단위로 저장

INT tempD[8]       -> 뒤에 값을 일단위로 저장

INT temp[8]         -> 입력 CH값 십단위값으로 저장

INT a                  -> FOR문 변수
------------------------------------------------------------


입력

INT in1U              -> , 백 단위값 저장됨(CH1 상위값)

INT in1D              -> , 일 단위값 저장됨(CH1 하위값)

INT in2U              -> , 백 단위값 저장됨(CH2 상위값)

INT in2D              -> , 일 단위값 저장됨(CH2 하위값)

INT in3U              -> , 백 단위값 저장됨(CH3 상위값)

INT in3D              -> , 일 단위값 저장됨(CH3 하위값)

INT in4U              -> , 백 단위값 저장됨(CH4 상위값)

INT in4D              -> , 일 단위값 저장됨(CH4 하위값)
------------------------------------------------------------


출력

INT ch1               -> CH1 출력

INT ch2               -> CH2 출력

INT ch3               -> CH3 출력

INT ch4               -> CH4 출력
------------------------------------------------------------


(*
상위값, 하위값 별로 아스키 문자를 헥사값으로 변환*)

inTemp[0] := in1U - 16#3030;

inTemp[1] := in1D - 16#3030;

inTemp[2] := in2U - 16#3030;

inTemp[3] := in2D - 16#3030;

inTemp[4] := in3U - 16#3030;

inTemp[5] := in3D - 16#3030;

inTemp[6] := in4U - 16#3030;

inTemp[7] := in4D - 16#3030;

(*단위별로 분류*)

FOR a := 0 TO 7 DO

     tempU[a] := (inTemp[a] / 16#0100) * 16#0010;

     tempD[a] := (inTemp[a] - tempU[a] * 16#0010);

     temp[a] := tempU[a] + tempD[a];

END_FOR;

(*1워드에 값저장*)

ch1 := temp[0] * 16#0100 + temp[1];

ch2 := temp[2] * 16#0100 + temp[3];

ch3 := temp[4] * 16#0100 + temp[5];

ch4 := temp[6] * 16#0100 + temp[7];

+ Recent posts