100% found this document useful (1 vote)
2K views99 pages

Manual PLC Samkoon

This document provides instructions for installing and using the SamSoar II visual programming software for programming PLCs made by Shenzhen Samkoon Cooperation. The software allows editing ladder logic and function block programs. It supports editing via mouse, keyboard, and dragging objects. Programs can be downloaded to and monitored on a PLC. The software requires Windows XP/7/8/10 and .NET Framework 4.0 and is installed via a setup program. Basic mouse and keyboard functions are described for navigating menus and editing programs.

Uploaded by

Oscar Montañez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views99 pages

Manual PLC Samkoon

This document provides instructions for installing and using the SamSoar II visual programming software for programming PLCs made by Shenzhen Samkoon Cooperation. The software allows editing ladder logic and function block programs. It supports editing via mouse, keyboard, and dragging objects. Programs can be downloaded to and monitored on a PLC. The software requires Windows XP/7/8/10 and .NET Framework 4.0 and is installed via a setup program. Basic mouse and keyboard functions are described for navigating menus and editing programs.

Uploaded by

Oscar Montañez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Software Manual of Samkoon PLC

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

functions in the function block editor.

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

edit the project.

The project is protected strictly in the download and upload procedure, user can set the password

of downloading or uploading, or prohibit uploading.

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

automatically detect and install it.

Installation and uninstall


Installation of application
Before installation, make sure the computer meets the lowest condition for installation. Detailed

installation procedures as follows:

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

2. Confirm to uninstall the application.

Figure 1. 10

3. Wait the uninstall processing.

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

Right click to display pull-down menu.

Hotkey
Table 1.1 lists some hotkey that be frequently used, to convenient the operation.

Key Function Key Function

Enter Input or modify an instruction Ctrl+Y Redo

Delete Delete the selected instruction Shift+↑↓←→ Expand the selection

↑↓←→ Move the caret of ladder Shift+Ctrl+↑↓←→ Move the instruction

Ctrl+↑↓←→ Draw line Shift+Enter Insert a network

Ctrl+Mouse wheel up Screen scale up Shift+Delete Delete current network

Ctrl+Mouse wheel down Screen scale down Shift+Mouse left Multiple selection

Ctrl+Enter Add row behind Shift+Esc Multiple selection reset to single

Ctrl+Delete Remove the selected rows Ctrl+N Create a new project

Ctrl+X Cut Ctrl+O Open an exist project

Ctrl+C Copy Ctrl+S Save the current project

Ctrl+V Paste Ctrl+F Search

Ctrl+Z Undo Ctrl+H Replace

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

move the focus and open the context menu.

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

as same as the context menu of the menu bar.

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:

Key Function Key Function Key Function

View Tools Pulse

Ctrl+T,I Ladder scale up Ctrl+T,U Upload Ctrl+P,O Polyline setting

Ctrl+T,O Ladder scale down Ctrl+T,D Download Ctrl+P,I DXF import

Ctrl+E,C Comment mode Ctrl+E,S Simulation Language

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+F3,O Show soft component initialize Ctrl+T,N Check ladder Help

Ctrl+F4,O Show monitor list Ctrl+T,F Check function block Ctrl+F10,O Show the help document

Ctrl+F5,O Show error list Ctrl+T,H File conversion Edit

Expansion module
Ctrl+F8,O Show breakpoint list Ctrl+T,C Ctrl+F1,A Insert row before
detect

Show soft component


Ctrl+F9,O Ctrl+F6,O PLC setting Ctrl+F1,B Insert row after
breakpoint list

Project Ctrl+F2,A Insert column before

Ctrl+W,R Create a subroutine Ctrl+F2,B Insert column after

Ctrl+W,F Create a function block Ctrl+F3,B Insert network before

Ctrl+W,M Create a Modbus table Ctrl+F3,E Add network end

Ctrl+F7,O Application setting

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

selects configuration as following:


10
Figure 1. 17

Open a project
User can also open an existing project, the project file name must be end with “ssr” suffixes. Click

[File] -> [Open Project] from the menu bar.

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

conversion] from the menu bar.

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

instance, as follow figure, to insert a normally open contact M0 in the ladder.

Figure 1. 21

Search and replace


Users can use the search/replace function by click [Edit] -> [Search]/[Replace] to open the dialog,

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.

Soft component manager


Select the [View] -> [Soft component manager], or click the icon in the toolbar, to open the

window and look up all the soft components, and modify the alias and comment of the soft

component. More details refer to Soft component manager.

