Diff of /trunk/json/json-pac/Examples/ExampleJSON_PRG/svnobj [r7] .. [r8]  Maximize  Restore

Switch to side-by-side view

--- a/trunk/json/json-pac/Examples/ExampleJSON_PRG/svnobj
+++ b/trunk/json/json-pac/Examples/ExampleJSON_PRG/svnobj
@@ -1,5 +1,4 @@
-Gx_lb*!0…jüo	"£Õ9×1‘ovøSystem.StringL{6f9dac99-8de1-4efc-8465-68ac443b7d08}SpecialFuncL{0db3d7bb-cde0-4416-9a7b-ce49a0124323}NoneImplementationL{3b83b776-fb25-43b8-99f2-3c507c9143fc}TextDocument	L{f3878285-8e4f-490b-bb1b-9acbb7eb04db}
-TextLinesL{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}Id
longTagTextÒ(*======================================================================================================="ExampleJSON_PRG()VAuthor: Tim Van Meppelen, Pro Electric Inc.(timv@proelectric.com"Date: Nov 2, 2018’example program demonstrating JSONVAR, STRUCT_TO_JSON, AND JSON_TO_STRUCTÐThis example will populate a structure with values and types.  On a rising edge of ComposeJSON.Execute, ÈComposeJSON will create a JSON string.  When ComposeJSON.Done is set, ParseJSON.Execute is set, and ‚ParseJSON will parse that string back into a different structure.~Tested with 200mS cyclic task, GPL_JSON.MAX_EXECUTION_TIME=50mS²Depending on the application and speed of the controller, these values could be changed. ¦Be aware of how much cycle time is being taken when using multiple function blocks.ÊEach function block will limit its time to GPL_JSON.MAX_EXECUTION_TIME, but multiple function blocks ªcould take up more than that.  This is on the list of things that could be improved. JSONVAR ¬FB_Init will fill in information about the variable name and structure in VarNameArray! variable type and size are automatically determined when a value is set, either:"Ò	-with the set accessor of the AsString Property, which will make a guess at the type, based on the value#¾	-with any of the set accessors of the CharString, Boolean, Integer, Number, or Null properties$Zvariable name is set automatically in FB_Init%@	-variable name is the JSON name&Æ	-JSON allows some object names that are not valid variable names in IEC61131, for example "type", 'Â	"3h", etc.  Workaround is to put an underscore at the beginning of the variable name.  This will(¼	match in JSON_TO_STRUCT, and STRUCT_TO_JSON will create a name without the leading underscore)	*JSON_TO_STRUCT+nconvert a JSON string into a local structure of JSONVAR,ÐLong strings can take several seconds--for example, I have tested with a string of 20kB length, and the -Òparse time is about 4 seconds.  Ensuring that the local variable structure is designed to be as close as .Öpossible to the expected order of variables in the JSON string will decrease parsing time, the search loop /¦always starts with the next local variable and loops around until a match is found.0STRUCT_TO_JSON1jconvert a local structure of JSONVAR to a JSON string2ž.Format input will create indenting and new lines, useful for writing to a file3GPL_JSON4ÐParameter list that contains limits on size of strings, arrays, etc.  Most of these variables are simply5Òto limit memory usage, so they can be increased or decreased to suit the local application and controller6Ô========================================================================================================*)7BLocalJSONObj.var1.Boolean:= TRUE;8FLocalJSONObj.var2.Number:= 34.8756;9XLocalJSONObj.var3.CharString:= 'teststring';:DLocalJSONObj.obj.var4.Number:= 22;;ºLocalJSONObj.obj.var5.AsString:= 'FALSE';	//JSONVAR will guess at type, in this case, boolean<TLocalJSONObj.obj.var6.CharString:= 'qwer';=TLocalJSONObj.obj.var7[1].Number:= 123.234;>ÂLocalJSONObj.obj.var7[2].AsString:= '55.46';	//JSONVAR will guess at type, in this case, a number?LLocalJSONObj.obj.var7[3].Number:= 985;@HLocalJSONObj.arrayobj[1].Number:= 1;AHLocalJSONObj.arrayobj[2].Number:= 2;BHLocalJSONObj.arrayobj[3].Number:= 3;CP//create a JSON string from local objectDComposeJSON(E>	JSONString:= ADR(JSONString), FJ	JSONStringSize:= SIZEOF(JSONString),G<	JSONVars:= ADR(LocalJSONObj),Hl	NumberOfVars:= SIZEOF(LocalJSONObj) / SIZEOF(JSONVAR)I);Jˆ//fill another local object with values from the created JSON stringKParseJSON(L8	Execute:= ComposeJSON.Done,M8	JSONVars:= ADR(NewJSONObj),Nh	NumberOfVars:= SIZEOF(NewJSONObj) / SIZEOF(JSONVAR)OInterfacePL{a9ed5b7e-75c5-4651-af16-d2c27e98cb94}Q.PROGRAM ExampleJSON_PRGRVARSD	LocalJSONObj:		EXAMPLEJSONSTRUCT;T<	ComposeJSON:		STRUCT_TO_JSON;U8	JSONString:			STRING(1000);VD	NewJSONObj:			EXAMPLEJSONSTRUCT;	W:	ParseJSON:			JSON_TO_STRUCT;XEND_VARY"UniqueIdGeneratorZ417[POULevel\L{8e575c5b-1d37-49c6-941b-5c0ec7874787}]Standard^ ChildObjectGuids_8System.Collections.ArrayList`,AddAttributeSubsequentaboolÐÐ-ÐÐ	E
-KÐÐ
­aÚÐ-ÐÐ
­bÚÐ-ÐÐ
­cÚÐ-ÐÐ
­dÚÐ-ÐÐ
­eÚÐ-ÐÐ
­”ÚÐ-ÐÐ
­•ÚÐ-ÐÐ
­—ÚÐ-ÐÐ
­™ÚÐ-ÐÐ
­sÚÐ-ÐÐ
­tÚÐ-ÐÐ
­“ÚÐ-ÐÐ
­uÚÐ-ÐÐ
­vÚÐ-ÐÐ
­xÚÐ-ÐÐ
­ÚÐ-ÐÐ
­‡ÚÐ-ÐÐ
­ˆÚÐ-ÐÐ
­†ÚÐ- ÐÐ
­‹ÚÐ-!ÐÐ
­ŒÚÐ-"ÐÐ
­ÚÐ-#ÐÐ
­ŽÚÐ-$ÐÐ
­ÚÐ-%ÐÐ
­ÚÐ-&ÐÐ
­‘ÚÐ-'ÐÐ
­’ÚÐ-(ÐÐ
­ÚÐ-)ÐÐ
­ŠÚÐ-*ÐÐ
­€ÚÐ-+ÐÐ
­‚ÚÐ-,ÐÐ
­ƒÚÐ--ÐÐ
­„ÚÐ-.ÐÐ
­yÚÐ-/ÐÐ
­zÚÐ-ÐÐ
­…ÚÐ-0ÐÐ
­¡ÚÐ-1ÐÐ
­šÚÐ-2ÐÐ
­žÚÐ-ÐÐ
­ŸÚÐ-3ÐÐ
­ ÚÐ-4ÐÐ
­iÚÐ-5ÐÐ
­jÚÐ-ÐÐ
­kÚÐ-6ÐÐ
­lÚÐ-ÐÐ
­ÀÚÐ-7ÐÐ
­ÁÚÐ-8ÐÐ
­nÚÐ-9ÐÐ
­ÄÚÐ-:ÐÐ
­ÅÚÐ-;ÐÐ
­pÚÐ-<ÐÐ
­qÚÐ-=ÐÐ
­rÚÐ->ÐÐ
­ÆÚÐ-?ÐÐ
­ÇÚÐ-@ÐÐ
­ÈÚÐ-AÐÐ
­½ÚÐ-BÐÐ
­VÚÐ-ÐÐ
­0ÚÐ-CÐÐ
­2ÚÐ-DÐÐ
­GÚÐ-EÐÐ
­5ÚÐ-FÐÐ
­6ÚÐ-GÐÐ
­<ÚÐ-HÐÐ
­@ÚÐ-IÐÐ
­WÚÐ-ÐÐ
­AÚÐ-JÐÐ
­`ÚÐ-KÐÐ
­BÚÐ-LÐÐ
­HÚÐ-EÐÐ
­CÚÐ-FÐÐ
­DÚÐ-MÐÐ
­EÚÐ-NÐÐ
­IÚÐ-IÐÐ
­ÚÐ-ÐOPÐ	E
-
-ÐÐ
­ÚÐ-QÐÐ
­ZÚÐ-RÐÐ
­[ÚÐ-SÐÐ
­_ÚÐ-TÐÐ
­\ÚÐ-)ÐÐ
­SÚÐ-UÐÐ
­^ÚÐ-ÐÐ
­TÚÐ-VÐÐ
­XÚÐ-WÐÐ
­ÚÐ-XÐY-ZÐ[\-]^_Ð`a­
\ No newline at end of file
+Gx_l"+!0…jüoi"ROQn‘îWäSystem.StringL{6f9dac99-8de1-4efc-8465-68ac443b7d08}SpecialFuncL{0db3d7bb-cde0-4416-9a7b-ce49a0124323}NoneImplementationL{3b83b776-fb25-43b8-99f2-3c507c9143fc}TextDocument	L{f3878285-8e4f-490b-bb1b-9acbb7eb04db}
+TextLinesL{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}Id
longTagTextÒ(*======================================================================================================="ExampleJSON_PRG()VAuthor: Tim Van Meppelen, Pro Electric Inc.(timv@proelectric.com"Date: Nov 2, 2018’example program demonstrating JSONVAR, STRUCT_TO_JSON, AND JSON_TO_STRUCTÐThis example will populate a structure with values and types.  On a rising edge of ComposeJSON.Execute, ÈComposeJSON will create a JSON string.  When ComposeJSON.Done is set, ParseJSON.Execute is set, and ‚ParseJSON will parse that string back into a different structure.~Tested with 200mS cyclic task, GPL_JSON.MAX_EXECUTION_TIME=50mS²Depending on the application and speed of the controller, these values could be changed. ¦Be aware of how much cycle time is being taken when using multiple function blocks.ÊEach function block will limit its time to GPL_JSON.MAX_EXECUTION_TIME, but multiple function blocks ªcould take up more than that.  This is on the list of things that could be improved. JSONVAR ¬FB_Init will fill in information about the variable name and structure in VarNameArray! variable type and size are automatically determined when a value is set, either:"Ò	-with the set accessor of the AsString Property, which will make a guess at the type, based on the value#¾	-with any of the set accessors of the CharString, Boolean, Integer, Number, or Null properties$Zvariable name is set automatically in FB_Init%@	-variable name is the JSON name&Æ	-JSON allows some object names that are not valid variable names in IEC61131, for example "type", 'Â	"3h", etc.  Workaround is to put an underscore at the beginning of the variable name.  This will(¼	match in JSON_TO_STRUCT, and STRUCT_TO_JSON will create a name without the leading underscore)	*JSON_TO_STRUCT+nconvert a JSON string into a local structure of JSONVAR,ÐLong strings can take several seconds--for example, I have tested with a string of 20kB length, and the -Òparse time is about 4 seconds.  Ensuring that the local variable structure is designed to be as close as .Öpossible to the expected order of variables in the JSON string will decrease parsing time, the search loop /¦always starts with the next local variable and loops around until a match is found.0STRUCT_TO_JSON1jconvert a local structure of JSONVAR to a JSON string2ž.Format input will create indenting and new lines, useful for writing to a file3GPL_JSON4ÐParameter list that contains limits on size of strings, arrays, etc.  Most of these variables are simply5Òto limit memory usage, so they can be increased or decreased to suit the local application and controller6Ô========================================================================================================*)7BLocalJSONObj.var1.Boolean:= TRUE;8FLocalJSONObj.var2.Number:= 34.8756;9XLocalJSONObj.var3.CharString:= 'teststring';:DLocalJSONObj.obj.var4.Number:= 22;;ºLocalJSONObj.obj.var5.AsString:= 'FALSE';	//JSONVAR will guess at type, in this case, boolean<TLocalJSONObj.obj.var6.CharString:= 'qwer';=TLocalJSONObj.obj.var7[1].Number:= 123.234;>ÂLocalJSONObj.obj.var7[2].AsString:= '55.46';	//JSONVAR will guess at type, in this case, a number?LLocalJSONObj.obj.var7[3].Number:= 985;@HLocalJSONObj.arrayobj[1].Number:= 1;AHLocalJSONObj.arrayobj[2].Number:= 2;BHLocalJSONObj.arrayobj[3].Number:= 3;CP//create a JSON string from local objectDComposeJSON(E>	JSONString:= ADR(JSONString), FJ	JSONStringSize:= SIZEOF(JSONString),G<	JSONVars:= ADR(LocalJSONObj),Hl	NumberOfVars:= SIZEOF(LocalJSONObj) / SIZEOF(JSONVAR)I);Jˆ//fill another local object with values from the created JSON stringKParseJSON(L8	Execute:= ComposeJSON.Done,M8	JSONVars:= ADR(NewJSONObj),Nh	NumberOfVars:= SIZEOF(NewJSONObj) / SIZEOF(JSONVAR)O"CreateJSONInFB();PInterfaceQL{a9ed5b7e-75c5-4651-af16-d2c27e98cb94}R.PROGRAM ExampleJSON_PRGSVARTD	LocalJSONObj:		EXAMPLEJSONSTRUCT;U<	ComposeJSON:		STRUCT_TO_JSON;V8	JSONString:			STRING(1000);WD	NewJSONObj:			EXAMPLEJSONSTRUCT;	X:	ParseJSON:			JSON_TO_STRUCT;Y:	CreateJSONInFB:		EXAMPLE_FB;ZEND_VAR["UniqueIdGenerator\421]POULevel^L{8e575c5b-1d37-49c6-941b-5c0ec7874787}_Standard` ChildObjectGuidsa8System.Collections.ArrayListb,AddAttributeSubsequentcboolÐÐ-ÐÐ	E
+MÐÐ
­aÚÐ-ÐÐ
­bÚÐ-ÐÐ
­cÚÐ-ÐÐ
­dÚÐ-ÐÐ
­eÚÐ-ÐÐ
­”ÚÐ-ÐÐ
­•ÚÐ-ÐÐ
­—ÚÐ-ÐÐ
­™ÚÐ-ÐÐ
­sÚÐ-ÐÐ
­tÚÐ-ÐÐ
­“ÚÐ-ÐÐ
­uÚÐ-ÐÐ
­vÚÐ-ÐÐ
­xÚÐ-ÐÐ
­ÚÐ-ÐÐ
­‡ÚÐ-ÐÐ
­ˆÚÐ-ÐÐ
­†ÚÐ- ÐÐ
­‹ÚÐ-!ÐÐ
­ŒÚÐ-"ÐÐ
­ÚÐ-#ÐÐ
­ŽÚÐ-$ÐÐ
­ÚÐ-%ÐÐ
­ÚÐ-&ÐÐ
­‘ÚÐ-'ÐÐ
­’ÚÐ-(ÐÐ
­ÚÐ-)ÐÐ
­ŠÚÐ-*ÐÐ
­€ÚÐ-+ÐÐ
­‚ÚÐ-,ÐÐ
­ƒÚÐ--ÐÐ
­„ÚÐ-.ÐÐ
­yÚÐ-/ÐÐ
­zÚÐ-ÐÐ
­…ÚÐ-0ÐÐ
­¡ÚÐ-1ÐÐ
­šÚÐ-2ÐÐ
­žÚÐ-ÐÐ
­ŸÚÐ-3ÐÐ
­ ÚÐ-4ÐÐ
­iÚÐ-5ÐÐ
­jÚÐ-ÐÐ
­kÚÐ-6ÐÐ
­lÚÐ-ÐÐ
­ÀÚÐ-7ÐÐ
­ÁÚÐ-8ÐÐ
­nÚÐ-9ÐÐ
­ÄÚÐ-:ÐÐ
­ÅÚÐ-;ÐÐ
­pÚÐ-<ÐÐ
­qÚÐ-=ÐÐ
­rÚÐ->ÐÐ
­ÆÚÐ-?ÐÐ
­ÇÚÐ-@ÐÐ
­ÈÚÐ-AÐÐ
­½ÚÐ-BÐÐ
­VÚÐ-ÐÐ
­0ÚÐ-CÐÐ
­2ÚÐ-DÐÐ
­GÚÐ-EÐÐ
­5ÚÐ-FÐÐ
­6ÚÐ-GÐÐ
­<ÚÐ-HÐÐ
­@ÚÐ-IÐÐ
­WÚÐ-ÐÐ
­AÚÐ-JÐÐ
­`ÚÐ-KÐÐ
­BÚÐ-LÐÐ
­HÚÐ-EÐÐ
­CÚÐ-FÐÐ
­DÚÐ-MÐÐ
­EÚÐ-NÐÐ
­IÚÐ-IÐÐ
­¢ÚÐ-ÐÐ
­£ÚÐ-OÐÐ
­ÚÐ-ÐPQÐ	E
+ÐÐ
­ÚÐ-RÐÐ
­ZÚÐ-SÐÐ
­[ÚÐ-TÐÐ
­_ÚÐ-UÐÐ
­\ÚÐ-)ÐÐ
­SÚÐ-VÐÐ
­^ÚÐ-ÐÐ
­TÚÐ-WÐÐ
­XÚÐ-XÐÐ
­¤ÚÐ-)ÐÐ
­¥ÚÐ-YÐÐ
­ÚÐ-ZÐ[-\Ð]^-_`aÐbc­
\ No newline at end of file