https://www.automationdirect.com/brx
(VID-BRX-0031)
This video is part 2 of a 3 part series that details the needed information to setup and use JSON in the do-more BRX PLC.
This video details how to use the JSON Build in the Do-more BRX PLC.
Our FREE Practical Guide to Programmable Logic Controllers eBook: https://www.automationdirect.com/ebooks/plc-handbook
this is a how-to video on using do-more designers brix plc's json build instruction it assumes you already are familiar with the json data format or you have watched our training video on the json data format the json build instruction does one of two things it builds a single object with one or more name value pairs or it builds a single array containing multiple values to build an object it assigns a value to a name creating that name value pair but it also allows you to add multiple rows of name value pairs up to 50. if we double click on a row or we use the add or insert buttons we can pull up a dialog to add the name value pair we'll talk about that insert structure fields button in a moment but first the dialog the first thing of course is that you must give your name value pair a name this can be a static string contained in quotes or a variable string like an ss sl or a user created string element then you must assign this name a value in keeping with json value types the value can be a numeric a boolean a string another object or an array yes these are only five of the six value types available in json the sixth being null but if you'll notice the little comment in the dialog that says a string element like ss0 or string literal like null this will give you a clue that if you want to use null value type then you will have to manually type it in double quotes right here in this box and make sure the enclosed in quotes is not checked if this is hard to remember then you can always look down at the bottom of the dialog in the example box to see exactly what you're creating remember that the null value type should not be contained in quotes the buttons at the bottom should be self-explanatory now let's talk about this insert structure field button it's another way to add several name value pairs at one time pressing this button pulls up this dialog by default the system structure dollar sign now or sdt 0 is put there but any structure can be used but just as a demonstration if i use the default this will be the result notice that each useful structure member of 0 is made into a name value pair so every how you populate the rows or whether you only populate one row the json build instruction will add the necessary formatting of curly braces and commas as needed the second function json build allows is the building of an array of values the difference here is that you cannot build multiple arrays as it at first may seem since there's multiple rows allowed instead the multiple rows are provided in case you have non-contiguous values to add to a single array for example you may want to add d10 d50 and then the range of d100 and 105. if so you'd have three lines that look like this one line for d10 one for d50 and one for the range of d100 to 105. when you add a row this dialog comes up notice the name parameter is missing that's because you're not making name value pairs but merely an array of values so you must choose the value type as a numeric boolean string object or array just as before but there is an additional box added called range of array elements so this is where you can define contiguous ranges of elements to include in your array the json build instruction will add the necessary square brackets and commas for proper formatting as a note the insert structure fields button even though it is not grayed out it doesn't make any sense to use here the reason being that it creates name value pairs not merely values at the bottom of the json build is the json output record box regardless of whether you use the instruction to create an object or an array you will here have to tell it where to place that newly created record you have the choice of putting it in the standard elements of ss sl or your user created string or it can be stored in a numeric data block containing text we'll see how that will be important later on so how do we go about building a json record well let's look at a simple example with a lot of data let's say we have an automation plant that has a particular building in this building there is an oven that has three heating zones in it each heating zone has three temperature zones of measurement let's say also that each zone measures the air pressure as well further let's say it measures the humidity now it's quite a bit of information but let's make it even more interesting instead of just one oven like this let's say there are three and further let's say there's an entire other building in this plant with an identical configuration this indeed is a lot of information but even so we want to make this information available so that these processes could be monitored remotely this example is a good candidate for using json data format simply because of its hierarchical arrangement this should be very straightforward in our minds we are already thinking of this data in a hierarchy in our example there is a building an oven in a zone and this oven zone has three temperature measurements these three measurements could be put in an array that we'll just simply call temp why an array well it doesn't have to be an array we could just create temp 1 temp 2 and temp 3 but i chose an array just because it makes sense and also to demonstrate the json builds array function at the same level we add the pressure value and the humidity of course these 5 values would then belong under zone one and this zone would belong under oven one and this oven would belong under building one see that's not hard and then of course zone two is added at the same level as zone one and then zone three so that we have three zones under the same oven this same process would be repeated for oven two and oven three so the hierarchy is clear measurements of a zone in an oven in a building finally we add the second building under building two as essentially a copy paste version of building one but how do we use the json build instruction to do this well now that we've arranged our data in a hierarchy we must use the json build instructions in such a way as to build the data up from the lowest level that's easy to see in our hierarchy because it is the data that is indented the most so starting at that lowest level we would use multiple json build instructions to build temp array for each zone so let's look at one oven we build this array of values let's say in zone 1 the three temperature values come from r100 to r102 when the json build is executed it will go and grab the current values stored there the json build will then add the proper formatting required commas and square brackets we also tell the json build to store this formatted string in ss0 for example subsequently we do the same for the other temperature arrays storing them in ss1 and ss2 now we move up a level here we see that humidity pressure and temperature or temp are all at the same level the array we just created must become the value portion of a name value pair along with humidity and pressure which each have a single value since the string is probably getting much larger than an ss can contain we'll store these in sls like so moving up another level shown in blue we can now assign sl0 the name zone 1 and s01 zone 2 etc we'll store those in sl3 remember we have two more ovens with this same arrangement moving up another level shown in red we can now put this arrangement into oven one and don't forget oven 2 and oven 3 even though they're not shown here since this structure is becoming very large very quick it would not be possible to store it even in an sl which is only 256 characters long so in anticipation of large strings i create a block of strings where each string in that block is 1024 characters long i called it json data i would store each oven in subsequent json data locations json data 0 1 and 2 and so forth but we still have yet another level which is going to be even larger we now move up to the building level shown in purple and there are two buildings and by this time i was sure that the record of data we are creating would be even longer than 1024 characters so what do we do now remember that json output record box this is why that second option is available called numeric data block containing text so in the system configuration or right here in the instruction itself using the create byte buffer button i create a memory block made of 2048 elements each element in this block is merely one byte long this allows me to store a single string of text that is up to 2048 characters or bytes long i called this one json buff thus json buff 0 would contain the first byte json buff 1 would contain the second byte and so on and so forth this is where i will store the final huge record now let's just go to the ladder logic and do it okay so here you can see i have a program already written called json build and i'm going to execute that by turning on c0 so we've got that guy running now and here you can see you want to start with c2 this rung here i'm going to put some values in our 100 through 114 to simulate the the temperature values and the pressure in the humidity so if i execute that you can see that this got filled up with some values and then the next thing we're going to start building our json data so here in this one if you remember we're going to build the array first so if i open this guy up you can see an array and we'll double click here you can see i give it um the value r 100 is the numeric this is the first value in the range and there's going to be three values r 100 through r 102 and this down here shows you an example of what it's going to look like once we get that those values then it's going to format them and then stuff them into ss0 then the second one here is going to go up a level and it's going to take that array that we just made in ss0 and assign it the name temp and we're going to get r103 and assign it the name pressure and r104 and assign it name humidity so here you can see uh for example the humidity there's the name humidity telling you where to get it from an example of what it's going to look like and also this one is going to give it it's going to go get ss0 whatever is in there which is what we just built as an array and assign it the name temp so since there are three zones then we're going to have three rungs just like this so so if i turn on c3 you can see the data uh in ss0 is that array and then sl0 which is this one over here it's going to have the humidity value the pressure value but you can't really see it that well but there's this great tool in do-more designer you go here to this little wrench and pick json pretty and see there we can see it very easily since i was on this instruction the json pretty automatically picks this output record string and stuffs it right there shows you the raw string and then you can see here now that the braces now contain the humidity pressure and temp with the associated values and also this array that's delineated by these square brackets so we can close that out i'm going to do the same thing with this run turning on c4 and go over here again pick the json pretty and there you can see it is also the same with its values close that one out and we'll do for the third zone so now you can go over here and see scroll this guy up and pick this tool and look at sl2 and see that it got built properly too you know you could also look at the uh this one here it doesn't matter which one it's got this tool here you pick this as a tune so you can just see the array the array by itself is there now next what we're going to do well now we're going to go and assign each of these zones that we uh just created we're going to assign them the name zone 1 zone 2 0 3. so if i go here to this guy you can see that the field name is zone one and get that data from sl0 so it's going to say zone one is the contents of sl0 which we just built i'm going to do the same for zone one zone two is on three that's going to build those up and store them in sl3 so when we execute that with c6 it's going to get stuffed into sl3 as we told it to right there over here and pull up the json pretty for that one and there you can see how we're building this up slowly there's zone one with all of its values on two and zone three and if i stretch that out i can see that the whole thing is ready now that i have this object well that's going to go up another level and the next level it's going to be assigned to an oven right so remember we had three ovens and each oven has three zones now i'm just going to pretend that we've already done this zone generation right here the same build for the other two ovens and so you can see here i'm going to assign oven one with what's in sl3 which we just built but also going to just duplicate it just for the sake of making this shorter then we're going to say the same data we'll call 11 2 and the same day we'll call open three when actually i would be getting these from different locations but that's what we're going to do with this one with the c7 and go up to this oven and remember this one if you'll notice this one's going to build these up and stuff it into this json data 0 string which if you'll remember it was a string that is 1024 characters long so once we do that then you can see it was actually 640 characters long so that would never have fit into an sl which is only 256 so it's a good thing we did that but you can also go and see that it doesn't really matter with this tool it knows what to do so when i pick it it goes and picks json data 0 shows me the raw data and again arranges it in this nice pretty format now you can see it's pretty big now we've got oven one with three zone open two with three zones and open three with three zones so now we're going to go up to the building level so we'll close that guy out and here remember this one's already 640 characters long so we're going to have another one that's another building it's going to be about that long and then we're going to stuff that into something and if you remember we talked about that again i'm going to say that we've already done this for building two we're just going to use the same data for the sake of making this shorter but here you can see i picked that numeric data block containing text and uh json buff is the name of that byte buffer that i created and i made it 2048 long but this instruction also says uh tell me the length and stuff that value into d0 so that's all we're going to do this will be our final one so when i turn on c8 you can see it's 1307 characters long so now again this nice little tool i don't have to do anything i just go print select this and you can see here instead of using string structure it selected the numeric data containing text it automatically selected that selected the json buff and it knows what number of bytes to display as d0 because d0 is going to change you know it's 1307 but the next time i run this it might be you know 1400 characters long or something but again now you can see our final structure has been completely built in the hierarchy we wanted here is uh the object itself there's building one with three ovens three zones each and scrolling down here there's building two with oven one two and three with their each three zones so you can see this is a massive json data record that we just built up uh just by observing hierarchy so that concludes how to use the json build instruction to build a json data record now the next video will tell you how to use the json parse instruction and how to actually extract data from such a structure as this thanks for watching you
Voted #1 mid-sized employer in Atlanta
Check out our
job openings