You can help by commenting or suggesting your edit directly into the transcript. We'll review any changes before posting them. All comments are completely anonymous. For any comments that need a reply, consider emailing docs@inductiveautomation.com.
Version:
LESSON LIST
-
4:33Connecting to the Device Simulator
-
7:24Custom Programs
-
2:35Control Tags
LESSON
Custom Programs
Description
Learn how to make your own custom program for the device simulator. Lesson includes discussion on time intervals, static values, repeating programs, and functions as value sources.
Video recorded using: Ignition 8.0
Transcript
(open in window)[00:00] In this lesson, we'll be taking a look at how you can create your own programs using the Programmable Device Simulator. You can configure your own OPC items to be populated using functions or static values, as well as specify how the value should be updated over time. So to get started, let's go ahead and find our simulator connection. So I'm in the config section of my gateway web page, and I'm going to scroll down until I find OPC UA device connections. Now, I already have a simulator connection configured, so I'm just going to go to more and then edit program. In the context of our Programmable Device Simulator, a program is just a set of instructions to run, where each instruction reads some value or function output and pushes that value onto an OPC item. So to see this in action, let's go ahead and add an instruction. So once I click that add instruction link, a row appears in our table here with a few different options we have to specify. So the first is a time interval associated with this instruction. Effectively, whenever our program executes, that program will start at time zero and increment once for each time unit that passes. By default, that time unit is one second, although we can change it in the device connection properties. So in this case, if I set up an instruction to run at time interval five, that instruction will occur five seconds into the execution of my program. Whereas setting the time interval to zero here is effectively controlling the starting value of this item. So next, I have to type in a path to the item. So for example, 'Test/MyTag', what that's going to do is define a folder called 'Test' and an item inside of it called 'MyTag'. So once we actually spin up this program, that item will be defined. So next we have this value source field here. And what this controls is effectively what value we should assign to our path at the specified time interval. So how about I make it easy and set that to zero. So now we'll pass over a value of zero at that zero time interval. And then finally we have our data type for the value, so I can make it a double or a Boolean, or an integer, and so on. I'll just leave it at double for now. So now I have an instruction complete for time interval zero. Now I'm going to go ahead and add an instruction for time interval one. So I'll set the time interval to one, I'll set the browse path to my tag again, I'll set the value source to one and I'll leave the data type as double. So now after one second has passed the 'Test/MyTag' item should take on a value of one. And with that, I'll go ahead and save my program. Now we're ready to see our program in action. So what I'm going to do is scroll down and find OPC Quick Client under OPC Client. I already have this open in the second tab. So from in here, we can test out subscriptions without having to create real tags on our gateway. So I'll find ignition OPC UA server and expand devices, and then expand test, which is our simulated device, and then expand the test again, which is the name of the folder we created. And there finally we can see our my tag item. So I'll go ahead and click the 's' to subscribe to that item. And now we can see our subscription underneath. And we can see the value on that tag fluctuate between zero and one. So it makes good sense that the value should go from zero to one because that's exactly how we programmed the simulator. But the reason that the value goes back to zero is because the program is actually restarting, it's being run on a loop. This again is a configurable option that we can find in our simulator settings. So for that, I'll come back to my first tab, scroll up, come back into my simulator and then hit edit instead of more and this will give me the two basic settings for this simulator. One, repeat program is the setting telling it to repeat indefinitely, meaning once the program is finished and there are no more time intervals to execute, go ahead and restart the program. The other property here specifies the program base rate, which indicates how long each time interval in our program should be. So I'll leave this alone for now but I will go back into our program and configure some more advanced settings. So I said at the very beginning, the value source here does not have to be a static value. In fact, it could be the output of a function. So for this example, I'm going to add another instruction to my program. So this time my browse path is going to be 'Test/MySineTag'. So this is going to be another item inside of our simulator, but this time its value source is going to be sine, open parenthesis, negative 10 comma 10 comma 60, comma true and then a closed parenthesis. So to quickly breakdown what this function is doing, it is going to give me values for a sine wave fluctuating between negative 10 and 10 with a period of 60 seconds because of that 60 parameter. Meaning that if the value is negative 10 now it will be 60 time intervals before the value is negative 10 again. And that brings me to the final parameter here, this true parameter. This is the repeat parameter for this function. And what that means is, if I set this to true, every second will push a new value from this waveform onto the item. This effectively just saves us the trouble of configuring 60 instructions in this table just for this single item. Another important note here, if I had set that parameter to false and otherwise left the program alone, you would actually see some interesting behavior. Specifically, you would find that 'MySineTag' updates every two seconds instead of every second but otherwise sticks to the exact same behavior. This is because setting this parameter to false will still allow the value to update anytime the program's time interval is zero. And currently the program is repeating every two seconds, so every other second has a time interval of zero. This is an important thing to keep in mind because it might be tempting to think that this sine function will be restarted every time the program restarts. However, this is not the case. This sine function is taking the simulators clock as an input, not the program's time interval. Now this is generally very handy because I've actually done all that I need to get this sine tag working as it is, once I hit 'Save Program' and I go back into my OPC Quick Client, and I refresh, expand devices test, test, and then I subscribe to 'MySineTag', we'll see our assigned value updating seamlessly, and it'll keep doing so forever, even with the program resetting every two seconds. Worth noting that there are many other functions you can use. You can create square waves, triangle waves, random values, ramp values and so on. And a full list of our simulator functions are available in the user manual, along with documentation for each of the parameters. So, that's all it takes to get a simple program up and running. Now I'm ready to take my program and turn it into ignition tags and use those tags throughout my project.