Versions Compared

Key

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

Exercise: Checking Data Logging with Object

Data Logger Configuration

  1. Create a Data Logger Model. Go to Tools > Data Log Editor. Click the + to 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 initial value to 0.

  1. Go to Tools > Data Log Editor. Then select Counter. Click on the Tab Tag List, then click the Add Tag button. Once you do, click the Add Tag button on the new page, check “Count,” then click Select. This will save the Tags. Click OK to exit the Add Tags page, then click OK to exit the page.

  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.

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

    Code Block
    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, right-click the script, click on Script Properties, and 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.

Data Logger Runtime

  1. Click Tools >Launch Simulator to launch the Canvas Simulator.

  1. Click the lamp to toggle it On. The Count tag will update every 5 seconds when the lamp turns on. The Data Log will also reflect any changes made to the Count tag every 5 seconds.

  1. Try changing the value of the count. Notice how the number will be correctly reflected in the following Data Log entry when you update the tag value.