All Projects → fbarresi → TwinCAT.JsonExtension

fbarresi / TwinCAT.JsonExtension

Licence: MIT license
TwinCAT variables to and from json

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to TwinCAT.JsonExtension

TwinRx
.NET library for connecting with Beckhoff TwinCAT PLC via Reactive Extensions (Rx)
Stars: ✭ 16 (-58.97%)
Mutual labels:  twincat, beckhoff, twincat-ads
tame4
JS library for the access to a TwinCAT PLC. Current version V4.3.1 final.
Stars: ✭ 37 (-5.13%)
Mutual labels:  twincat, beckhoff, twincat-ads
Examples-Inxton.Package.Vortex.Core
Repository contains introductory examples to Inxton.Package.Vortex.Core
Stars: ✭ 32 (-17.95%)
Mutual labels:  twincat, beckhoff, twincat-ads
ads-client
Unofficial Node.js ADS library for connecting to Beckhoff TwinCAT automation systems using ADS protocol.
Stars: ✭ 44 (+12.82%)
Mutual labels:  twincat, beckhoff, twincat-ads
TcOpen
Application framework for industrial automation built on top of TwinCAT3 and .NET.
Stars: ✭ 187 (+379.49%)
Mutual labels:  twincat, beckhoff, twincat-ads
TcUnit-Runner
Program that makes it possible to automate runs of TcUnit unit tests
Stars: ✭ 23 (-41.03%)
Mutual labels:  twincat, beckhoff
SoftBeckhoff
Virtual Beckhoff PLC for local testing with docker support
Stars: ✭ 40 (+2.56%)
Mutual labels:  twincat, beckhoff
ioBroker.beckhoff
ioBroker Adapter to Communicate with Beckhoff Automation System over ADS
Stars: ✭ 14 (-64.1%)
Mutual labels:  twincat, beckhoff
node-ads
NodeJS Twincat ADS protocol implementation
Stars: ✭ 49 (+25.64%)
Mutual labels:  twincat, beckhoff
TcBlack
Opnionated code formatter for TwinCAT.
Stars: ✭ 67 (+71.79%)
Mutual labels:  twincat, beckhoff

TwinCAT.JsonExtension

TwinCAT variables to and from json

Build status Codacy Badge codecov Licence Nuget Version

Bring the power of Json.Net to TwinCAT

Tranform DUTs decorated with the custom Json-Attribute like this:

TYPE JsonDUT :
STRUCT
	{attribute 'json' := 'message'}
	sMessage : STRING := 'test';
	iResponse : INT;
	{attribute 'json' := 'status'}
	sStatus : STRING := 'success';
	{attribute 'json' := 'numbers'}
	daNumbers : ARRAY[1..3] OF DINT := [1,2,3];
END_STRUCT
END_TYPE

into this (and back) recursively and absolutely type-independent:

{
  "message": "test",
  "status" : "success",
  "numbers" : [1,2,3]
}

only calling this two extension methods on your connected AdsClient:

var json = await client.ReadJson("GVL.JsonDutVariable")
await client.WriteJson("GVL.JsonDutVariable", json);

Options

Progress indication

For lengthy operations, a progress indiciator can be used to give some feedback about the current progress. By passing a Progress<int> object as parameter to ReadJson or WriteJson it is possible to count the total number of primitive types (INT, DINT, REAL, ...) that were read or written to the PLC, respectively.

int objects = 0;
var progress = new Progress<int>();
progress.ProgressChanged += (sender, args) => { objects++; Console.CursorLeft = 0; Console.Write(objects); };

Console.WriteLine("Primitives read from PLC");
await client.ReadJson("GVL.JsonDutVariable", progress: progress);

Console.WriteLine("\nPrimitives written to  PLC");
await client.WriteJson("GVL.JsonDutVariable", json, progress: progress);

Enumeration stringify

Values of enumerations are by default started as integer values. However, sometimes it is beneficial to store said values as strings. This can be achieved by the stringify parameter.

await client.ReadJson("GVL.JsonDutVariable", force: true, stringifyEnums: true);

Read/Write without json attribute

The attributes mentioned above are optional when using this library. The following example achieves a similar result. The only difference is the instance names in the generated json file.

TYPE JsonDUT :
STRUCT
	sMessage : STRING := 'test';
	iResponse : INT;
	sStatus : STRING := 'success';
	daNumbers : ARRAY[1..3] OF DINT := [1,2,3];
END_STRUCT
END_TYPE

yields

{
  "sMessage": "test",
  "iResponse" : 0,
  "sStatus": "success",
  "daNumbers" : [1,2,3]
}

by calling the ReadJsonAsync method on your connected AdsClient

var json = await client.ReadJson("GVL.JsonDutVariable", force: true);

Have fun using this simple package and don't forget to star this project!

Referenced projects

Would you like to see the power of TwinCAT.JsonExtension in action?

Then checkout BeckhoffHttpClient, an unofficial TwinCAT function for HTTP requests

or

TwincatAdsTool your swiss knife for twincat development.

Credits

Special thanks to JetBrains for supporting this open source project.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].