Instruction list
Click the icon in the toolbar, to open the instruction list of the current ladder diagram. The ladder

editor is on the top, and the instruction list is on the bottom.

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.

Add and use a subroutine


In the project explorer, right click the [Subroutine] folder to open the context menu, add a new

subroutine or build a new empty folder. Double click the created one to add it to the ladder editor.

Use function block


In the project explorer, right click the [FuncBlock] folder to open the context menu, add a new

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

toolbar to call the download dialog.

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

value as initialization data before first execution.

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

⚫ New Project:Create new SamSoarII project file.

⚫ Open Project:Open the existed SamSoarII project file.

⚫ Save Project:Save the opening project to file.

⚫ Save As:Select another directory path of local computer to save.

15
⚫ Recent Project:Look recently opened files, and choose one to open.

⚫ Close Project:Close the opening project.

⚫ Exit:Exit the SamSoarII application.

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,

and reopen the project.

⚫ Redo: Restore to the last status before undoing executed.

⚫ Cut: Cut the selection to the clipboard.

⚫ Copy: Copy the selection to the clipboard.

⚫ Paste: Read to data from clipboard, and load it to the editor.

⚫ Select All: Select all the editing ladder programs or text.

⚫ 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

⚫ Zoom In: Zoom in the scale of current the ladder program.

⚫ Zoom Out: Zoom out the scale of current ladder program.

⚫ Comment Mode: Show or hide the comment of soft component in the current ladder

program.

⚫ Project Explorer: Look up and manage each part of the project.

⚫ 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

can only be displayed under monitor mode.

⚫ 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,

it is helpfully to debug the running of the simulation process.

⚫ 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

condition is true, and spot to the running position.

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 FuncBlock: Create a new function block in the project explorer.

⚫ 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

⚫ Upload: Display dialog to upload the data from PLC.

⚫ Download: Display dialog to download the data to PLC.

⚫ 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

and write the value of soft components.

⚫ Return to Edit Mode: Can only be used under simulation mode or monitor mode, click to

return to the editor mode.

⚫ 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

project file of SamSoar II (2rd generation application).

⚫ PLC Reset: Clear the program and data of the connected PLC, reset it to the status first

issued from the factory.

⚫ System setting: Display the dialog to configure the programming style and view style.

Pulse (Y)

Figure 2. 7

⚫ Pulse platform: Display dialog to configure the platform system.

⚫ DXF Import: Display dialog to import and manage the CAD graph.

Language (Y)

Figure 2. 8

⚫ Chinese: Switch the language to Chinese.

⚫ English: Switch the language to English.

19
Help(H)

Figure 2. 9

⚫ Help: Click to open the help document.

⚫ Abort: Click to display the version and license of this application.

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.

Create: Create a new SamSoar II project file.

Open: Open an existing SamSoar II project file.

Save: Save the editing SamSoar II project.

Undo: Undo the last editing operation.

Redo: Redo the last revoked operation.

Cut: Cut the selection to clipboard.

Copy: Copy the selection to clipboard.

Paste: Paste data from clipboard to the targeted position.

Compile: Check the validity of whole project.

Upload: Display the dialog to upload the program and data from PLC.

Download: Display the dialog to download program and data to PLC.

Simulate: Enter simulation mode, and simulate the program running.

Monitor: Enter monitor mode, and monitor the registers of PLC.

Zoom in: Scale up the view of edition area.

Zoom out: Scale down the view of edition area.

20
Ladder diagram: Display or hide the ladder program window.

Instruction list: Display or hide the instruction list window.

Comment: Display or hide the comments.

Project explore: Display or hide the project explore.

Soft component list: Display or hide the soft component list window.

Soft component initialization: Display or hide the soft initialization window.

Error list: Display or hide the error list window.

Monitor: Display or hide the monitor window.

Breakpoint list: Display or hide the breakpoint list window.

Component breakpoint list: Display the component breakpoint list window.

Program comparison: Display the program comparison window.

Variable tendency curve: Display the variable tendency curve page.

String monitor: Display the String monitor window

Routine argument: Display the program argument window.

Communication setting: Display the communication setting dialog.

System setting: Display the system setting dialog.

PLC setting: Display the PLC setting dialog.

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

diagram (refer to LD instruction in the instruction manual). Hotkey is F2.

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

diagram (refer to LDI instruction in the instruction manual). Hotkey is F3.


21
Immediate NC contact: Insert an immediate normally close contact element in the selected

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

diagram (refer to LDP instruction in the instruction manual). Hotkey is F5.

