Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Exercise: Checking Data Logging with Object

  1. Create a Data Logger Model. Go to Tools > Data Log Editor. Click the + in order create the new Data Logger Model. Once created, name it “Counter”. Set the Logging Options to Periodic and 5 Seconds. Click OK to confirm the changes and exit the screen.

  1. Go to Insert > Data Log Table. Click and Drag the Data Log table. Once the table is created, select it, and under Data Logger Model select the Counter that was created. This will link it to the Data Logger table.

  1. Create a new Tag named “Count”. Do this by going under Tag Editor and pressing the Add Tag button. Set the Data Type to INT (INT16). Click OK to confirm the changes and create the new tag. Then Create a Bool Tag called “On”. Set the intitial value to 0.

Image Added

Image Added

  1. Create a lamp on the page. To create a Switch/Lamp object, go to Insert > Switch/Lamp or left-click the Insert Switch/Lamp icon in the Toolbar. Then, click and drag on the screen to place the lamp. Once the Switch/Lamp object is created, drag the ON tag to the Lamp. This will bind the Value field to the Tag ON.

Image Added

  1. Click on Tools > Script Editor. Click the + icon to create a new script; on the popup window, click OK. Copy and paste the following code into the new script:

    Code Block
    var invert = false; // Decides if the value should increase or decrease
    thread.msleep(100); // Waits for Lamp tag to update
    while (tag.read("ON")) { // While Lamp tag is On (1)
      	tag.write("Count", tag.read("Count") + 1); // add 1 to count
      	thread.msleep(5000); // Waits for Count tag to update
    }

    Once pasted in, close the Script Editor by clicking OK. Select the lamp and go to the Actions tab. If Actions does not display, go to View > Properties > Actions and check the box. Under On Press, click the Action field and Create New Command. Click on Add New Command and select Toggle Tag Value. In the Tag field, select the ON tag. Then, in the top left of the Command Editor, click the + icon to create a new command. Change the new command to Call Script and select the created script.

Image Added