Note: See the Adapter Script Overview-V2 for an overall look at the V2 adapter scripts.
In this article, we're going to be walking through creating a V2 adapter script for a brand new I/O machine that has been integrated using a T4 Labjack and has two sensors attached. One for execution connected to Pin-0 of the LabJack, and the other for part count connected to Pin-1.
Though the specifics might vary between data collection methods, such as MTConnect or Fanuc Focas, the structure of any V2 Script will be the same as this example.
Selecting the Data Collection Method
First, we'll navigate to the Machine Settings page for the desired machine, then select the Data Collection tab from the machine's settings window.
From the Drop-Down, we'll select Digital IO (T4-Module) since we're creating an Adapter Script for a T4 LabJack.
Next, enter the LabJack's IP in the field below. If you're unsure of what that is, see this article
Specify Version
The first line within your Adapter Script should be indicating which version of Adapter Script you're using. To use a V2 adapter script, enter the following.
version: 2
If there is no version set, version 1 will be assumed.
Data Transform
Next, we're going to want to tell our script where it should look for data.
On the line after the version, we'll enter "variables:" with no indentation. We can use variables to pass through and transform data.
version: 2
variables:
After that, we'll declare our first variable and call it "exec-in". This variable should be indented at least once. All the following variables should use the same indentation. The exact amount isn't important, simply that all like items within an adapter script section have a matching indentation.
version: 2
variables:
exec-in:
Now we'll enter where our "exec-in" variable gets its value from.
version: 2
variables:
exec-in:
- source: pin-0
- threshold: 2.5
source - determines which sensor our variable will use. In this case, our sensor that is monitoring execution is plugged into pin-0 on our LabJack, so we enter "pin-0" as the source.
threshold - takes the values coming from the source and checks if they are above a given value, or in this case, 2.5. If the value coming off pin-0 is less than 2.5, exec-in will be false. If it is above 2.5, exec-in will be "true".
Now that our execution variable is set, we can move on to adding our part counting variable. It will follow exactly the same formula as our exec-in variable but with a few additional parameters.
version: 2
variables:
exec-in:
- source: pin-0
- threshold: 2.5
parts-in:
- source: pin-1
- threshold: 2.5
- rising-edge
- count
Our parts-in variable has two new parameters, "rising-edge" and "count". To learn more about them, see our variable documentation here.
The result will be that our parts-in variable will store a number that increases by 1 whenever the sensor attached to pin-1 reports a value above 2.5.
Important: Don't forget your indentation! Consistent indentation is crucial for YAML, the format Adapter Scripts are required to be written in.
Data Items
We now have two variables configured and ready to go! exec-in should report "true" or "false" to indicate whether it is in or out of execution, and parts-in should keep a running total of the number of parts this machine has produced. All that is left to do is to tell our Adapter Script to report this to the MachineMetrics cloud. You can think of the Data Items section like an export, it is what determines the output of the Script.
Below your last variable parameter enter data-items: on a new line with no indentation.
version: 2
variables:
exec-in:
- source: pin-0
- threshold: 2.5
parts-in:
- source: pin-1
- threshold: 2.5
- rising-edge
- count
data-items:
Each data-item is reported in the following format
data-items:
<name of tag>:
value: <value of tag>
The <name of tag> can be any string of characters that does not match a variable name, though we recommend using clear and consistent language as our system will recognize common tags such as "execution".
The <value of tag> can be somewhat more complicated. It can be a variable or a hardcoded set value. See our completed example below.
data-items:
execution:
value:
ACTIVE: exec-in
READY: true
part_count:
value: parts-in
the part_count data item is fairly simple. The tag name is part_count and its value is set to the value of the parts-in variable. This means the part_count tag will report the total parts counted.
execution is somewhat more complicated. Execution as it is defined by MTConnect can't simply be true or false. It has a list of possible states, such as "ACTIVE" or "READY". So rather than does what we did for part_count, we need to configure the execution tag to report terms that apply to execution.
We can accomplish this by creating a list of possible values to report. The Adapter script will check each one from top to bottom until one returns "true".
The flow would be as follows
- Pin-0 reports 1.7
- 1.7 is below exec-in's threshold of 2.5, so the variable exec-in reports "false".
- The Data Item execution reports its value
- exec-in is false, so it does not report "ACTIVE"
- "READY" as been set to "true" so execution will have the value of "READY"
Whenever one of pin-0 or pin-1's values changes, the Adapter Script will re-check all Data Item values.
That's the Adapter Script finished! Click the Save Data Collection Method button at the bottom right of your screen to save your Adapter Script.
The final step to ensure your machine will report correctly is mapping those data items you just created. Follow the instructions on this article to do so!
Have Questions?
Reach out to support@machinemetrics.com for additional help.
Comments
0 comments
Please sign in to leave a comment.