WasomCodeX試用-工程文件結構
官方的Gitee提供了Tutorial程序供下載學習。
打開后,可以看到程序結構。

在這個程序里,可以看到從main主程序到各個FC都寫在一個文件里。
同時,通過終端查看下文件目錄結構。
/wasomeide_workspace/tutorials/projects/ch05-1$ tree -l
.
├── ams_pack.log
├── build
│ ├── app.tar.gz
│ ├── app.zip
│ ├── debug
│ │ ├── app.bin
│ │ ├── app.layout
│ │ ├── iec.cfg
│ │ ├── iec.io_map
│ │ ├── iec.sn
│ │ └── resources
│ │ └── project.manifest
│ └── release
│ ├── app.bin
│ ├── app.layout
│ ├── iec.cfg
│ ├── iec.io_map
│ ├── iec.sn
│ └── resources
│ └── project.manifest
├── CONFIG
│ ├── build.id
│ ├── global.WAVARS
│ ├── project.IOMAP
│ ├── resources
│ │ └── project.manifest
│ └── resources.WARES
├── MODULES
├── PROGRAM
│ ├── DOUs
│ │ └── User_DataTypes.json
│ ├── POU_FBs
│ ├── POU_FULL_ST
│ ├── POU_FUNCs
│ ├── POU_PRGs
│ │ └── prog_main.st
│ └── SYS_EVENTS
└── README.md
16 directories, 23 files
可以看到,主要就是一個在PROGRAM/POU_PRGs路徑下的prog_main.st文件。
我們再查看下這個文件內容:
/wasomeide_workspace/tutorials/projects/ch05-1$ cat PROGRAM/POU_PRGs/prog_main.st
(* 本APP展示基本變量定義、賦值、使用; 表達式、基本流程語句的用法 *)
PROGRAM PLC_PRG
VAR
b: BOOL; (**BOOL類型的變量定義*)
n: INT := 10; (*初始化為10*)
r: REAL := 5.2;
s: SINT;
d: ARRAY[0..2] OF DINT; (*定義長度為3的一維數組*)
END_VAR
b := convertToBOOL(n); (*調用函數并將返回值賦給變量b*)
s := convertToSINT(TO_DINT(r));
d[0] := getSumWithFor(s); (*使用for語句實現的函數*)
d[1] := getSumWithWhile(s); (*使用while語句實現的函數*)
d[2] := getSumWithRepeat(s); (*使用repeat語句實現的函數*)
WA_LOG('g_iVar1=%d, g_iVar2=%d, g_bVar=%d, g_fVar1=%f, g_sVar=%s',
g_iVar1, g_iVar2, TO_INT(g_bVar), g_fVar1, g_sVar);
g_fVar1 := g_fVar1 + 0.1;
END_PROGRAM
(** 使用IF ELSE 語句將INT轉換為BOOL *)
FUNCTION convertToBOOL : BOOL
VAR_INPUT level: INT; END_VAR
IF level > 10 THEN
convertToBOOL := TRUE;
ELSIF level <= 10 THEN
convertToBOOL := FALSE;
ELSE
convertToBOOL := TRUE;
END_IF;
END_FUNCTION
...
可以看到,st程序的文本就在這個文件里面。
咨詢了廠方工程師,被告知FC、FB也可以分多個文件保存。于是,按照該樣例程序內容,重新寫了一個。

這個程序里,我把FC都拆到了函數欄里,一個個獨立開來,可以看到主程序就顯得干凈很多,看起來和另外幾個PLC編程軟件類似了。
再看下文件結構:
/wasomeide_workspace/tutorials/projects/Tutorials-1$ tree -l
.
├── ams_pack.log
├── build
│ ├── app.tar.gz
│ ├── app.zip
│ ├── debug
│ │ ├── app.bin
│ │ ├── app.layout
│ │ ├── iec.cfg
│ │ ├── iec.io_map
│ │ ├── iec.sn
│ │ └── resources
│ │ └── project.manifest
│ └── release
│ ├── app.bin
│ ├── app.layout
│ ├── iec.cfg
│ ├── iec.io_map
│ ├── iec.sn
│ └── resources
│ └── project.manifest
├── CONFIG
│ ├── build.id
│ ├── global.WAVARS
│ ├── project.IOMAP
│ ├── resources
│ │ └── project.manifest
│ └── resources.WARES
├── MODULES
└── PROGRAM
├── DOUs
│ └── User_DataTypes.json
├── POU_FBs
├── POU_FULL_ST
│ ├── convertToBOOL.st
│ ├── convertToSINT.st
│ ├── getSumWithFor.st
│ ├── getSumWithRepeat.st
│ ├── getSumWithWhile.st
│ └── main.st
├── POU_FUNCs
├── POU_PRGs
└── SYS_EVENTS
可以看到,在POU_FULL_ST路徑下,多了幾個st文件,包括出程序main.st以及幾個函數。
再看下main.st的內容:
/wasomeide_workspace/tutorials/projects/Tutorials-1$ cat PROGRAM//POU_FULL_ST/main.st
(* 本APP展示基本變量定義、賦值、使用; 表達式、基本流程語句的用法 *)
PROGRAM PLC_PRG
VAR
b: BOOL; (**BOOL類型的變量定義*)
n: INT := 10; (*初始化為10*)
r: REAL := 5.2;
s: SINT;
d: ARRAY[0..2] OF DINT; (*定義長度為3的一維數組*)
END_VAR
b := convertToBOOL(n); (*調用函數并將返回值賦給變量b*)
s := convertToSINT(TO_DINT(r));
d[0] := getSumWithFor(s); (*使用for語句實現的函數*)
d[1] := getSumWithWhile(s); (*使用while語句實現的函數*)
d[2] := getSumWithRepeat(s); (*使用repeat語句實現的函數*)
WA_LOG('g_iVar1=%d, g_iVar2=%d, g_bVar=%d, g_fVar1=%f, g_sVar=%s',
g_iVar1, g_iVar2, TO_INT(g_bVar), g_fVar1, g_sVar);
g_fVar1 := g_fVar1 + 0.1;
END_PROGRAM
可以看到,對應的就是主程序的內容了。

浙公網安備 33010602011771號