I hope you all are enjoying a break this time of year. I have the following challenge for your consideration when you get back in the office. Sorry for the length so the TL;DR version is I am looking for auto serialized output of user data types to JSON into a given memory block of strings.
Background...I am using the BRX PLC as a generalized platform for automated test equipment to make it easier for our young Test Engineering team to turn out functional testers with repeatable results. The base programs and tasks control the general flow for things like validating operators, work orders, products etc. HMI functionality is provided via a modified version of plcnut's web server. The primary page displays the devices under test (DUTs) and is updated periodically with AJAX requests to the PLC. These base programs, tasks and supporting data structures will be considered sacred and protected from being modified by the Test Engineers. They will be able to add in additional data structures, programs, etc to round out their testers but the core should remain untouched to ensure a base level of consistency.
So far all is going extremely well, at least through simulation. This is my first big project with PLCs so there is still a lot of learning along the way. Luckily Host Engineering has built an amazing community so that process has been pretty painless.
My next hurdle that has me spinning a bit is if it will be possible to generalize the DUT reporting back to the HMI and/or final log collection server. Lets assume the Engineer has defined the following fields in the DutResult user data type.
DutResult
DutID unsigned byte
T1_Start dword
T1_End dword
T1_Expected real
T1_Actual real
T2_Start dword
T2_End dword
T2_Expected real
T2_Actual real
I'd like to be able to generate a JSON record of a given DutResults memory block location (ex. DutResults0-9) without explicitly building the string(s). Below is an example of the conversion.
{
"DutId": 0,
"T1_Start": 234123432,
"T1_End": 234123450,
"T1_Expected": 5.00,
"T1_Actual": 5.01,
"T2_Start": 234123451,
"T2_End": 234123455,
"T2_Expected": 1.500,
"T2_Actual": 1.495
}
I am looking for something similar to using Newtonsoft.Json.JsonConvert.SerializeObject(someObject) in C#. By dynamically generating this I could avoid the need to teach our Test Engineers the finer points of JSON and also wouldn't have to worry about missing a field in the output. We could just focus on building testers.
Fundamentally, I think everything exists on the PLC in terms of the documentation, nicknames, etc. What I am not sure of is the ability to query and iterate through the fields of a structure, get the names of the fields and then get the associated values. I think this could be useful for handling web based requests for data and for logging data to external endpoints without the need for any middle-ware. I'd like to hear the thoughts of the team and community on this to see if there is any merit or if you have some better thoughts. Thanks in advance and keep up the great work!