Falling-edge pulse: Insert a falling-edge pulse element in the selected position of ladder

diagram (refer to LDF instruction in the instruction manual). Hotkey is F6.

Rising-edge conversion: Insert a rising-edge conversion element in the selected position of

ladder diagram (refer to MEP instruction in the instruction manual). Hotkey is shift+F5.

Falling-edge conversion: Insert a falling-edge conversion element in the selected position of

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

INV instruction in the instruction manual). Hotkey is F7.

Output: Insert an output element in the selected position of ladder diagram (refer to OUT

instruction in the instruction manual). Hotkey is F8.

Immediate output: Insert an immediate output element in the selected position of ladder

diagram (refer to OUTIM instruction in the instruction manual). Hotkey is F8.

Transverse connection line: Insert a transverse connection line in selected position of ladder

diagram. Hotkey is F9.

Vertical connection line: Insert a vertical connection line in the selected position of ladder

diagram. Hotkey is F10.

Delete transverse connection line: Delete a transverse connection line in selected position

of ladder diagram. Hotkey is shift+F9.

Delete vertical connection line: Delete a vertical connection line in the selected position of

ladder diagram. Hotkey is shift+F10.

Row insert: Insert a row in the selected position of ladder diagram.

Row delete: Delete a row in the selected position of ladder diagram.

Colum insert: Insert a column in the selected position of ladder diagram.

Colum delete: Delete a column in the selected position of ladder diagram.

22
Network insert: Insert a network in the selected position of ladder diagram.

Network delete: Delete 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

navigate to the corresponding position in ladder diagram.

User can also search instruction, single soft component, soft component range, a name by

inputting corresponding keywords:

⚫ Instruction

Search instruction by inputting keywords like “LD”,“OUT”,“ADD”.

⚫ Single soft component

Search soft component by inputting keywords like “D0”, “K1”, “M0V0”.

⚫ Soft component range

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

output result to D0.

Search in function block text


While editing function, user can also click [Edit]->[Search] to display the search dialog, as follow

figure.

Figure 2. 11

User can select search scope: current Text or all text.

user can also set searching configuration by clicking , as follow figure:

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.

Replacement content must obey the following rules:

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,

“D[10..20]” is regarded as “D10”, and the constant value K1 will be reserved.

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

“MUL K1 D0 D1” will be replaced to “LD D1.8” and “MUL K1 D1 D1”.

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

CV[10..12] D20”, “ADD D0 D0 D12” be replaced to “SUB D0 CV10 D20”, “ADD D0 D1

D12” be replaced to “SUB D0 CV11 D20”, these replacements are valid.

When replacement fails, the error report will occur with error reason.

26
Figure 2. 14

Replace in function block text


While editing function block text, user can click [Edit]->[Replace] to display the replace dialog, as

following figure.

Figure 2. 15

Rules of search part refer to introduction above.

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.

⚫ [Search]: Users can search target soft components by input keywords.

⚫ [Display Details]: If this option is checked, details (location, usage in the ladder) of the soft

diagram will be displayed, as the following figure.

Figure 2. 17

⚫ [Clear Selected]: Cancel all the selection in the table.

