先定義變量VAR_INPUT
D_IN1:INT;
D_IN2:INT;
D_IN3:INT;
D_IN4:INT;
D_IN5:INT;
D_IN6:INT;
END_VAR
VAR_TEMP
D_T1:REAL;
D_T2:REAL;
D_T3:REAL;
D_T4:REAL;
D_T5:REAL;
D_T6:REAL;
INDEX:INT;
END_VAR
VAR_OUTPUT
DATA_OUT:REAL;
END_VAR
寫程序:
BEGIN
IF D_IN1>47 AND D_IN1<58 THEN
D_T1:=INT_TO_REAL(D_IN1)-48.0;
END_IF;
IF D_IN1=46 THEN
INDEX:=1;
END_IF;
IF D_IN2>47 AND D_IN2<58 THEN
D_T2:=INT_TO_REAL(D_IN2)-48.0;
END_IF;
IF D_IN2=46 THEN
INDEX:=2;
END_IF;
IF D_IN3>47 AND D_IN3<58 THEN
D_T3:=INT_TO_REAL(D_IN3)-48.0;
END_IF;
IF D_IN3=46 THEN
INDEX:=3;
END_IF;
IF D_IN4>47 AND D_IN4<58 THEN
D_T4:=INT_TO_REAL(D_IN4)-48.0;
END_IF;
IF D_IN4=46 THEN
INDEX:=4;
END_IF;
IF D_IN5>47 AND D_IN5<58 THEN
D_T5:=INT_TO_REAL(D_IN5)-48.0;
END_IF;
IF D_IN5=46 THEN
INDEX:=5;
END_IF;
IF D_IN6>47 AND D_IN6<58 THEN
D_T6:=INT_TO_REAL(D_IN6)-48.0;
END_IF;
IF D_IN6=46 THEN
INDEX:=6;
END_IF;
CASE INDEX OF
1:
DATA_OUT:=D_T2*0.1+D_T3*0.01+D_T4*0.001+D_T5*0.0001+D_T6*0.00001;
2:
DATA_OUT:=D_T1+D_T3*0.1+D_T4*0.01+D_T5*0.001+D_T6*0.0001;