Manual PLC Samkoon
Manual PLC Samkoon
1
Quick Start
What is SamSoar II
SamSoarII is a visual programming application for the programming logic component (PLC)
issued by the Shenzhen Samkoon Cooperation. This application help to edit a PLC project quickly
and easily. It supports the edition of the ladder program and function block.
It supports to edit ladder by mouse, toolbar, keyboard inputting and double clicking or dragging
the instruction item from the project explorer. It supports the auto-tab, code completion and other
User can enter one of those modes: Editor mode, monitor mode and simulation mode. The editor
mode support to normally edit, modify, and convert ladder program; Monitor mode supports
monitor and modification of registers in PLC. Under simulation mode users can simulate a PLC
program processing.
The program can be downloaded and uploaded with a serial port or USB communication. Before
uploading, downloading, and monitor, test the communication to ensure that PLC is connected to
the computer. The serial port’s parameters can also be automatically detected.
It supports the automatic saving at every interval time, user can set it in system setting to safely
The project is protected strictly in the download and upload procedure, user can set the password
2
System requirement
This application is supported in Windows XP,Windows 7,Windows 8, and Windows 10 32bit or
64-bit operation system, with .NET Framework 4.0 and DirectX 9.0 or later version.
What should be noted is, the computer must have .NET Framework 4.0 or later version, otherwise
it refuses to install (uninstall the .NET Framework 4.0 will cause this application out of work).
The .NET Framework 4.0 setup package will be contained after installation (in the directory
DotNetFX40), User can install it manually. If the package is lost or moved to another path, the
user can visit the website of Microsoft to search and download the corresponding setup package.
For Windows XP, the image process program wic_x86_chs.exe is also required to install the .NET
Framework. It is contained in the installation package as well, and the installation will
1. Execute the setup program, select language, and click [Next >], as Figure 1.1 shows.
Figure 1. 1
2. Select the location to install the application. Make sure your free disk space is enough to
store this application, otherwise the installation will be failed. The default path is
3
“C:\Program Files (x86)\SamSoarII”, user can select the path as need. Then click [Next >].
Figure 1. 2
3. Select start menu folder and addition tasks, user can also skip it and click [Next >].
Figure 1. 3
Figure 1. 4
4
4. Setup is ready, check and click [Install] to install.
Figure 1. 5
5. Wait the installation processing.
Figure 1. 6
6. Installation completed, click [Finish] to end.
5
Figure 1. 7
Uninstall of application
1. Find uninstall program in start menu or install directory, and execute it.
Figure 1. 8 Figure 1. 9
Figure 1. 10
Figure 1. 11
4. Uninstall completed.
6
Base operation
Mouse operation
⚫ Left click
Left click to select menu, select ladder object, select tool button, and confirm the setting.
⚫ Left double-click
Left double-click on the object in the edition area to display modification dialog, so that the
user can modify the parameters of the corresponding soft component or instruction.
⚫ Right click
Hotkey
Table 1.1 lists some hotkey that be frequently used, to convenient the operation.
Ctrl+Mouse wheel down Screen scale down Shift+Mouse left Multiple selection
Table 1. 1
7
Use keyboard instead of mouse
1. Press the alt key on the keyboard, to focus on the menu bar. With the deep blue color filled
the first item, means that item it is be focused, and move the focus by left and right key on
the keyboard, enter or down key to open the context menu of the focused item. As a matter of
fact, the alpha in brackets shows each hotkey of items, press the hotkey works as well to
Figure 1. 12
2. In a similar way, while editing ladder program, press the menu key (between the right Alt key
and right Ctrl key, a shape of menu paper), then open the context menu, it can be controlled
Figure 1. 13
8
Three-key system
This application supports not only the custom hotkeys, but also the system of three-key. As Figure
1.14.
Figure 1. 14
Take checking ladder program as an example: Firstly, press ctrl + T (Release once after pressed),
and the message board of main window will hint the message, as Figure 1.15.
Figure 1. 15
Then press N Key, checking ladder program will processing, user can also move cursor to the
message board and hold to call out the hint. The supported three-key refer to following table:
Change language to
Ctrl+F1,O Show project explorer Ctrl+E,M Monitor Ctrl+U,C
Chinese
Ctrl+F2,O Show soft component list Ctrl+T,E Return to edit Ctrl+U,E Change language to
9
English
Ctrl+F4,O Show monitor list Ctrl+T,F Check function block Ctrl+F10,O Show the help document
Expansion module
Ctrl+F8,O Show breakpoint list Ctrl+T,C Ctrl+F1,A Insert row before
detect
Table 1. 2
Usage example
Build a new project
Click [File] -> [New project] from the menu bar.
Figure 1. 16
Display the new project setting dialog, select and fill the configuration if needed. This example
Open a project
User can also open an existing project, the project file name must be end with “ssr” suffixes. Click
Figure 1. 18
To be compatible with old SamSoar version, user can use file conversion function to convert old
version project file (end with “ssp”) to new version (end with “ssr”). Click [Tool] -> [File
Figure 1. 19
11
Project edition
In the edition area, users can do an operation like insert a network, inset a row, delete a network,
delete a row, and so on. Theses operation can be executed by clicking the icon in the toolbar, by
right clicking to display pull-down menu and select operation, or by using hotkeys.
Additionally, user can add instruction from double click one item in the instruction directory.
Figure 1. 20
User can also use instruction list to edit the ladder diagram by input instruction sentence. For
Figure 1. 21
and search or replace one or more instruction in the program. More details refer to Search and
Replace.
12
Soft component initialization
Select the [View] -> [Soft component initialize], or click the icon on the toolbar, to open the
window to set the initialization of the soft components. More details refer to Soft component
initialization.
window and look up all the soft components, and modify the alias and comment of the soft
Instruction list
Click the icon in the toolbar, to open the instruction list of the current ladder diagram. The ladder
Generally, the instruction list is not be updated as soon as the ladder changed, click the instruction
list to update, or setting the “Automatically update instruction list” to automatically update.
Comment mode
Click the [Comment mode] button in the toolbar, to display the comment of each instruction in the
ladder. Please notice that, do not make the comment too large, otherwise the excess part will be
hidden.
subroutine or build a new empty folder. Double click the created one to add it to the ladder editor.
function block or build a new folder. More details refer to “Build a function block”.
Download project
After edition, select the [Tool] -> [Download] on the menu bar, or click the download icon in the
13
Figure 1. 22
It supports three ways to download, COM (serial-port), USB and net (ether network). It requires
the serial-port parameters to be configured while using COM, user can modify it or detect it
automatically.
The download data parts can be selected or removed if needed. The [Program] always should be
checked if the user needs to download the program. The [Setting] should be checked if the user
needs to apply the PLC setting. The [Initialize] should be checked if the user wants to initialize the
Before download, click [Communication test] to test the communication. If the communication
works, it will show the message box to hint success, like the following figure.
Figure 1. 23
Upload project
Select [Tool] -> [Upload] in the menu bar, or click the upload button in the toolbar, to display the
upload dialog, as following figure. User can upload the project that last downloaded to the PLC.
14
Figure 1. 24
Application interface
Menu bar
The menu locates top on the interface, as following figure.
Figure 2. 1
File (F)
Figure 2. 2
15
⚫ Recent Project:Look recently opened files, and choose one to open.
Edit (E)
Figure 2. 3
⚫ Undo: Undo the last editing operation. Notice that it cannot to undo after the operations
below:
Check, compile, simulate or monitor the ladder program. Switch PLC device. Save, close,
⚫ Search: Search instruction or soft component in the ladder program, or search keyword in
text.
⚫ Replace: Replace instruction or soft component in the ladder program, or replace a word in
text.
16
View (V)
Figure 2. 4
⚫ Comment Mode: Show or hide the comment of soft component in the current ladder
program.
⚫ Soft component List: Look up and edit the information of the soft components.
⚫ Soft component Initialization: Setting the initial value of the soft components when PLC
run.
⚫ Error List: Check the ladder programs and function blocks, report all the errors.
⚫ Monitor List: Monitor soft component value, and write the new value back. Notice that it
⚫ Breakpoint List: Can only be displayed under simulate mode. It sets the breakpoint at
instruction or function block, the simulation will be automatically paused at this breakpoint,
⚫ Element Breakpoint: Can only be displayed under simulate mode. It sets the break condition
expression of the soft component, simulation will be automatically paused while the
17
Project (P)
Figure 2. 5
⚫ Add SubRoutine: The application will create a new subroutine in the path [Project Explorer]
-> [Project] -> [Routines] -> [Subroutine], with the default name “New_routine”. If the
subroutine with the same name already exists, it will append the rename index after the
default name. Users can also rename the subroutine after created.
⚫ Add Modbus Table: Display dialog to finish the creating of a new MODBUS table.
⚫ PLC parameter setting: Display the dialog to configure the parameters of PLC.
Tool (T)
Figure 2. 6
⚫ Simulate: The application will enter the simulation mode after clicked. The simulation will
simulate the PLC running. What should be noted is, simulation does not supports the pulse
18
output, communication, and the high counter.
⚫ Monitor: The application will enter the monitor mode after clicked. The monitor can read
⚫ Return to Edit Mode: Can only be used under simulation mode or monitor mode, click to
⚫ Compile: Check the correction of all the project, make sure that all part of the project is
correct. The errors will be detected and reported in the error list.
⚫ Program Check: Check the correction of all the ladder programs and function blocks.
⚫ File conversion: Convert the project file of SamSoar (1st generation application) to the
⚫ PLC Reset: Clear the program and data of the connected PLC, reset it to the status first
⚫ System setting: Display the dialog to configure the programming style and view style.
Pulse (Y)
Figure 2. 7
⚫ DXF Import: Display dialog to import and manage the CAD graph.
Language (Y)
Figure 2. 8
19
Help(H)
Figure 2. 9
Toolbar
Standard toolbar
Standard toolbar contains a group of basic operation for the project, such as build new project,
open existing project, save and other editor command such as cut, copy, paste and so on.
Upload: Display the dialog to upload the program and data from PLC.
20
Ladder diagram: Display or hide the ladder program window.
Soft component list: Display or hide the soft component list window.
Edit toolbar
This toolbar contains program units and edition operations frequently used.
NO contact: Insert a normally open contact element in the selected position of ladder
Immediate NO contact: Insert an immediate normally open contact element in the selected
position of ladder diagram (refer to LDIM instruction in the instruction manual). Hotkey is
shift+F2.
NC contact: Insert a normally close contact element in the selected position of ladder
position of ladder diagram (refer to LDIIM instruction in the instruction manual). Hotkey is
shift+F3.
Rising-edge pulse: Insert a rising-edge pulse element in the selected position of ladder
Falling-edge pulse: Insert a falling-edge pulse element in the selected position of ladder
ladder diagram (refer to MEP instruction in the instruction manual). Hotkey is shift+F5.
ladder diagram (refer to MEF instruction in the instruction manual). Hotkey is shift+F6.
Inversion: Insert an inversion element in the selected position of ladder diagram (refer to
Output: Insert an output element in the selected position of ladder diagram (refer to OUT
Immediate output: Insert an immediate output element in the selected position of ladder
Transverse connection line: Insert a transverse connection line in selected position of ladder
Vertical connection line: Insert a vertical connection line in the selected position of ladder
Delete transverse connection line: Delete a transverse connection line in selected position
Delete vertical connection line: Delete a vertical connection line in the selected position of
22
Network insert: Insert a network in the selected position of ladder diagram.
Search
Search in ladder diagram
While editing ladder diagram, user can click [Edit]->[Search] to display the search window, as
follow figure.
Figure 2. 10
Users can select search scope: current routine or all routines. Double-clicking on the result will
User can also search instruction, single soft component, soft component range, a name by
⚫ Instruction
Search soft component by inputting keywords like “D[0..2]”, “K[1.5..5]”. “D[0..2]” means
searching D0, D1, D2; “K[1.5..5]” means searching a constant value from K1.5 to K5.
⚫ Name
23
Search name of the routine, function block, and MODBUS table.
⚫ Combination
Search combination of items above, and character “*” can match any pattern, for instance:
“M0V[0..10]” means searching soft components range from M0V0 to M0V10; “LD *”
means searching any LD instruction; “ADD * * D0” means searching ADD instruction that
figure.
Figure 2. 11
24
Figure 2. 12
“Use Regular Expression” means user can use regular expression to match the searching target.
“Ignore Case” means the searching will ignore if the searching target is upper case or lower case.
Replace
Replace in ladder diagram
While editing ladder diagram, user can click [Edit]->[Replace] to display the replace dialog, as
following figure.
Figure 2. 13
The rules of search part refer to the introduction above. Double-clicking on the searched result
will execute the replacement of clicked one with input replacement content, user can also use
Ctrl+LeftClick to check or uncheck the results, and click [Replace] to execute the replacement.
25
Clicking [Replace] without checking will replace all the searching results.
1. Normally, the replacement happens in a definite part. For instance, the replacement content is
“ADD D0 * D[10..20]”, if the replaced target is “SUB K2 K1 D5”, the result of replacement
will be “ADD D0 K1 D10”, because the only item “ADD”, “D0” and “D[10..20]” is definite,
2. The searching target and replacement content must be consistent. For instance, the searching
keyword is “D0”, and the replacement content is “D1”, the searching results “LD D0.8” and
3. User can add ‘$’ before the address of the soft component, means force replacement to the
specified format, regardless of what format the original address was, like internal offset
(“D0V0”), word split to bit (“D0.0”), or bit combine to word (“K16M0”). For instance,
searching target is “D0”, replacement content is “$D1”, and searching result “MOV K10
D0V0” will be replaced to “MOV K10 D1”, the “V0” will be removed. Otherwise, if the
replacement content is “D1”, the result will be replaced as “MOV K10 D1V0”.
4. If the searching target is a soft component range, like “M[0..2]”, the replacement content
must be same type soft component range with the same length.
5. If the searching target is instruction and its arguments, and replacement content is also
instruction and its arguments, then the arguments must be typed consistent, otherwise the
replacement will fail. For instance, “ADD D0 D[0..2] D10” be replaced to “SUB D0
When replacement fails, the error report will occur with error reason.
26
Figure 2. 14
following figure.
Figure 2. 15
27
Soft component manager
Click [View]->[Soft component manager] to display the window, as following figure.
Figure 2. 16
⚫ [Select Component Range]: User can use this list to select which kind of soft component to
manage.
⚫ [Display Details]: If this option is checked, details (location, usage in the ladder) of the soft
Figure 2. 17
⚫ [Only Show Used Component]: Soft component not be used in the diagram will be hidden.
⚫ [Only Show Annotated Component]: Soft component not be annotated in the diagram will be
28
hidden.
⚫ [Import CSV]: Import external a CSV file to replace the component table.
⚫ [Export CSV]: Export the component table and save as CSV file.
Figure 2. 18
unselect).
⚫ [Load from PLC]: Upload the initialization table in PLC to replace the current one.
Notice the range of different data types when setting the initialization value.
29
WORD -32768~32767 BCD 0~9999
Table 2. 1
Error List
Click [View]->[Error List] to display the window, as following figure.
Figure 2. 19
Users can check the ladder diagram and function block by clicking [Tool]->[Program Check], and
the errors will be listed in the error list. Error may also be listed when the user compiles the
program.
By double clicking the error listed in the error list, it can navigate to the error position in the
30
Monitor List
Click the [View] -> [Monitor List] to open the window, as following figure. The monitor only
Figure 2. 20
or all component table, or export selected table and save as a CSV file.
Figure 2. 21
When adding component automatically, user can select the routine scope of components to add.
The system will add all components that selected routines contain.
31
Figure 2. 22
When adding a component manually, the user can use [Component Address] and [Data Type] to
add single component. User can also add multiple components by checking [Batch], and use offset
Figure 2. 23
by clicking [Monitor Start]. The component list will display the value of all the added components.
Users can modify the value of the component online by double-clicking the selected one.
Figure 2. 24
User can also modify value of components to set value in batch by right click in the component
Device model
Figure 2. 26
Users can select the model of PLC, and some specific instructions can only be applied in the
specific models. The system will also detect and switch the model automatically when
Figure 2. 27
Users can set parameters of each communication port of PLC. Refer to communication
⚫ [Baud Rate]: Frequency of data signal, the unit is baud (length of a single character, always
be 1 byte) per second, can be set with 1200, 2400, 4800, 9600, 19200, 38400, 57600, or
⚫ [Stop Bit]: Length of a stop signal, marks the end of one data frame.
⚫ [Check Bit]: Bit that locates after data bit, can be set with none, even, or odds. If none, there
is no check bit; If even, check bit is 1 if there are even a number of high-level signals in data
bit; If odds, check bit is 1 if there are odds number of high-level signals in the data bit.
⚫ [Buffer Bit]: Can be selected with 8 or 16, if it is selected with 8, the receiver will save
message only in low-byte of data register; If it is selected with 16, the receiver will save
station, the devices in same communication network must be set with different station
number.
⚫ [Timeout] and [Retransmission times]: If the slave doesn’t return the message for the set
timeout, the master will resend data, reset timeout, and wait for a return message from slave.
If reach the set retransmission times,the master will report error code 0x10 in specified
34
data-register.
Password setting
Figure 2. 28
⚫ [Upload Encryption]: Setting the upload password, user need to input the password to upload.
⚫ [Download Encryption]: Setting the download password, user need to input password to
download.
⚫ [Monitor Encryption]: Setting the monitor password, user need to input password to monitor
Figure 2. 29
Data in retentive zone is retentive after PLC power off (data out of it will be cleared). User can set
the retentive zone for M/D/S/CV type register, the retentive range is M7488~M7999,
Figure 2. 30
Filter Setting
Figure 2. 31
For the [Filter mode] option, user can select [Disable], [Unified mode], and [Other].
⚫ [Unified mode]: User can select [Filter time] as filter time for all X input ports.
⚫ [Other]: User can set filter time for each X input port.
Additionally, for FGm series, the user can enable hardware filtering, and select [Frequency
The base frequency of FGm series PLC is 50MHz, user can select the frequency division factor to
divide the base frequency as the sampling frequency of the input signal. The PLC will accept the
Note that don’t set the frequency division factor too high when the frequency of input signal is
high, otherwise the sampling will be erroneous. When the frequency of the input signal reaches
the high limit 500kHz, the user should set a frequency division factor on more than 6
(50MHz/(500kHz*8*2)≈6).
Other
Figure 2. 33
⚫ Realtime setting
User can enable the real-time clock error detection by checking [Whether to enable real-time
clock error detection]. When a real-time error occurs, the PLC will stop running, enter
ERROR state, and system special function register D8176 will report error code 0x09.
Users can set the format of a real-time clock with selection BCD code and BIN code (refer to
⚫ Watchdog setting
Users can enable the watch-dog by checking [Whether to enable watchdog], and set the target
time of the watch-dog timer. When timing of watch-dog timer reaches the target time, PLC
37
will stop running, enter ERROR state, and system special function register D8176 will report
error code 0x0A. Users can reset the watch-dog by using WDT instruction.
The time limit for PLC to judge if it is powered down. If duration of low power supply
exceeds the set time, PLC will enter power-down mode and save data in the retentive zone.
When the power supply is unstable, the user can increase the detection time properly.
What should be noted is, when the detection time is set too high, the retentive zone may not
take effect.
System setting
Click [Tool]->[System setting], or click in the toolbar to display the system setting dialog.
Figure 2. 34
Font setting
⚫ [Font Scope]: User can select font of which scope to set.
38
Figure 2. 35
Other setting
Figure 2. 36
⚫ [Autosave]: User can set time interval for autosave, the project will be saved after each set
⚫ [Auto Update]: Users can set time intervals for auto-updating of instruction table, the time
unit is second.
⚫ [Element Presentation]: Element uses double data registers will be shown the two registers
number (such as “D10D12”) when option [Showing element uses double registers] is
checked; Element will be showed alias instead (such as “M8151” is instead with “RN1”)
when option [Showing alias instead of original name] is checked; Concentrate the comments
⚫ [Ladder Checking]: Prohibit multiple outputs of the same coil in one program when option
[Check the multi-coil output] is checked; Prohibit multiple uses of the same timer in one
program when option [Check multiple timers] is checked; Prohibit multiple uses of same
39
counter in one program when option [Check multiple counters] is checked. If these options
are checked, the prohibition uses will cause errors when checking the program.
Figure 2. 37
⚫ [Convenience Setting]: Insert new network automatically when editing the last network of the
ladder when option [Auto Generate New Network] is checked; Insert new row automatically
when editing the last row of the network when option [Auto Generate New Line] is checked.
Communication setting
Click in the toolbar to display the dialog of communication setting, as following figure.
Figure 2. 38
Under USB connection mode, the user can immediately test communication while the USB port is
connected. Under Com connection mode, the user can check option [Manual] to set the
communication parameters manually, or check option [Auto Check] to detect the parameters
automatically.
40
Figure 2. 39:
If the communication test successes, the hint dialog will display as following figure:
Figure 2. 40
If the communication test fails, the hint dialog will display as following figure:
Figure 2. 41
Project comparison
Click [View]->[Project Comparison] or in the toolbar to display the project comparation
41
Figure 2. 42
This function compares differences between two projects, and can only be used under edition
mode. Users can click to open existing project files or click to upload the project from
User can select the ladder diagram, function block, Modbus table, and PLC setting to compare.
Different parts will be highlighted green in the editing project to compare, and highlighted red in
What should be noted is, the comparison result won’t update when the user edits the project to
42
Variable tendency curve
Click [View]->[Variable Tendency] or icon to display the variable tendency curve page,
Figure 2. 43
Figure 2. 44
User can check option [Intra Address] to use address offset, and check option [Batch] to add
User can select single added variable by Ctrl+LeftClick, select multiple added variables by
43
Figure 2. 45
option [Showed] in the variable list. The curves will be shown in the window with different colors
and tags for a different variables, the x-axis means time, and the y-axis means value of a variable.
Figure 2. 46
What should be noted is, the display only support at most 8 curves.
44
Move and scale the viewport
When move the cursor to the axis area, the control bar will be highlighted, users can drag the
position and ends of the control bar to move and scale the viewport of the curve display, as the
following figure shows. Users can also wheel-up/wheel-down mouse to scale the coordinates.
Figure 2. 47
lock the viewport by click icon in the variable list, so that user can adjust the viewport
freely.
45
Usage of soft component
Soft component is operation target of ladder program, following table shows brief introduction of
TV Timer. 2-byte
Table 3. 1
Format
The format of divided bits is “Dm.n”. “n” is a hexadecimal number, it indicates the position of
divided bit, and the range of it is 0~F, refer to the following figure.
46
Figure 3. 1
Example
Instruction table:
Network 000
LD D1.1 //get the 2nd bit (from low to high) of D1
OUT D2.2 //write the bit value into 3rd position bit (from low to high) of D2.
Ladder diagram:
Figure 3. 2
Bit string
The 1-bit type soft component X/Y/M/S can be merged into a bit string.
Format
The format of the merged bit string is “KnMm”, “n” is an integer, it means the length of the bit
string. When using 16-bit instruction, the range of n is 1~16; When using 32-bit instruction, the
range of n is 1~32. “Mm” is the start lowest address of the bit string. Refer to the following for
more details.
Figure 3. 3
47
Example
1. Bit string as read address
Instruction table:
Network 000
LD M0
MOV K5Y0 D0 //the lacking bits of K5Y0 will be regarded as 0
Ladder diagram:
Figure 3. 4
Instruction table:
Network 000
LD M0
MOV D0 K5Y0 //the redundant bits of D0 won’t be written
Ladder diagram:
Figure 3. 5
Local variable
Local variable is a kind of special soft element, it means a specified variable, and only take effects
Format
Data type Format initialization
BOOL LBxxx, “xxx” can be any length string consisted of number, alphabet, and underline. OFF
WORD LWxxx, “xxx” can be any length string consisted of number, alphabet, and underline. 0
DWORD LDxxx, “xxx” can be any length string consisted of number, alphabet, and underline. 0
FLOAT LFxxx, “xxx” can be any length string consisted of number, alphabet, and underline. 0.0
Table 3. 2
48
Local variable can be name freely, and the name is the unique identifier of the variable.
Example
Instruction table:
Network 001
LD M0
OUT LBaa //value of LBaa is same as M0
MOV K10 LWba //assign LWba with K10
MOV K20 LW12 //assign LB12 with K20
POP
Network 001
LD M0
AW< LWba LW12
SET Y0 K1 //Set Y0 to ON when value of LWba is less than value of LW12
POP
Ladder diagram:
Figure 3. 6
Routine argument
Click [View]->[Routine argument] or icon in the toolbar to display the routine argument
Figure 3. 7
49
Users can add, delete, and move arguments in the list. The data type of arguments can be BOOL,
WORD, DWORD, and FLOAT. Users can set the read-write access of each argument, the
argument cannot be used as an input argument in an instruction, shown as the following figure.
Figure 3. 8
The routine arguments can only be defined in subroutine, user must bind them to soft component
Figure 3. 9
Refer to the example in the figure above, argument ARG0 is bound to K10, argument ARG1 is
bound to D10. Argument ARG0 will be a constant value 10 in the subroutine, argument ARG1
One routine argument can also be bound to divided bit, bit string, local variable, and other routine
arguments in same routine. Casually, the binding rule refers to the following table.
type access
BOOL R X/Y/S/M/C/T bit soft component, divided bit from D/V/Z bit soft component, bit local variable
BOOL W or Y/S/M/C/T bit soft component, divided bit from D/V/Z bit soft component, bit local variable (LBxxx),
50
WORD R K/H constant, D/CV/TV/AI/AO/V/Z word soft component, bit string merged by X/Y/S/M/C/T bit soft
component, word local variable (LWxxx), and other R or R/W word argument in same routine.
WORD W or D/CV/TV/AI/AO/V/Z word soft component, bit string merged by Y/S/M/C/T bit soft component, word
R/W local variable (LWxxx), and other W or R/W word argument in same routine.
DWORD R K/H constant, D/CV word soft component, bit string merged by X/Y/S/M/C/T bit soft component,
dword local variable (LDxxx), and other R or R/W dword argument in same routine.
DWORD W or D/CV word soft component, bit string merged by Y/S/M/C/T bit soft component, dword local variable
FLOAT R K constant, D float soft component, float local variable (LFxxx), and other R or R/W float argument in
same routine.
FLOAT W or D float soft component, float local variable (LFxxx), and other R or R/W float argument in same
R/W routine.
Table 3. 3
Execution logic
When a subroutine is called, it executes as following procedures:
1. Read the value of the bound target, and write the value to the readable routine argument.
2. Execute the routine. During the execution, only the argument is handled, the bound target is
separated from the argument, value change of the argument doesn’t influence the bound
target.
3. Read the value of the routine argument, and write back the value to the bound target.
Special case
There are special cases that the bound target is handled during routine execution:
1. Use argument as a timer in timer instruction (TON, TOF, TONR). In this case, the bound
2. Use argument as a counter in counter instruction (CTU, CTD, CTUD). In this case, the
3. Use argument as pulse output or pulse direction in pulse instruction. In this case, the bound
51
target can only be Y soft component.
Integer
Integer value includes integer constant value and integer variable value. In the C Programming,
Integer constant
Notation of integer constant has following 3 forms:
⚫ The octal number must start with 0, let 0 as the prefix of the whole number. The range of a
digit is 0~7. The octal number usually an unsigned integer. The following shows legal and illegal
octal numbers:
illegal: 256 (No 0 as prefix) 03A2 (‘A’ appears) -0127 (‘-’ appears)
⚫ The hexadecimal must start with 0X or 0x. The range of a digit is 0~9,A~F or a~f. The
⚫ The decimal number only digits combined, every digit from 0 to 9. The following shows
The program identifies the number system by prefix, make sure the prefix is correct otherwise it
52
Integer variable
The integer variables are distributed to the following types:
⚫ Normal integer: The name of the data type is ‘int’,occupies 4 bytes in memory, the value is
⚫ Short: The name of the data type is ‘short’,occupies 2 bytes in memory, the value is a
⚫ Long: The name of the data type is ‘long’,occupies 8 bytes in memory, the value is a normal
The unsigned cooperates with the three integer types described above:
The bytes occupied of the unsigned integer is equal with its signed version. No signal bit to
support the negative number. Here list the value dimension and bytes occupied of the integer data
short -32768~32767 ■■
Table 4. 1
53
unsigned p, q; //p and q are unsigned integer
54
Follow the rules while declaring:
1) It allows declaring two or more variables after the same data type. The variables are divided
with a comma (‘,’), data type and variables are divided with at least one space (‘ ’).
2) The end of the variable declaration must be semicolon (‘;’).
3) A variable can be used until its declaration completed. The declaration probably locates in
front of the function content.\
Example refer to the following codes:
int a, b;
short c;
short d = 100;
a = d - 20;
b = a + d;
c = a + b + d;
d = d - a + c - b;
Real constant
Real constant (float or double), in the C Programming, can only be declared with a decimal
⚫ Notation with digit only, consists of 0~9 and dot. Such as “0.0”, “.25”, “5.789”, “0.13”, “5.0”,
⚫ Notation with exponent, consists with a number (mantissa) and exponent part (‘e’ or ‘E’ and
the power of 10). The custom format is: “a E n” (‘a’ is mantissa, ‘n’ is power of 10). the value
E7 (no mantissa) 53.-E3 (dot locate wrong) 2.7E (no power of 10)
The C Programming allow to use suffix to identified a constant as a float, add suffix ‘f’ or ‘F’
Real variable
The real variables contain single accuracy type (float) and double accuracy type (double). The
float occupies 4 bytes and the double occupies 8. The value range of float is 3.4E-38~
float a = 32;
float b;
double d;
b = 12345678;
d = b * 100;
d = d + a;
d = d + 58.123456;
Char value
Char value contains char constant and char variable.
Char constant is surrounded with simple quotation, such as 'a', 'b', '=', '+', '?' is correct char. In the
⚫ Char constant is surrounded with simple quotation, cannot use double quotation or other
brackets.
⚫ Char constant can be any char in the char set, but the digit once defined as char, it cannot
directly take part in the calculation of integer. For instance, '5' and 5 is different, 5+5 is equal
Char variable
The value of char variable is char constant, as well as one char. The name of data type is ‘char’
itself. The declaration rules is same as integer and real variable. For instance:
Every char variable occupies only one byte in the memory, one-byte stores one char. The byte
stores the ASCII code of a char. For instance, the ASCII code of char ‘x’ is 120, ‘y’ is 121. Assign
The binary remaps of memory of a (byte 120) and b (byte 121) as the following shows:
a 0 1 1 1 1 0 0 0
b 0 1 1 1 1 0 0 1
The char variable can also be used as one-byte integer. C Programming allows to assign a char
String constant
The string constant is a sequence of chars surrounds with double quotation, string constant likes
"CHINA", "C program:", and "$12.5" are all legal. The string and char are different, the
differences are:
1. The char constant surrounds with single quotation, string surrounds double quotation.
3. It is possible to assign a char value to a char variable, but prohibited to assign a string
constant to a char variable. In the C Programming it does not exists a string data type and
4. 4. The char constant occupy one byte, and string occupy the number of char and plus extra
one as the end char ‘\0’. For instance, string "C program" remap to memory as ‘p’, ‘r’, ‘o’,
Bool variable
Bool variable is a kind of variable that express truth-value, it has two value types: true and false.
57
When value is zero, it is false as a bool variable, when value is nonzero, it is true as a bool
variable. The bool variable can be assigned and initialized by “true” or “false”, it can also be
Macro defining
In the C Programming, The macro grammar ‘#define’ can let a name present to a constant or an
“#define” is a macro grammar, it uses to simplify the complicated expression to a single word, use
this word to instead. The name to define prefer to be all the upper char. Example refer to the
following codes:
#define PI 3.14159
void main()
float s, r;
r = 5;
s = PI * r * r;
printf("s=%f\n", s);
Define “PI” as 3.14159, “r” is the radius, “s” is the capacity of around.
Be sure that the defined name cannot be treated as a variable, it cannot be assigned with a new
value.
58
The initialize value and type conversion
Initialize value of variable
It is usual to declare variables with value initialize. It has many ways to assign an initial value to a
variable in the C Programming. If is called the variable initialize. The custom format to initialize a
variable is:
datatype variable1 = value1,variable2 = value1, …;
Such as:
int a = b = c = 5;
float x = 32, y = 3f, z = 0.75;
char ch1 = 'K', ch2 = 'P';
What should be noted is, it is prohibited to use assignment expression nested in the initialization,
like ‘int a=b=c=5’ is invalid.
The automatic conversion happens in the fusion calculation of the different kinds of data types of
values, it is automatically finished by the compiler. The automatic conversion must follow the
rules:
1. For values take part in the calculation, if their data types are different. The first to do is
2. The data type of calculation result is with the largest range in its arguments to maintains the
accuracy not lost. For instance, calculate an int with a long, int will be converted to long at
first.
3. Float calculates with other data type, the result must be double.
4. Char and short take part in the calculation with other data type occupied higher bytes, they
5. In the assignment, if the data type of the assigned variable is different from the value
assigning, the data type of assigning value converts to what variable is. In this case, the range
(for integer) or accuracy (for real) of the variable data type is less than assigning value, the
59
range will be exceeded and cause overflow, or the accuracy will be lost.
Force conversion
Force conversion is realized by the cast calculation, the custom format is:
It converts the result of an expression to the targeted data type. For instance: ‘(float)a’ converts a
1. The targeted data type and converted expression must surround with round bracket. For
instance, ‘(int)(x+y)’ write to ‘(int)x+y’ means that firstly convert x to int then add int x and
y.
2. No matter of the force conversion or the automatic conversion, they both do temporary
changing to the data type of the variable according to the calculation requirement, the
The operators of C Programming have different priorities. one feature it exists is associativity. In
the expression, the order of operator to calculate not only follows the rules of their priority, but
also rule in the associativity, make sure that it calculates from left to right, or from right to left.
⚫ Calculation operator
., such as plus (+), minus (-), multiply (*), divide (/), mod (%), increase (++) and decrease
(--).
⚫ Relation operator
Use to a series of comparisons, such as greater than (>), less than (<), equal to (==), no less
⚫ Logical operator
60
Use a series of logical calculations, such as and (&&), or (||), and not (!).
⚫ Binary operator
Use to a series of binary calculation, such as binary and (&), binary or (|), binary not (~),
binary xor (^), shift left (<<), and shift right (>>).
⚫ Assign operator
Use to a series of assignment, such as custom assignment (=), assignment after calculated (+=,
-=, *=, /=, %=), and assignment after binary calculated (&=, |=, ^=, >>=, <<=).
⚫ Condition operator
This is Ternary operator with ‘?’ and ‘:’, condition before ‘?’, expression on true between ‘?’
⚫ Quota operator
Use to combine expressions together to one, return the value of the last one.
⚫ Pointer operator
Use to get value from pointer (*) and get address pointer from variable (&).
⚫ Sizeof operator
⚫ Special operator
Sequential array
In the programming design, for the convenience, there have a structure to contain some variables
as sequence. The structure combined variables with same type is named as “Array”. In the C
programming, array is a constructed data type, the array can be split into some array elements, the
data type of element can be not only basic type, but also constructed type. According to the data
type of array element, array series have value array, char array, pointer array, structure array and
other series.
This chapter demonstrate the value array and char array. The type declaration is required before
61
datatype arrayname[length]
In the declaration, “datatype” can be any data type or structure type, “arrayname” is the name of
this array, “length” can be a constant value or an expression to calculate the value. The following
float b[10], c[20]; //Declaration two float arrays named as ‘b’ and ‘c’, ‘b’ has 10 elements and
1. The type of array is same as the data type of array element. With an array, the elements
3. The array name cannot be equaled with another variable name. For instance:
void main()
{
int a;
float a[10];
//error, name of integer and array is same
}
4. The first element with index as zero, then 1, 2, 3....
5. It allowed to declare arrays and variables together, like:
int a, b, c, d, k1[10], k2[20];
labeled as arrayname[index]. The index presents the order of elements in its array, so it is only
allowed to be an integer (constant value and expression is all okay, but must be an integer). For
instance, “a[5]”, “a[i+j]”, “a[i++]” is legal for array element. The array element is also called the
index variable. Before use the index variable, an array must be declared. In the C programming, an
62
The format of initialize value assign is:
In the statement, “static” means that the array takes effect in global, c programming rules that only
the static array or global array can assign as an initialize value. in the “{}”, the values are the
initialize values for each element in order, are split by quota. For instance:
static int a[10] = {0, 1, 2, 3, 4}; //a[0]=0, a[1]=1, a[2]=2, a[3]=3, a[4]=4, the else=0
This statement only assigned first 4 elements, and the others are reset to zero.
2. Elements of the array can only be assigned one by one, but not the whole array. For instance,
assign elements of an array from 1st to 10th, the valid format is:
but not:
3. If no initialization is executed, all the elements of the array are reset to zero.
4. Assign all the elements to an array, the length of the array can be hidden. For instance:
Char array
The array stored char is char array. The format of char array is same as normal array, for instance:
char c[10];
Char array can be initialized one by one, or initialized with a string. For instance:
static char[10] = {'C', ' ', 'p', 'r', 'o', 'g', 'r', 'a', 'm'};
static char[] = {'C', ' ', 'p', 'r', 'o', 'g', 'r', 'a', 'm'}; //omit the length
static char[] = "C program"; //initialized with string without curly braces
there is a char ‘\0’ at the end of a string, the length of array is more one than the length of string.
63
The actual memory stored of array is : “C Program\0”, ‘\0’ is automatically created by the
compiler. Because it used ‘\0’ label, the length of array is not required while assigning a string to it,
the length is processed by system. By applying the string assignment, the input and output char
1. Expression statement
Expression statements contains an expression end with ‘;’. Executing this statement will
calculate the expression, but the calculation result is ignored at once. For instance:
2. Control statement
Controlling statement control the procedure of program executing, to realize various kinds of
programming structures.
They are combined with the specific keyword. C Programming has some keywords to control
the executing:
3. Empty statement
The statement has no content but only a char ‘;’ at the end. An empty statement executing
while(getchar() != '\n')
}
64
65
4. Assignment statement
The assignment statement contains an assignment expression end with ‘;’. The custom format
is:
variable = expression;
It is one of the most used in C Programming. Notice the following details while using this
kind of statement:
⚫ An assignment statement assigns rvalue (value at right side of ‘=’) to lvalue (value at
left side of ‘=’), and the rvalue can also be a lvalue, so that the assignment statement can
a=b=c=d=e=5;
a=5; b=5; c=5; d=5; e=5; //take same effect as statement above
⚫ Notice the difference between initialization and assignment. The variable initialization is
quotas, it is prohibited to assign a value with two or more variables. The assignment
statement can assign the same value to multiple variables as well, the data type of the
⚫ Notice that the difference of expression statement and assignment statement. Expression
statement can be used for condition of conditional structure, but assignment statement
Conditional structure
Relation operator and expression
Operator that compares two operands is called relation operator. Details of relation operators refer
66
== Check if two operands is equal, if equal the condition is true. (A == B) is false
> Check if left operand is greater than left operand, if it is the condition is true. (A > B) is false
< Check if left operand is less than left operand, if it is the condition is true. (A < B) is true
>= Check if left operand is no less than left operand if it is the condition is true. (A >= B) is false
<= Check if left operand is no greater than left operand if it is the condition is true. (A <= B) is true
Table 4. 2
Relation operands are all binocular operator, and left-associative. The priority of relation operands
is lower than calculation operators, and higher than assignment operators. Among 6 relation
operands, the priority of “<”, “>”, “>=”, and “<=” is same and higher than “==” and “!=”, the
operators, shown as following table (in the example, bool A = true, bool B = false):
&& And operator, condition is true when two operands is true. (A && B) is false
Table 4. 3
“&&”, “||” are binocular operator and left-associative; “!” is a unary operator and right-associative.
“!” has the higher priority than calculation operators; Priority of “&&” and “||” is lower than
relation operators, and higher than assignments; Priority of “&&” is higher than “||”.
If-else statement
If-else statement use keyword “if” to lead the target condition, use keyword “else if” to extend
condition branches, use keyword “else” to summarize the left conditions. The statement format
show as following:
if (condition1) {
statements1;
67
}
else if (condition2) {
statements2;
else if (condition3) {
statements3;
else {
statements4;
If-else statement will execute statements when corresponding condition is meet, and statements
if (a = b)
else
switch statement
Switch statement executes statements according to different value of target variable. The keyword
“switch” leads the target variable, keyword “case” leads different value of the target variable, the
keyword “default” summarizes left value case of the target. The statement format show as
following:
switch (variable) {
case value1: {
statements1;
case value2: {
statements2;
68
}
default: {
statements3;
Statements will be executed when variable is equal to corresponding value, and the other case will
int a;
switch (a) {
case 0: {
case 1: {
default: {
In this statement, if expression1 is true, this statement returns expression2; When an expression is
69
Loop structure
The loop structure is an important structure in the programming. The feature is, while the targeted
condition is true, repeat to execute the program paragraph, until the condition becomes false. The
targeted condition is called loop condition, the program paragraph repeated is called loop content.
The C Programming supports lots of types of loop keyword for loop structures.
While statement
The custom format of while statement is:
while (expression) {
statements;
The expression is the target condition, the statements are loop content. This loop structure
calculates the expression firstly, if it is true, the statements will be executed, the processing will
Do-while statement
The custom format of while statement is:
do {
statements;
} while(expression)
The statements are loop content, and the expression is the target condition. This loop structure executes
the statements once and judges the expression, if it is true, statements will be executed again, the
For statement
The custom format of for statement is:
statements;
70
}
The expression1 is always used to initialize an iterating variable as a start value. If this iterating
The expression2 is the condition of the loop, usually to be a relation statement or logical statement.
this expression can be hidden and the loop will permanently be repeated (except break).
The statements will be executed if the variable initialized by expression meets the condition
defined by an expression, the variable iterates after each execution of statements. Loop will stop
till the variable doesn’t meet the target condition. For instance:
int n = 0;
printf("%d", n); //output increasing number until user input the enter
statements, and start the next turn loop (judge of target condition and execution of loop content). For
instance:
int x = 1
x++;
if (x <= 5) continue; //pass left statements and continue next turn loop
printf ("greater than 5"); //output “greater than 5” when x is greater than 5
Keyword “break” can be used in the loop content, it jumps out from the loop and executes statements
int x = 0
71
printf ("%d", x); //output 0 1 2 3 4
Figure 4. 1
2. In this dialog, the top side placed the input box of the name, the author, and the version of
creating a function block. The left side lists the function inside, the right side lists the
arguments of the left side selected function. Click [Create function] to create a new function
in the left list, [Remove function] to remove the selected function in the left list, [Yes] to
create function block, [No] to cancel creating and close this dialog.
Figure 4. 2
3. Double click the function block in the project explorer, the screen will show the editor to edit
it.
72
Figure 4. 3
4. Write the code of the function block. While coding, it supported to automatically fulfill tab
spaces before each line, insert the right bracket for each inputted left bracket, and show the
code completion list. The code completion list contains keywords, function arguments, local
variables, and global variables (constant maybe). all the word in the completion list includes
the word inputting at present. For instance, input a word “va”, “var1”, “var2”, “var3”, “var4”
all include “va” will all be displayed on the list. Click one of the list or press the direction key
to move caret and enter to select, the selection will replace the inputting word.
5. After completed, view the folder of this function block on the project explorer, to look up all
Figure 4. 4
Press F4 key to compile the ladder and function block together, SamSoarII makes a higher
priority to compile the ladder program, and terminate the compile while error happens in
ladder program, make sure your ladder program is correct. Click the [Tool] -> [Program
Check] -> [FuncBlock Check] to skip the ladder checking to check the function block only.
6. Once complete the function block, the first compile may appear lots of error messages, and it
is normal.
73
Figure 4. 5
SamSoarII checks all the errors and reports them to the error list. Double click one of them, the
screen will be navigated to the targeted location. After modification and compile again, the error
point has been repaired will disappear. If all the errors repaired, the message box will show
“Complied successfully”.
Figure 4. 6
After the errors disappear, the warning messages probably exist still. Although the compile is
accepted, we suggest you certify the warning messages and decide to modify it or not. (Through
click the [View] -> [Error list] to open and look at).
74
Figure 4. 7
Notice that even though the errors and warnings not exist, other potential problems may be in your
programming. Programming designing needs to be careful, avoid unnecessary trouble and lost.
Figure 4. 8
called by a CALLM instruction. As a matter of fact, there has some strict conditions to limit a
function to be called.
1. The number of arguments not more than four. such as “func1(WORD i, WORD j, WORD k,
2. The data types of all the arguments must be all uppercase characters. In fact, they are all the
75
FLOAT float* The pointer of float
Table 4. 4
The pointer of bit-register is 32-bit, so each 4-byte memory maps to one bit-register, please notice
that.
another way to edit the program by instruction list. The instruction list is a sequence of
instructions generated by the current ladder diagram to present the executed logic. Click on
the toolbar to display the instruction list and view. (By default, both ladder diagram and
instruction list are visible on the screen, click on the toolbar to hide the ladder diagram and
Figure 4. 9
Click one line of the instruction list, the ladder editor will be navigated to the corresponding visual
unit at once. Double click this instruction, it will show the dialog to edit the arguments of this
instruction. But the difference from the ladder diagram is, Input text to insert instruction is
prohibited in the instruction list. The only way to edit the instruction list is to use a function block
76
Operation
1. In the project explorer, right click the ladder diagram wanted to edit, open the context menu,
Figure 4. 10
2. Then there display out the dialog to determine the name and function block of creating
function.
Figure 4. 11
3. After click [Yes] button, the function block editor will be opened and displays the created
function, and the function creating is completed. (You can also write the code as follows, the
diagram).
77
Figure 4. 12
The ladder-building is different from the general function, it owns some features:
⚫ The header of function inserts “[Routine("Program name")]” before, presents that the
⚫ The inner of the function is “__asm__” structure, the string argument means the network,
the inner content of the structure is the instruction list. Create this structure to create a
new network.
⚫ Placed ‘,’ between each instruction, based on this premise, more than one instruction can
be placed in one line. Two or more ‘,’ cannot be near, the start and end cannot be ‘,’.
After completed, press F4 key to compile and build the ladder. If the ladder-building function
Figure 4. 13
Make sure the function is valid and accept the compile, so that the ladder be built
automatically.
78
Figure 4. 14
⚫ The ladder-building function must follow this structure. Otherwise the built ladder will be
⚫ Call the ladder-building function by CALLM instruction or function block, nothing will be
⚫ Users can write a comment in the ladder-building function, but please do not comment out
instance, the pointer of M register is named “Mbit”, D register is “DWord”, and so on. Those
variables have all the pointers, D0 is present as “DWord[0]”, M10 is “MBit[10]”, and so on.
Here are all the base addresses of the soft component and their variable name as following.
79
Base address Variable name Data type
X, Y, M, S, C, T XBit,YBit,MBit,SBit,CBit,TBit BIT(uint32_t*)
D, CV, TV, AI, AO, V, Z DWord, CVWord, TVWord, AIWord, AOWord, VWord, ZWord WORD(int16_t*)
Table 4. 5
Example
Ladder program:
Figure 4. 15
Function block:
void Func()
if (MBit[0])
if (MBit[1]) YBit[0] = 1;
The function block takes the same effect as the ladder diagram. But what should be noted is, the
Simplification
Add the attribute statement “[Simplify("Register")]” before the header of a function to enable you
[Simplify("Register")]
void Func()
80
{
if (M0)
if (M1) Y0 = 1;
This feature follows a specific grammar to simplify our code, such as offset verified by V/Z register
and the data type conversion can be realized by this brief grammar:
In the C Programming, once to get a specific data type from a targeted address, the user needs to
convert the pointer to that data type, finally get the value from that converted pointer. For instance,
The following shows the comparing from the original code to simplify code:
DWord[0] D0
DWord[0+VWord[0]] D0V0
*((DWORD)(DWord+10)) DD10
*((FLOAT)(DWord+20)) FD20
*((UWORD)(CVWord+5)) UCV5
*((UDWORD)(DWord+20+ZWord[2])) UDD20Z2
Table 4. 6
81
Program simulation
Start to simulate
Before the simulation, the user should make sure the program successfully compiles. Click
Under simulation mode, the edit toolbar will be replaced, as the following figure shows.
Figure 5. 1
Under simulation mode, user can also use the monitor function.
Simulation control
The simulation processes like actual PLC, user can click icon to start the simulation; Click
When simulation starts, user can monitor the value of the soft component, and modify most of
Figure 5. 2
When simulation pause, the program processing will pause at where the yellow block located.
Users can still monitor and modify the value of the soft components, but the program won’t
refresh.
82
Figure 5. 3
When simulation stop, user cannot monitor and modify any value of soft component.
Figure 5. 4
Debug
When simulation is pause, user can debug the program by using tool in the toolbar:
Figure 5. 5
By process: Execute to next instruction and pause, and ignore the call of subroutine and
function block
By sentence: Execute to next instruction and pause, step into subroutine and function block
Jump out: When pausing in the subroutine or function block, process the rest of it, jump out
Current pause position: Navigate the viewport to where the current pause position locates at.
83
Breakpoint
Breakpoint can help user to debug the program, program will pause at the breakpoint
automatically.
Add a breakpoint
Under simulation mode, select position need to add a breakpoint, right click to display pulldown
Figure 5. 6
Breakpoint management
Right click at breakpoint, and select [Breakpoint point] in the pulldown menu, display the
Figure 5. 7
84
⚫ [Release]: Delete the breakpoint immediately.
⚫ [Interrupt Condition]: When the interrupt condition is set, breakpoint will take effects only
when the condition is met for specified times. The condition can be selected with on state, off
state, rising-edge, falling-edge, edge, and be shown at right-up of the breakpoint marked
block.
Figure 5. 8
⚫ [Interrupt Number]: Times limit for that the interrupt condition is met, when times reach the
Figure 5. 9
⚫ [Condition add]: Add a component breakpoint, and the user needs to set the condition to
85
⚫ [All delete]: Clear all the selected a component breakpoint.
⚫ [Status]: Show the status of component breakpoint, be invalid when the condition is not set.
⚫ [Condition]: For the bool soft component, the condition can be selected with: rising-edge,
falling-edge, change, equal to the comparison target, not equal to comparison target. For
word soft component, the condition can be selected with: change, equal to comparison target,
not equal to comparison target, greater than comparison target, no less than comparison target,
SFC programming
SFC introduction
SamSoar II supports SFC programming. SFC (Sequential Function Chart) is a kind of
programming language according to standard IEC 61131-3, one of its significant features is
For instance, the following SFC and ladder diagram are equivalent.
Figure 6. 1 Figure 6. 2
In the example, program starts from S0 state, and out Y2 when M10 is ON; When M0 is ON, S0
state jumps to S1 state, and set M3 when X3 is ON; When M1 is ON, S1 state jumps to S2 state,
86
and out Y4.
SFC edition
Click [SFC Editor] in project explorer to display the SFC edition page, as following figure shows.
Figure 6. 3
User can select one grid in the edition area by click, and move the selected gird by direction key.
User can select multiple grids in the edition area by press and drag, or by using the shift key with
direction key.
Figure 6. 4
⚫ [Cut]: Copy the element in the selected grid it to the clipboard, and delete the one in grid.
87
⚫ [Row Insert]: Insert a new row in the position before/after select grid, or insert at the end.
⚫ [Row Delete]: Delete the row in the position of the select grid.
⚫ [Column Insert]: Insert a column in the position before/after select grid, or insert at the end.
⚫ [Column Delete]: Delete the column in the position of the selected grid.
SFC Units
State unit
State unit consists of 3 parts: state register, output condition, and output instruction. Refer to
following figure.
Figure 6. 5
When the state register is ON, it means this state is enabled, the output instruction will be
executed when output condition is met. When the state register is OFF, this state is disabled, the
output instruction won’t be executed when the output condition is met. The enabled states can
User can double click the selected grid to display the unit dialog, and set the parameters.
88
Figure 6. 6
⚫ [State Register]: Flag of state, can only be set with S soft component.
⚫ [Output Condition]: The condition to output, set with SFC condition expression.
⚫ [Output Instruction]: The output when the condition is met, set with instruction sentences,
Line unit
Line unit is used to connect two other units above and below, as the following figure shows.
Figure 6. 7
User can double click the selected grid to display the unit dialog, and insert a line unit.
89
Figure 6. 8
Jump unit
The jump unit can be used as a common state unit, but it cannot be connected with the line unit
below. It means the state will transfer to the set state register.
What should be noted is, when multiple jump units are used, it’s better to set the output condition
90
Figure 6. 9 Figure 6. 10
User can double click the selected grid to display the unit dialog, and insert a jump unit. Parameter
Figure 6. 11
is with a condition, and the state will transfer to the branch state unit when the corresponding
condition is met.
91
Figure 6. 12
User can double click the selected grid to display the unit dialog, and insert condition branch unit.
Figure 6. 13
the “condition” refers to SFC condition expression, and the “column” is the number that which
92
Parallel branch unit
The condition branch unit connects one root state unit and multiple branch state units. the root is
with a condition, and the state will transfer to all branch state units when the condition is met.
Figure 6. 14
User can double click the selected grid to display the unit dialog, and insert parallel branch unit.
Figure 6. 15
the “condition” refers to SFC condition expression, and the “column” is the number that which
Figure 6. 16
User can double click the selected grid to display the unit dialog, and insert CP branch unit.
Figure 6. 17
the “condition” refers to SFC condition expression, and the “column” is the number that which
column the branches located at. Parallel part sentences are divided into a semicolon.
94
Condition merge unit
Condition merge unit connects multiple branch state units and one joint state unit. Each branch is
with a condition, the branch state will transfer to the joint state when the corresponding condition
is met.
Figure 6. 18
User can double click the selected grid to display the unit dialog, and insert condition merge unit.
Figure 6. 19
the “condition” refers to SFC condition expression, and the “column” is the number that which
95
Parallel merge unit
Condition merge unit connects multiple branch state units and one joint state unit. The joint is with
a condition, all the branch states will transfer to the joint state when the condition is met.
Figure 6. 20
User can double click the selected grid to display the unit dialog, and insert condition parallel unit.
Figure 6. 21
the “condition” refers to SFC condition expression, and the “column” is the number that which
96
CP merge unit
CP merge unit is combination of condition merge unit and parallel merge unit.
Figure 6. 22
User can double click the selected grid to display the unit dialog, and insert CP merge unit.
Figure 6. 23
the “condition” refers to SFC condition expression, and the “column” is the number that which
column the branches located at. Parallel part sentences are divided with semicolon.
97
SFC condition expression
The expression of the condition can be a single operand or operands with operators.The following
D+register Get double value of the data register DD10 (double value in D10 and D11)
F+register Get float value of the data register FD10 (float value in D10 and D11)
Register+offset Get value of the register with address offset D0V0, M0Z0
(dword)
and And logic operation with two operands or expressions M0 and M1, D0 and H00FF,
xor Exclusive-or operation with two operands or expressions M0 xor M1, D0<0 xor D10>0
mep Rising-edge of bit register or bool expression map M4, mep(M0 and M2)
mef Falling-edge of bit register or bool expression mef M4, mef(M0 and M2)
period of PLC
98
!= Not equal comparison with two operands or expressions D10!=20
Table 6. 1
99