⚫ [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.

Soft component initialization


Click [View]->[Soft Component Initialization] to display the window, as following figure.

Figure 2. 18

⚫ [Component Address]: Head address of components to be added in batch.

⚫ [Data type]: Data type of components to be added in batch.

⚫ [Components Length]: Number of components to be added in batch.

⚫ [Add]: Click to add components in batch as setting.

⚫ [Delete]: Click to delete selection component in table (use Ctrl+LeftClick to select or

unselect).

⚫ [Delete All]: Clear the table.

⚫ [Import CSV]: Import external CSV file to replace the table.

⚫ [Export CSV]: Export the table and save as CSV file.

⚫ [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.

Data Type Range Data Type Range

29
WORD -32768~32767 BCD 0~9999

UWORD 0~65535 FLOAT -3.4e38~3.4e38

DWORD -2147483648~2147483647 HEX 0x000~0x9999

UDWORD 0~4294967295 DHEX 0x00000000~0x99999999

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

ladder diagram or function block text.

30
Monitor List
Click the [View] -> [Monitor List] to open the window, as following figure. The monitor only

works under monitor mode or simulation mode.

Figure 2. 20

Add and remove component table


By right click in the component table list, the user can build a new component, delete the selected

or all component table, or export selected table and save as a CSV file.

Figure 2. 21

Add and remove component


User can add components manually by clicking [Add Component], or add component

automatically by clicking [Quick Add].

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

component by checking [Intra Address].

Figure 2. 23

Start and stop monitor


When PLC is communicating with the upper software SamSoar II, the user can start to monitor

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

table and select [Set all SetValue].


32
Figure 2. 25

PLC parameter setting


Click [View]->[PLC Parameter Setting] to display the dialog. User can select [Device Model],

[Communication Parameters], [Password Setting], [Retentive Zone Setting], [Extension Module],

[Filter Setting], and [Other].

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

downloading data to PLC.


33
Communication Parameters

Figure 2. 27

Users can set parameters of each communication port of PLC. Refer to communication

instructions in the instruction manual for details.

⚫ [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

115200. The baud rate of master and slave must be same.

⚫ [Data Bit]: Length of the data signal of each data frame.

⚫ [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

message in whole bits of data register.

⚫ [Station Number]: Used for Modbus communication,number of master station or slave

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.

⚫ [Modbus Interval]: Time interval between each data frame.

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

Retentive zone setting

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,

D5952~D7999, S600~S999, CV100~CV255.


35
[Not clear while downloading]: When this option is checked, data in the retentive zone will not be

cleared after downloading.

Extension module setting

Figure 2. 30

Details refer to extension module manual.

Filter Setting

Figure 2. 31

For the [Filter mode] option, user can select [Disable], [Unified mode], and [Other].

⚫ [Disable]: Disable the software filter of input signal X.

⚫ [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

division factor] for each X input port, as the following figure.


36
Figure 2. 32

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

signal of which level is same during 8 sampling.

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

real-time instructions in the instruction manual).

⚫ 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.

⚫ Power-down detection time

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.

⚫ [Font Style]: User can select font of the font.

⚫ [Font Size]: User can select size of the font.

⚫ [Font Color] The color of font can be user-defined.

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

time interval, the time unit is minute.

⚫ [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

of elements in each line when option [Comment line minimize] is checked.

⚫ [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

window, as following figure.

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

PLC, and click to close the comparison.

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

the compared one.

What should be noted is, the comparison result won’t update when the user edits the project to

compare, unless reloading the compared project.

42
Variable tendency curve
Click [View]->[Variable Tendency] or icon to display the variable tendency curve page,

show as following figure.

Figure 2. 43

Add and remove variable


Click the icon in the left bar to add variable, as following figure shows:

Figure 2. 44

User can check option [Intra Address] to use address offset, and check option [Batch] to add

multiple variables in batch.

User can select single added variable by Ctrl+LeftClick, select multiple added variables by

Shift+LeftClick, and click to remove them, as following figure shows.

43
Figure 2. 45

Display of the tendency curve


User needs to enable the display of the corresponding variable tendency curve by checking the

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.

Shown as following figure:

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 and track


The display of viewport is tracking the tendency of variable automatically by default. User can

lock the viewport by click icon in the variable list, so that user can adjust the viewport

freely.

Export and import


Click to export the curve data of selected variable out as CSV formatted file.

Click to import CSV file into curve data.

45
Usage of soft component
Soft component is operation target of ladder program, following table shows brief introduction of

the Samkoon PLC soft component types.

Soft component type Description data length

X Input coils. 1-bit

Y Output coils. 1-bit

M Inner coils. 1-bit

T Flag-bit of timer. 1-bit

C Flag-bit of counter. 1-bit

S State bit. 1-bit

D Inner data register. 2-byte

TV Timer. 2-byte

CV Counter. 2-byte (CV0~CV199), 4-byte (CV200~CV255)

AI Analog quantity input. 2-byte

AO Analog quantity output. 2-byte

V/Z index register. 2-byte

Table 3. 1

Word divides into bits


The 16-bit type soft component D/V/Z can be divided into bits.

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

2. Bit string as write address

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

in the routine where it is defined.

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

window, as the following figure.

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

read-only argument cannot be used as an output argument in an instruction; The write-only

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

before calling a subroutine, as following figure shows.

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

will return value to D10 after the subroutine is executed.

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.

Data R/W Binding target

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

(LBxxx), and other R or R/W bit argument in same routine.

BOOL W or Y/S/M/C/T bit soft component, divided bit from D/V/Z bit soft component, bit local variable (LBxxx),

R/W and other W or R/W bit argument in same routine.

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

R/W (LWxxx), and other W or R/W dword argument in same routine.

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

target can only be the TV soft component.

2. Use argument as a counter in counter instruction (CTU, CTD, CTUD). In this case, the

bound target can only be the CV soft component.

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.

Build a function block


Primer of C programming

C programming data type

Integer
Integer value includes integer constant value and integer variable value. In the C Programming,

the integer constants can be octonary, hexadecimal and decimal.

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:

legal: 015 (13) 0101 (65) 0177777 (65535)

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

following shows legal and illegal hexadecimal numbers:

legal: 0X2A (42) 0XA0 (160) 0XFFFF (65535)

illegal: 5A (no ‘0x’ as prefix) 0X3H (Contains ‘H’)

⚫ The decimal number only digits combined, every digit from 0 to 9. The following shows

legal and illegal decimal numbers:

legal: 237 -568 65535 1627

illegal: 023 (‘0’ cannot be prefix) 23D (Contains ‘D’)

The program identifies the number system by prefix, make sure the prefix is correct otherwise it

will cause the calculation result to get wrong.

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

a normal constant integer.

⚫ Short: The name of the data type is ‘short’,occupies 2 bytes in memory, the value is a

normal constant short integer.

⚫ Long: The name of the data type is ‘long’,occupies 8 bytes in memory, the value is a normal

constant long integers.

⚫ Unsigned: add unsigned before the data type.

The unsigned cooperates with the three integer types described above:

1) The name of the data type is ‘unsigned int’ or ‘unsigned’

2) The name of the data type is ‘unsigned short’

3) The name of the data type is ‘unsigned long’

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

type in the ARM core.

name of data type The value range bytes occupied

int -2147483648~2147483647 ■■■■

unsigned int 0~4294967295 ■■■■

short -32768~32767 ■■

unsigned short 0~65536 ■■

long -922337203685477808~922337203685477807 ■■■■■■■■

unsigned long 0~18446744073709551615 ■■■■■■■■

Table 4. 1

The declaration of the integer variable


The custom format to declare integer variables is: “data type variable 1, variable2, ....;” Such as:
int a, b, c //a, b, and c are integer
long x, y; //x and y are long integers

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

number system. Notation of real constant has the following 2 forms:

⚫ Notation with digit only, consists of 0~9 and dot. Such as “0.0”, “.25”, “5.789”, “0.13”, “5.0”,

“300.”, “-267.8230”, they are all the legal real numbers.

⚫ 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

is m×10n . For instance: “2.1E5” equal to 2.1×105 , “3.7E-2” equal to 3.7×10-2 .

The following shows some illegal real number examples:

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’

means that it is a float value. Such as “356f” means 356.0.

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~

3.4E+38 ,and value range of double is 1.7E-308~1.7E+308.


55
Format as writing rule of float variable declaration is same as integer. Such as:

float x, y; //x and y are float

double a, b, c; //a, b, and c are double

Example refer to following codes:

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

C Programming, char constant has the following features:

⚫ Char constant is surrounded with simple quotation, cannot use double quotation or other

brackets.

⚫ Char constant contains one char only, not a string.

⚫ 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

10, but ‘5’+5 not.

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:

char a, b; //a and b are char

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

‘x’ and ‘y’ to char variable a, b:


56
a= 'x'; b='x';

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

value to an integer variable, vice versa. Example refer to following codes:


char a = 49;
char b;
char d;
b = a + 10;
d = a + b;

char c1, c2;


c1 = 'a';
c2 = 'b';
c1 = c1 - 32;
c2 = c2 - 32;

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.

2. The char constant is only one char, string with more.

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

make it as a variable, instead of it as a pointer of char to the first address of a string.

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’,

‘g’, ‘r’, ‘a’, ‘m’, ‘\0’.

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

assigned and initialized by other type variable, For instance:

bool x = true; //x is initialized with true

bool x = false; //x is initialized with false

bool x = 0; //x is initialized with integer 0, it is false

bool x = 1; //x is initialized with integer 1, it is true

Macro defining
In the C Programming, The macro grammar ‘#define’ can let a name present to a constant or an

expression. The custom format is:

#define name expression

“#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 data type conversion


The data type of value can be converted. There are two ways to convert. The first is automatic

conversion, the second is force conversion (cast).

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

convert them to the same data type before calculation.

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

are converted to int at first.

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:

(the targeted data type)(expression)

It converts the result of an expression to the targeted data type. For instance: ‘(float)a’ converts a

to float, ‘(int)(x+y)’ converts the result of x+y to int.

Notice the details when doing force conversion:

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

conversion no influence to its original data type defined initially.

Operator and expression


C Programming contains rich operators and expressions, it is rare in the advanced programming.

This is a primary feature of C Programming.

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.

This makes it difficulty for C Programming.

The operators in C Programming can be distributed as following:

⚫ 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

than (>=), no greater than (<=), and not equal to (!=).

⚫ 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 ‘?’

and ‘:’, expression on false after ‘:’.

⚫ 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

Calculate the size occupied of data type (sizeof).

⚫ Special operator

Such as ‘()’, ‘[]’, and others.

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

use an array. The custom format of type declaration is:

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

shows some examples:

int a[10]; //Declaration an integer array named as ‘a’, it has 10 elements.

float b[10], c[20]; //Declaration two float arrays named as ‘b’ and ‘c’, ‘b’ has 10 elements and

‘c’ has 20.

char ch[20]; //Declaration a char array named as ‘ch’, it has 10 elements.

Notice the rules of array declaration:

1. The type of array is same as the data type of array element. With an array, the elements

included must be same data type.

2. The spell rule of array name is same as variable.

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];

Presenting method of array elements


The elements are primary units to combine an array, it can also be regard as variables, which

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

index variable can be used as a variable, but an array cannot.

62
The format of initialize value assign is:

static datatype arrayname[length] = {value, value, ..., value};

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, 5, 6, 7, 8, 9}; //a[0]=0, a[1]=1, ...a[9]=9

