Skip to content

Commit

Permalink
Merge pull request #21 from simatic-ax/fix_ci_workflow
Browse files Browse the repository at this point in the history
Fix ci workflow
  • Loading branch information
sjuergen authored Jun 1, 2023
2 parents 24c0361 + 14748dd commit b74e06e
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 6 deletions.
12 changes: 6 additions & 6 deletions apax.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: "apax-package-name-d7b4b031"
version: 1.0.0
version: 3.0.0
type: lib
targets:
- "1500"
# - axunit-llvm
dependencies:
"@simatic-ax/json": 4.1.2
"@simatic-ax/statemachine": 2.1.1
"@simatic-ax/json": 4.1.3
"@simatic-ax/statemachine": 2.1.2
devDependencies:
"@ax/sdk": 3.0.10
"@ax/ax2tia": 4.2.10
"@simatic-ax/snippetscollection": 0.0.15
"@ax/sdk": 3.0.18
"@ax/ax2tia": 4.5.4
"@simatic-ax/snippetscollection": 0.1.3
variables:
GLOBAL_LIBRARY_PATH: "apax-package-name-d7b4b031"
LIBRARY_DOCUMENTS_FOLDER: "HandoverLibraryDocuments"
Expand Down
75 changes: 75 additions & 0 deletions src/JsonParser/JsonParser.st
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
25 changes: 25 additions & 0 deletions test/JsonParser/TestJsonParster.st
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

0 comments on commit b74e06e

Please sign in to comment.