当前位置:网站首页>[old horse of industrial control] detailed explanation of Siemens PLC s7-300scl programming
[old horse of industrial control] detailed explanation of Siemens PLC s7-300scl programming
2022-06-29 07:43:00 【Industrial control old horse】
SCL Programming details
One . data type :
notes : There are also two types :P:POINTER( Pointer data type ).A:ANY( Any kind of )
Definition of array :M1:ARRAY[n0…m0,n1…m1] OF INT;
Two . Addressing
○1 Absolute addressing 
○2 Symbolic addressing
Such as :DB10.setpoint
“motor1data”.DW12
○3 Indirect addressing
Such as :E[byteindex,bitindex]
MB[byteindex]
DB10.DW[byteindex]
3、 ... and .SCL Operators and Expressions 
notes : The expressions of the above operators are basically the same as our mathematical expressions . I'll just explain it here AND,XOR,OR Instructions .
Such as :a1:=a1 AND W#16#FFFF
a1:=a1 XOR W#16#FFFF
a1:=a1 OR MW10
Four . Control statement 
Be careful : When using the program loop , Please ensure that the cycle monitoring time is not exceeded .
IF sentence :
IF Conditions 0
THEN sentence 0;
ELSIF Conditions 1
THEN sentence 1;
ELSIF Conditions 2
THEN sentence 2;
ELSE sentence 3;
END_IF;CASE sentence :“ choice ” The value in is equal to Const The values in the execute that statement . Other statements are not executed , Is executed END_CASE;
CASE choice OF
Const1: sentence 1;
Const2: sentence 2;
………
Constn: sentence n;
END_CASE;FOR sentence
FOR Variable :=n0 TO n BY m DO
……………………;
………………….;
END_FOR;
Be careful : there n Is an integer variable or integer value .m Add a few... To each cycle .WHILE sentence : As long as the conditions are met , The program loop repeats .
WHILE Conditions DO
sentence ;
END_WHILE;REPEAT sentence : As long as the conditions are not met , Just repeat the program cycle .
REPEAT
sentence ;
UNTIL Conditions ;
END_REPEAT;CONTINUE sentence : stay FOR, WHILE, REPEAT Terminates the current program channel in the loop .
EXIT sentence : stay FOR, WHILE, REPEAT Terminate all program channels in the loop .
RETURN sentence : Statement unconditionally exits the currently executing block .
GOTO sentence :
example :
LABEL // Define Tags
M1,M2,M3,END;
END_LABEL;
………………
CASE Selection;
1:GOTO M1;
2:GOTO M2;
3:GOTO M3;
ELSE GOTO DND;
END_CASE;
M1: sentence 1;
GOTO DND;
M2: sentence 2;
GOTO DND;
M3: sentence 3;
END: ;
5、 ... and . Constant :
Bit constant : The value is TRUE perhaps FALSE.
character constants :( Here is a character )
Charac_1:=’B’
Charac_2:=char#43;
Charac_3:=char#’B’ // character ‘B’
Charac_4:=’$41’ // character ‘A’String constant :
M1:=’ABCDEFJH’Date constant :
T1:=DATE#1995-11-11;
T2:=D#1995-11-11Time constant
N1:=TIME#10.2S;
N2:=T#3D_2S_3MS;TIME_OF_DAY Constant :
TM1:=TIME_OF_DAY#12:11:10.1;
TT2:=TOD#10:10:10;DATE_AND_TIME Constant :
TT:=DT#2012-4-26-18:12:00;
6、 ... and . Timers and counters :
1. The timer has 5 Kind of , In turn :S_PULSE S_PEXT S_ODT S_ODTS S_OFFDT
VAR
CurrTime : S5time;
BiVal : word;
ActFlag : bool;
END_VAR
// When calling the timer , Some parameters can be omitted , But the assignment variable on the left must not be omitted .
CurrTime:=S_ODT(T_N=T10, // Absolute call , Set the timer number
S:=TRUE, // Set condition
TV:=T#1s, // Set the timer value
R:=FALSE, // Reset condition
BI:=biVal,
Q:=actFlag);
FUNCTION_BLOCK TIME
VAR_INPUT
MY_TIMER: ARRAY [1…4] of STRUCT
T_N INT;
TV : WORD;
END_STRUCT;
…
END_VAR
…
FOR I:= 1 TO 4 DO
CurrTime:= S_ODT(T_N=MY_TIMER.T_NO, S:=true,
MY_TIMER.TV);
END_FOR;
FUNCTION_BLOCK TIMER
VAR_INPUT
mytimer:TIMER;
END_VAR
…
CurrTime:=S_ODT(T_N=mytimer,…);
2、 Counter
S_CU Increment counter
S_CD Minus counter
S_CUD increase / Minus counter
e.g.
S_CUD (C_N=C12, // Absolute call timer , Specify the counter number
CD:=I0.0,
CU:=I0.1,
S:=I0.2 & I0.3, // Set condition
PV:=120, // Set the counter value
R:=FALSE, // Reset condition
CV:=binVal, // Output parameters , Binary count value
Q:=actFlag); // Output parameters , Status of the counter
FUNCTION_BLOCK COUNT
VAR_INPUT
Count: ARRAY [1…4] of STRUCT
C_N INT;
PV : WORD;
END_STRUCT;
…
END_VAR
…
FOR I:= 1 TO 4 DO // Dynamic call counter
S_CD(C_N=Count.C_NO, S:=true, PV:= Count.PV);
END_FOR;
FUNCTION_BLOCK COUNTER
VAR_INPUT
MYCounter:COUNTER;
END_VAR
…
CurrVal:=S_CD(C_N=MyCounter,…); // Dynamic call counter
7、 ... and . Mathematical functions :
Trigonometric functions Logarithmic function
SIN sine EXP With e Index function for the bottom
COS cosine EXPD With 10 Index function for the bottom
TAN tangent LN Natural logarithm
Anti trigonometric function LOG With 10 Log base
ASIN Anti sine Other mathematical functions
ACOS Arccosine ABS Find the absolute value
ATAN Anyway SQR Find the square
SQRT take a square root
Example :
RESULT := ABS (-5) ; //5
RESULT := SQRT (81.0); //9
RESULT := SQR (23); //529
RESULT := EXP (4.1); //60.340 …
RESULT := EXPD (3); //1_000
PI := 3. 141 592 ;
RESULT := SIN (PI / 6) ; //0.5
8、 ... and . Shift function :
ROL、ROR、SHL、SHR
Example :
RESULT := ROL (IN:=CRC, N:=5); //CRC , Move left 5 position , The removed fill to the right space
RESULT := ROR (IN:=BYTE#2#1101_0011, N:=2); //2#1111_0100 , Move right 2 position , The removed fill to the left space
RESULT := SHL (IN:=BYTE#2#1101_0011, N:=3); //2#1001_1000 , Move left 3 position , For the spare part 0 fill
RESULT := SHR (IN:=BYTE#2#1101_0011, N:=2); //2#0011_0100 , Move right 2 position , For the spare part 0 fill
Nine .SCL block
SCL The block structure used is in exactly the same way as standard programming languages .
Be careful : No function returned by function value FC yes VOID data type .
Ten . example :
1. Sort
FUNCTION FC4:VOID
Know_How_Protect
VAR_TEMP
// Temporary Variables
loop_count:INT;
index_1:INT;
index_2:INT;
Data_Store:ARRAY[0…5] OF INT;
T :INT;
N :INT;
END_VAR
// Statement Section
// Block Parameters
VAR_INPUT // Input Parameters
INT0:INT;
INT1:INT;
INT2:INT;
INT3:INT;
INT4:INT;
INT5:INT;
END_VAR
VAR_IN_OUT
// I/O Parameters
END_VAR
VAR_OUTPUT
// Output Parameters
min_data:INT;
l_0,l_1,l_2,l_3,l_4,l_5: INT;
END_VAR
Data_Store[0]:=INT0;
Data_Store[1]:=INT1;
Data_Store[2]:=INT2;
Data_Store[3]:=INT3;
Data_Store[4]:=INT4;
Data_Store[5]:=INT5;
min_data:=Data_Store[0];
N:=0;
T:=0;
FOR loop_count:=0 TO 5 BY 1 DO
// Find minimum
IF min_data > Data_Store[loop_count] THEN min_data:=Data_Store[loop_count];
END_IF;
END_FOR;
FOR index_1:=0 TO 5 BY 1 DO
FOR index_2:=index_1 TO 5 BY 1 DO
IF Data_Store[index_1] < Data_Store[index_2] THEN
T:=Data_Store[index_2];
Data_Store[index_2]:=Data_Store[index_1];
Data_Store[index_1]:=T;
END_IF;
END_FOR;
END_FOR;
l_0:=Data_Store[0];
l_1:=Data_Store[1];
l_2:=Data_Store[2];
l_3:=Data_Store[3];
l_4:=Data_Store[4];
l_5:=Data_Store[5];
END_FUNCTION
2. seek RTU To verify :
FUNCTION FC101 : VOID
//RTU signal communication SCL Program
// Block Parameters
VAR_INPUT
// Input Parameters
ZH:BYTE;// Station No
GNM:BYTE;// Function code
SZDZ1:BYTE;// Data address 1
SZDZ2:BYTE;// Data address 2
SZNR1:BYTE;// The data content 1
SZNR2:BYTE;// The data content 2
END_VAR
VAR_IN_OUT
// I/O Parameters
END_VAR
VAR_OUTPUT
// Output Parameters
SCZH:BYTE;// Station No
SCGNM:BYTE;// Function code
SCSZDZ1:BYTE;// Data address 1
SCSZDZ2:BYTE;// Data address 2
SCSZNR1:BYTE;// The data content 1
SCSZNR2:BYTE;// The data content 2
XYM1:BYTE;// To verify 1
XYM2:BYTE;// To verify 2
END_VAR
VAR_TEMP
// Temporary Variables
CRC:WORD;
SHUZU:ARRAY[0…7]OF BYTE;// Array
N:INT;// Outer loop 6 Time
M:INT;// Inner loop 8 Time
ZZ:INT;// Array pointer
YCW:WORD;//CRC When shifting right , Judge the last .
TEM:WORD;// Used as a CRC The final result is high 8 Bit and low 8 Separate transmission of bits .
END_VAR
BEGIN
// Statement Section
ZZ:=0;// Clear the pointer
TEM:=0;// Zero clearing
SHUZU[0]:=ZH;// Send the entered station number to the array 0 position
SHUZU[1]:=GNM;// Send the entered function code to the... Of the array 1 position
SHUZU[2]:=SZDZ1;// The data address to be entered 1 To the array 2 position
SHUZU[3]:=SZDZ2;// The data address to be entered 2 To the array 3 position
SHUZU[4]:=SZNR1;// The data content to be entered 1 To the array 4 position
SHUZU[5]:=SZNR2;// The data content to be entered 2 To the array 5 position
CRC:=W#16#FFFF;// take 16#FFFF Send CRC register
FOR N:=0 TO 5 BY 1 DO// Outer loop 6 Time
CRC:=CRC XOR SHUZU[ZZ];// take CRC Register and bytes exclusive or
FOR M:=0 TO 7 BY 1 DO// Inner loop 8 Time
YCW:=CRC;// take CRC The contents of the register are sent to YCW in
YCW:=YCW AND W#16#0001;
// take CRC The last bit of the register , That is, the overflow bit of the following shift
CRC:=SHR(IN:=CRC,N:=1);// Yes CRC Shift the register one bit to the right
IF YCW=W#16#0001 THEN CRC:=CRC XOR W#16#A001;
// Determine whether the overflow bit is 1, yes 1 will CRC Register and 16#A001 Exclusive or .
END_IF;
END_FOR;
ZZ:=ZZ+1; // One byte is processed , Array pointer plus 1.
END_FOR;
TEM:=CRC;// take CRC Content in to TEM
TEM:=TEM AND W#16#00FF;// take TEM(CRC) It's low 8 position
SHUZU[6]:=WORD_TO_BYTE(TEM);// take TEM low 8 Bit to array 6 No. A
TEM:=CRC;// then CRC Content in to TEM
TEM:=TEM AND W#16#FF00;// take TEM(CRC) The height of 8 position
TEM:=SHR(IN:=TEM,N:=8);// Re high 8 Shift right 8 position
SHUZU[7]:=WORD_TO_BYTE(TEM);// Will be high 8 The contents of bits are sent to the 7 No. A
SCZH:=SHUZU[0];// Output station No
SCGNM:=SHUZU[1];// Output function code
SCSZDZ1:=SHUZU[2];// Output data address 1
SCSZDZ2:=SHUZU[3];// Output data address 2
SCSZNR1:=SHUZU[4];// Output data content 1
SCSZNR2:=SHUZU[5];// Output data content 2
XYM1:=SHUZU[6];// Output validation code
XYM2:=SHUZU[7];// Output validation code
END_FUNCTION
边栏推荐
- matlab 多普勒效应产生振动信号和处理
- 服裝行業的CRM品牌供應商如何選型?
- Roblox剑九之剑二
- 4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
- Vibration signal generation and processing based on MATLAB Doppler effect
- From XX import* is equivalent to from XX import *, and no space is required
- Use of LSTM neural network and general neural network
- Wechat applet learning notes (summer vacation)
- 【工控老马】洗衣机PLC程序控制系统设计详解
- 498. 对角线遍历(模拟)
猜你喜欢
随机推荐
A hybrid model of machine learning notes time series
tf.count_nonzero
Golang modifying the value of a structure slice
Kingbasees v8r6 cluster maintenance case - data migration between clusters
Markdown skill tree (9): tables
MFC中利用CDockablePane实现悬浮窗
358. K 距离间隔重排字符串 排序
解题-->在线OJ(十三)
JMeter can't find its own jar package imported by BeanShell
KingbaseES应对表年龄增长过快导致事务回卷
4 years of working experience, and you can't tell the five communication modes between multithreads. Can you believe it?
施努卡:什么是视觉定位系统 视觉定位系统的工作原理
Markdown skill tree (8): code blocks
Use of LSTM neural network and general neural network
Loop nesting: why can large loops inside and small loops outside improve the running efficiency of programs
路由详解(九阳真经)
Deploy Prometheus server service system management
Markdown skill tree (1): introduction to markdown
Dump (cl\alv\tree\base================================cp|set\items\for\column) when expanding node or clicking toolbar button
服裝行業的CRM品牌供應商如何選型?








