Home / Micro800 / Micro800 Simulator
Description
The Micro800 Simulator that comes with Connected Components Workbench (CCW) provides the capability to use a REST API to simulate external I/O
This video shows how to set up the external I/O access in the Micro800 simulator and test the REST API using Postman.
Then we demonstrate using the REST API Client in FactoryTalk Optix to interface directly with the Micro800 simulator.
Details
The Micro800 simulator that is built-in to the Connected Components Workbench (CCW) software has the ability to connect to “external I/O” using either the REST API, or an XML file.
Of course the Micro800 simulator cannot connect to physical external I/O, but these options allow users to control the I/O status without directly interactioning with Micro800 Simulator.
With the API method, you can send read or write requests to the web service endpoint URL and receive responses from it using either the GET or POST commands.
To use the I/O interface with API
- Open the Micro800 simulator in CCW.
- In the Tools menu, select Options > Enable external I/O access > API.
- Power on Micro800 Simulator.
- Take note of the API Comm Port that is assigned.
The URL of the API will be http://localhost.portnumber/inputs
Note that you will substitute the portnumber in the URL path with the API Comm Port shown in the running Micro800 simulator.
To view simulator input values from REST API Client:
| GET | http://localhost:port number/inputs |
|---|---|
| Sample Response | [{"Name":"_IO_EM_DI_00","Value":"false"},{"Name":"_IO_EM_DI_01","Value":"false"},……{"Name":"_IO_EM_DI_27","Value":"false"},{"Name":"_IO_P2_AI_00","Value":"0"}……{"Name":"_IO_P2_AI_03","Value":"0"}] |
To view simulator output values from REST API Client:
| GET | http://localhost:port number/outputs |
|---|---|
| Sample Response | [{"Name":"_IO_EM_DO_00","Value":"false"},{"Name":"_IO_EM_DO_01","Value":"false"},……{"Name":"_IO_EM_DO_18","Value":"false"},{"Name":"_IO_P3_AO_01","Value":"0"},{"Name":"_IO_P3_AO_02","Value":"0"},] |
To change input values from the REST API Client:
| POST | http://localhost:port number/inputs |
|---|---|
| Body | [{"Name":"_IO_EM_DO_00","Value":"True"},{"Name":"_IO_P2_AO_03","Value":"10"}] |
Transcript
(00:02) in this video I want to show some of the uh additional capabilities of the micro 800 simulator in my last video I just showed the basics how the how the micro800 simulator works and how we could use the um the virtual wire to connect an output back into an input to drive you know our simulation but there is uh two two capabilities that the simulator can do to kind of quote unquote connect to external IO of course we really can’t connect to real remote IO devices but what we can do is we can uh either use the built-in rest API or of the
(00:41) simulator or there’s an XML capability so this video I’m going to first show The API and I’m going to link it to U Vector talk Optics because Vector talk Optics also has the ability to uh to be a rest API client so I got the simulator already up it’s not running right now um it doesn’t even matter what I have if I have any kind of program in the simulator or not um I do have a program running in there but but it’s not using any of the embedded IO so the first thing we need to do is we need to make sure that we’ve enabled the um remote IO
(01:22) as they call it so we have to go to tools and this is all has to be done before I start the simulator so I go to tools I’m going I go to options and I’m going to choose to enable the external IO access and I’m going to make sure that I’m choosing API so I have the two options here can’t do both at the same time so we’re going to enable the API for this for this time and I’m going to say okay now um I want to say before I start the thing uh if we go to help and go to about micro800 simulator you will open up a help file
(02:00) and there is a you know there is a little bit of content here to help guide you with this um not a lot but there’s a little bit so underneath the micro 800 simulator and then configure the io wiring which is also right over here uh we see that they talk about the API and the XML so for the API it talks about the steps here that I just did and there are basically three um I guess commands uh that we could use we can use to get um well basically we can we can get the inputs we can get the outputs and we can post to either the inputs or the
(02:44) outputs so uh we we’ll get to this point here in just a second to show you kind of what what this um HTTP string is in a moment um so back on the simulator I’m going to go ahead and start it so the first thing we need to know is we need to make note of this API comp Port so in this case for me uh in this instance it is 52 611 now every time we create this um it’s going to create a new API comp Port so um I don’t know if there’s a way to to continue to use the same comport over and over again um but if you’re trying to to do something um
(03:31) you know then know that this comport might change each time so I’m going to go ahead and uh leave this up it’s running and we’ve got our API comport assigned so first thing do is we’ll we’ll just come to um we’ll go to postmen First and this is Postman is just a um you know a web tool that uh I can use to just test the API you know capabilities the get and the um as well as the uh post so going back to my my help file we see here that uh the the command is for a git to get the uh the value of the inputs I I basically
(04:14) type in you know I’ll use a git command and then I’ll I’ll just this is the API uh string I’m going to use Local Host and this will be the response we get back basically uh each input and its value if it’s on or off off I’m going to go ahead and copy and paste this just so I don’t have to uh type it in and I’ll paste it into my uh into my Postman um command line here and I need to make sure to put in the value for the port number which is 5 2611 so if I go ahead and hit send I get my string down here here you
(05:00) know down here in the uh in the in the U I guess the the Json window I see that I get my name IO EMD i00 is false false false right so I’m actually reading from my my emulator now if I go ahead and uh turn on a couple of these inputs and if I go ahead and run this uh send command one more time we’ll see now that it says true true right so the first three is true true and true so I’m definitely able to read my values turn those off now let’s say I want to actually write to the values here so I’m going to go ahead and uh I’m
(05:54) going to go ahead and try to do this here and minim minimize this window a little bit so we can see this at the same time um so what I need to do is I need to um basically I’m now going to do a post and I’m going to post to the inputs now actually before I do that I should say if I come back here and change this to outputs and run this command one more time you’ll see that my IO EMD o00 is a false false false so it’s reading the outputs so they’re kind of grouped as either all the inputs or all the outputs I’m going go a and put the inputs back
(06:42) on the line here now going back to um going back to the help file if I want to do a post well here’s the body that I need to basically send uh this is a Json uh script so to speak or string that I have to be able to send so the format is I’m going to have to do an open bracket and then an open uh curly brace and then I need to put the syntax here name in print in uh in quotations colon and then the the the uh the embedded IO point and then the value and then true or false now if I was going to write to the um to a plug-in module then I can
(07:29) write an actual numerical value to the to this like an analog output but in this case I only have the discret uh input and outputs being used in my in my simulat to moment so this is the string I want I’m going to go ahead and copy this so I don’t have to necessarily retype it um now to do this I’m going to go to I’m going to first change this to a post and I’m going to go here to the body I’m going to choose raw and you notice how it is a Json and I’m going to just basically paste so I don’t have this analog plugin
(08:12) so I’m going to get rid of that line and I need to make sure that I update this to the d00 so I want to turn on my very first input and the value is going to be true so again if I can try to get this all together on one screen for you we can see that right now 0 is off so if I come back here and if I run my command there it went it just turned on so now I come back to um to my body and if I type in false and say send it turned off so I can control the simulator just through this API post um instruction and I could basically you
(09:07) know send a you know multiple string if I want to do another line then I could of course copy paste this missed the brace there but I’ll make sure to put it and then let’s change this to di maybe 02 and let’s go ahead and turn them both on this time so uh make them both true all right so now if I uh put that back up in the corner there and if I um send my send command both 0 0 and 02 turned on if I go ahead and change them to false they will both turn off all right so able to prove that we can do this now let’s go to um
(10:10) Optics and see how we can do this in Optics as well so I’ve um I’ve got an Optics application built and I went ahead and and put some comments here so I wouldn’t forget some of the the um proper syntax or we can show you you know on the screen um so I’m going to go ahead and uh change my uh I’m going to go ahead and change this to to put my port number that I have for this instance and that’s 5 2611 right so we don’t forget that I’ve got a push button at it a simple push button but right now there’s nothing configured for the push button so the
(10:54) first thing we have to do in optics for me to do an API client so I can actually use Optics to now communicate to the uh to the simulator uh I I need to create a um a rest API client and I need to put it under my my net logic now um I already had one here I’m going to go ahead and delete this so I want to show you how I do it from scratch um we’re going to go up here to the library so that the the uh rest API client is in the template Library and uh it opens up on the other screen so all I need to do is I’m going to type
(11:33) in rest and uh of course finished typ it in the API but it found it there so here’s rest the rest API client I’m going to take the rest API client component and drag it to my net Logics net logic and then say close now that’s really all I got to do I don’t have to set up anything else on this rest API client um there is a couple there’s there really two things here uh one is the timeout duration and one is the um the user agent basically how the rest API client identifies itself and right now the theault is Ft Optics and no no need for
(12:13) us to change that so when I want to call the rest API client and send this post command to the um to the emulator I’m going to do that with a push button so I’ve added a push button uh just happens to be momentary it doesn’t really matter what type it is uh and then when I I need to do an event right so um I’m going to create a mouse click event so I’m going to use the plus symbol to add a new method and I’m going to go to net logic and here’s my rest API client and in Optics I’ve only got three U methods to get the poster the
(12:53) put now the put is not a command that is allowed or a method that is allowed from the micro800 simulator so only get and post workor in this case I want to actually write you know I want to write a value to the emulator to turn it on or off so I’m going to use the post command and say select now when I get the post command I’ve get a few things underneath these input arguments one is the API URL which is basically going to be this string right here uh and the other one is the request body and that’s basically
(13:29) basically the the um the syntax that we we kind of used there when we tested in in in the postman app I got to put that here as well and then there are a few other ones the bearer token and content type and we can leave those two blank at least for uh for this application so for the a API URL um I can basically come here and copy this and then then bring it back to my uh API URL and paste it and for my um uh for my uh body I can um copy what I’ve already created here as well so I’m to type this out just highlight
(14:21) this copy it click back on the push button and put this into the request body now the only thing I need to do too is I want to change this from false to true and make sure we didn’t lose any of our proper syntax and hit enter and that’s it now um since so I’ve got one push button here to turn it on uh just for for uh making this an easy demonstration I’m going to copy this and paste it I’m going to go ahead and create uh a second push button and I’m going to re label this to um to say off basically and actually I should have
(15:13) should have called that di right not D um come back and fix this on the other button not that really matters but uh I uh type that wrong so I’m come back to my off button and basic basically the same method will get invoked we’re going to send a post uh API post and we’re going to use that same API client that we’ve already added there uh under net logic and all I need to do is I need to change the body from True to false this time so essentially when I push the on button I will send a true and when I send push the off button it’ll send a
(15:57) false pretty pretty straightforward so pretty much that’s it I’m going to go ahead and fire up the emulator this will open up momentarily and open up the other window of course and we bring up the the micro 800 uh simulator on off screen as well so now when I press the DI on button it sends the um post command to you know over the API to the simulator and turns it on and if I hit the off button it sends the the post to turn it off so pretty interesting pretty powerful we can create or use the API so we could build
(16:44) our own custom interfaces to the simulator um so you know again for for training or for testing purposes um you know we could do a little bit more you know some more interesting things with the a Pi um the other method is the XML which is basically like an XML uh spreadsheet uh where you can we can kind of use a spreadsheet to send XML and manipulate the variables that way I will uh we’ll we’ll demonstrate that in a separate video