The initialization of array


1. Assigning part elements of array is permitted. While the values in “{}” is less than the length

of array, it assigns value to prefix part of array. 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:

static int a[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

but not:

static int a[10] = 1;

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:

static int a[5] = {1, 2, 3, 4, 5};

static int[] = {1, 2, 3, 4, 5};

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

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

become simpler and more convenient.

The design of C programming


Statement of C programming
The executing unit of C Programming is a statement. The statement implements the function of

the program. The series of statements of C Programming can be divided as follows:

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:

y+z; //calculate y plus with z, result is not reserved

y>z; //compare y with z, it is true when y>z, it is false when y<=z

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:

⚫ Condition keyword: if, switch.

⚫ Loop keyword: do-while, while, for.

⚫ Jump keyword: break, goto, continue, return.

3. Empty statement

The statement has no content but only a char ‘;’ at the end. An empty statement executing

nothing, but it can be applied in a loop structure. For instance:

while(getchar() != '\n')

; //do nothing while input is not ‘\n’(enter)

}
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

be used nested. For instance, the following 2 statement are equivalent:

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

a part of variable declaration, multiple variables in a declaration must be divided by

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

variable must be the same. For instance:

int a = b = c = 5; //error, variable cannot be initialized by nested assignment

int a = 5, b = 5, c = 5; //right, each variable should be initialized apart

