-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from simatic-ax/fix_ci_workflow
Fix ci workflow
- Loading branch information
Showing
3 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
USING Simatic.Ax.Json; | ||
USING Simatic.Ax.Conversion; | ||
USING AxUnit.Assert; | ||
|
||
NAMESPACE Simatic.Ax.Tiax | ||
|
||
/// {"DeviceName": "Device1", "Parameter": {"IP": "192.168.0.1", "Timeout": 300, "AutoConnect": true}} | ||
FUNCTION_BLOCK JsonParser | ||
VAR_INPUT | ||
Execute : BOOL; | ||
JsonAsString : STRING; // := '{"Name": "SIMATIC", "data": {"plc_type: 1518", "OPC_SERVER_ENABLED": 1}}'; | ||
END_VAR | ||
VAR_OUTPUT | ||
Name : STRING; | ||
Plc_type : INT; | ||
Opc_server_enabled : BOOL; | ||
END_VAR | ||
VAR | ||
_init : BOOL; | ||
deserializer : Deserializer; | ||
buffer : ARRAY[0..200] OF CHAR; | ||
_executeOld : BOOL; | ||
len : DINT; | ||
keyArray: ARRAY [0..1] OF STRING; | ||
value: STRING; | ||
valueInt : INT; | ||
keyFound: BOOL; | ||
END_VAR | ||
VAR_TEMP | ||
|
||
executeRis : BOOL; | ||
END_VAR | ||
|
||
// Check the execute signal | ||
executeRis := Execute AND NOT (_executeOld); | ||
_executeOld := Execute; | ||
|
||
IF (executeRis) THEN | ||
|
||
// Convert String to "ArrayOfChar" | ||
len:= Strings.ToArray.OfCharCount(str := JsonAsString, arr := buffer); | ||
deserializer.buffer := REF(buffer); | ||
|
||
// Parse for String Name and expect value "SIMATIC" | ||
keyFound := deserializer.TryParse( 'Name', value); | ||
IF (keyFound) THEN | ||
Name := value; | ||
ELSE | ||
Name := 'not found'; | ||
END_IF; | ||
|
||
// Parse for nested key darta.plc_type and expect value 1518 | ||
keyArray[0] := 'data'; | ||
keyArray[1] := 'plc_type'; | ||
keyFound := deserializer.TryParse(keyArray, valueInt); | ||
IF (keyFound) THEN | ||
Plc_type := valueInt; | ||
ELSE | ||
Plc_type := -1; | ||
END_IF; | ||
|
||
// Parse for Integer plc_type and expect value 1518 | ||
keyArray[0] := 'data'; | ||
keyArray[1] := 'OPC_SERVER_ENABLED'; | ||
keyFound := deserializer.TryParse(keyArray, valueInt); | ||
IF (valueInt = 1) THEN | ||
Opc_server_enabled := TRUE; | ||
ELSE | ||
Opc_server_enabled := FALSE; | ||
END_IF; | ||
|
||
END_IF; | ||
END_FUNCTION_BLOCK | ||
|
||
END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
USING Simatic.Ax.Conversion; | ||
USING Simatic.Ax.Json; | ||
USING AxUnit.Assert; | ||
USING System.Strings; | ||
|
||
NAMESPACE Simatic.Ax.Tiax | ||
|
||
{TestFixture} | ||
CLASS TestJsonParserWrapper | ||
VAR | ||
JsonParserWrapper : JsonParser; | ||
END_VAR | ||
|
||
{Test} | ||
METHOD PUBLIC MyTestMethod | ||
JsonParserWrapper.JsonAsString := '{"Name": "SIMATIC", "data": {"plc_type": 1518, "OPC_SERVER_ENABLED": 1}}'; | ||
JsonParserWrapper(execute := TRUE); | ||
; // AxUnit.Assert.Equal(y, x) | ||
Equal(expected := 'SIMATIC', actual := JsonParserWrapper.Name); | ||
Equal(expected := 1518, actual := JsonParserWrapper.Plc_type); | ||
Equal(expected := TRUE, actual := JsonParserWrapper.Opc_server_enabled); | ||
END_METHOD | ||
END_CLASS | ||
|
||
END_NAMESPACE |