⚫ Notice that the difference of expression statement and assignment statement. Expression

statement can be used for condition of conditional structure, but assignment statement

cannot. For instance:

if (x=y) z = x+y; //error, “x=y” is assignment statement

if (x==y) z = x+y; //right, “x==y” is expression statement

Conditional structure
Relation operator and expression
Operator that compares two operands is called relation operator. Details of relation operators refer

to following table (in the example, int A = 10, B = 20):

Operator Description Example

66
== Check if two operands is equal, if equal the condition is true. (A == B) is false

!= Check if two operands is equal, if equal the condition is false. (A != B) is true

> 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

priority of “==” and “!=” is same.

Logical operator and expression


Logical operators judge truth-value of expressions combining, there are 3 kinds of logical

operators, shown as following table (in the example, bool A = true, bool B = false):

Operator Description Example

&& And operator, condition is true when two operands is true. (A && B) is false

|| Or operator, condition is true when one of two operands is true. (A || B) is true

! Not operator. condition is opposite to the operand (!A) 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

under other conditions will be passed. For Instance:

if (a = b)

printf("%d", a); //output value of a when a is equal to b

else

printf("a=0"); //output string “a=0” when a is not equal to b

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

be passed. For instance:

int a;

switch (a) {

case 0: {

printf("a=0"); //output string “a=0” when a is equal to 0

case 1: {

printf("a=1"); //output string “a=1” when a is equal to 1

default: {

printf("error"); //output string “error” when a is not equal to 0 or 1

conditional operator and expression


The conditional operator “?” and “:” can also be used for conditional statements. condition

operator is ternary operator, the format shows as following:

expression1 ? expression2 : expression3;

In this statement, if expression1 is true, this statement returns expression2; When an expression is

false, this statement returns expression3. For instance:

a>b ? max = a : max = b; //max=a when a>b, max=b when b>=a

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

continue repeatedly until the expression is false.

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

processing will continue until the expression is false.

For statement
The custom format of for statement is:

for (expression1; expression2; expression3) {

statements;

70
}

The expression1 is always used to initialize an iterating variable as a start value. If this iterating

variable is initialized before, this expression can be hidden.

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 expression3 is always used to iterate the iterating variable.

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("input the enter to stop");

for (; getchar() != '\n'; n++) {

printf("%d", n); //output increasing number until user input the enter

Continue and break


The keyword “continue” can be used in the loop content, it ends the current loop turn, pass left

statements, and start the next turn loop (judge of target condition and execution of loop content). For

instance:

int x = 1

while (x < 10) {

printf ("%d", x); //output 0 1 2 3 4 5 6 7 8 9

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

after the loop statements. For instance:

int x = 0

while (x < 10) {

71
printf ("%d", x); //output 0 1 2 3 4

if (x == 5) break; //jump out from the loop when x is equal to 5

The usage of function block


Create a new function block
1. Right click the [Project] -> [Program] -> [FuncBlock] folder, open the context menu and

click [Create FuncBlock], to display the setting dialog.

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

the realized functions.

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

Condition of function to be called by CALLM


Although the function in the function block accepted the compile, it is not presented that it can be

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,

WORD l, WORD m)” has 5 arguments, is invalid in this condition.

2. The data types of all the arguments must be all uppercase characters. In fact, they are all the

pointer of the primary data type.


Name Data type Description
BIT uint32_t* The pointer of bit register(M/Y/S)
WORD int16_t* The pointer of signed word register(D/TV/CV/AO)
UWORD uint16_t* The pointer of unsigned word
DWORD int32_t* The pointer of signed double word
UDWORD uint32_t* The pointer of unsigned double word

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.

Use function block to edit instruction list


Introduction
While editing the ladder diagram, besides editing the ladder directly, the SamSoarII supports

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

show the instruction list only.

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

to write the ladder-building functions.

76
Operation
1. In the project explorer, right click the ladder diagram wanted to edit, open the context menu,

then click [Create Ladder-Building Function].

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

application automatically detects it as a ladder-building function and create its ladder

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

ladder program to build.

⚫ 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

is wrong, the wrong messages are displayed in the error list.

Figure 4. 13

Make sure the function is valid and accept the compile, so that the ladder be built

automatically.

78
Figure 4. 14

What should be noted is:

⚫ The ladder-building function must follow this structure. Otherwise the built ladder will be

unfamiliar with its original structure.

⚫ Call the ladder-building function by CALLM instruction or function block, nothing will be

executed, please avoid these two situations.

⚫ Users can write a comment in the ladder-building function, but please do not comment out

the instruction and the ‘,’ split label.

Usage of soft component in function block


In the function block built by user, besides using function arguments and local variables, user can

also directly use the register like ladder diagram.

The variable of soft component


Every soft component has its base address as a global pointer variable in the function block. For

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*)

CV32 CVDoubleWord DWORD(int32_t*)

Table 4. 5

Example
Ladder program:

Figure 4. 15

Function block:

void Func()

if (MBit[0])

if (MBit[1]) YBit[0] = 1;

if (MBit[2]) DWord[2+VWord[0]] = DWord[0] + DWord[1];

The function block takes the same effect as the ladder diagram. But what should be noted is, the

function cannot replace the ladder diagram totally.

Simplification
Add the attribute statement “[Simplify("Register")]” before the header of a function to enable you

to simplify the usage of register. For instance:

[Simplify("Register")]

void Func()

80
{

if (M0)

if (M1) Y0 = 1;

if (M2) D2V0 = D0 + D1;

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:

1. Offset verified by V/Z register

Such as D0V0, in the original C Programming it must be written as “DWord[0+VWrod[0]]”. With

simplification, it can be directly inputted as “D0V0”.

2. The conversion of data type

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,

to get a double word value in D0(D1), it needs to be written as “*((DWORD)(DWord+0))”. With

simplification, it can be written as “DD0”.

The following shows the comparing from the original code to simplify code:

Before simplification After simplification

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

[Tool]->[Simulate] or icon to switch to simulation mode.

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

to pause the simulation; Click to stop the simulation.

When simulation starts, user can monitor the value of the soft component, and modify most of

them. The program will refresh after modification.

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

when meeting the call.

Jump out: When pausing in the subroutine or function block, process the rest of it, jump out

to main routine and pause at the next instruction.

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

menu, and select [Add breakpoint], as following figure shows.

Figure 5. 6

The breakpoint position will be marked with red block.

Breakpoint management
Right click at breakpoint, and select [Breakpoint point] in the pulldown menu, display the

breakpoint list window to manage the breakpoint.

Figure 5. 7

⚫ [Jump]: Program executes to the selected breakpoint and pause.

⚫ [Enable/Disable]: Enable or Disable the selected breakpoint.

84
⚫ [Release]: Delete the breakpoint immediately.

⚫ [Release All]: Clear all the breakpoints.

⚫ [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

limit interrupt will be triggered and the times will be cleared.

Soft component breakpoint


Similar to breakpoint, the soft component breakpoint will also pause the execution of the program

when a specified condition is met.

Click [View]->[Component breakpoint] or icon to display the component breakpoint list, as

the following figure shows.

Figure 5. 9

⚫ [Condition add]: Add a component breakpoint, and the user needs to set the condition to

make the breakpoint valid.

⚫ [Enable/Disable]: Enable or disable the component breakpoint.

⚫ [Delete]: Delete the selected component breakpoint.

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.

⚫ [Comparison source]: Source soft component of the condition to compare.

⚫ [Comparison target]: Target value or soft component to compare with.

⚫ [Comparison type]: Data type of compared data.

⚫ [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,

less than comparison target, no greater 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

programming like a flow diagram, it is visualized and easy to understand.

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.

Right-click in the edition to display the pulldown menu.

Figure 6. 4

⚫ [Cut]: Copy the element in the selected grid it to the clipboard, and delete the one in grid.

⚫ [Copy]: Copy the element in the selected grid to clipboard.

⚫ [Paste]: Paste the element in the clipboard to the selected grid.

⚫ [Delete]: Delete the element in the selected 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

transfer to the state unit connected below.

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,

multiple sentences are divided with comma.

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

and output instruction in only one of them to avoid confusion.

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

setting refer to state unit.

Figure 6. 11

Condition branch unit


The condition branch unit connects one root state unit and multiple branch state units. Each branch

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 parameter is set with a specified format sentence:

(condition1) column1, (condition2) column2 …

the “condition” refers to SFC condition expression, and the “column” is the number that which

column the branch locates at.

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 parameter is set with a specified format sentence:

(condition) column1, column2 …

the “condition” refers to SFC condition expression, and the “column” is the number that which

column the branches located at.


93
CP branch unit
CP branch unit is combination of condition branch unit and parallel branch unit.

Figure 6. 16

User can double click the selected grid to display the unit dialog, and insert CP branch unit.

Figure 6. 17

The parameter is set with a specified format sentence:

(condition1) column1, column2 …;

(condition2) column3, column4…

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 parameter is set with a specified format sentence:

(condition1) column1, (condition2) column2 …

the “condition” refers to SFC condition expression, and the “column” is the number that which

column the branch locates at.

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 parameter is set with a specified format sentence:

(condition) column1, column2 …

the “condition” refers to SFC condition expression, and the “column” is the number that which

column the branches located at.

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 parameter is set with a specified format sentence:

(condition1) column1, column2 …;

(condition2) column3, column4…

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

table shows the usage of operand and operator:

Operand Description Usage example

Register Get value of the register M0, D0, CV235

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

Constant Constant value K123 (word), K3.14 (float), K123456

(dword)

Divided bit Bit divided from word register D0.0, D0.1

Bit string Bit string merged by bit registers K16M0, K32M0

Alia Alias of specified soft component RN1 (alia of M8160)

Operator Description Usage example

and And logic operation with two operands or expressions M0 and M1, D0 and H00FF,

D0<0 and D10>10

or Or logic operation with two operands or expressions X0 or X2, D10<100 or M3

not Not logic operation of operand or expression not M2, not(D0=100)

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)

im Immediately read of X/Y register, get value regardless of scan im X0, im Y0

period of PLC

+ Addition with two operands or expressions D0+2<10

- Subtraction with two operands or expressions D0-2>10

* Multiplication with two operands or expressions D0*D1

/ Division with two operands or expressions D0/2

= Equal comparison with two operands or expressions D0=10

98
!= Not equal comparison with two operands or expressions D10!=20

> Greater-than comparison between two operands or expressions D20>30

< Less-than comparison between two operands or expressions D30<40

>= No-less-than comparison between two operands or expressions D40>=50

<= No-greater-than comparison between two operands or expressions D50<=60

Table 6. 1

99

You might also like