Adding Custom Metadata From Different Data Source Using DataPlugin

Updated Apr 3, 2024

Environment

Software

  • DIAdem
  • LabVIEW
  • SystemLink
  • SystemLink TDM DataFinder Module

Programming Language

  • Python
  • Visual Basic
  • LabVIEW G

Metadata is very important in a test and measurement workflow. Metadata is valuable because it helps identify, locate, and describe digital objects like files, images, videos, and websites.

NI DataPlugins enables DIAdem, LabVIEW, and SystemLink™ TDM DataFinder Module to read, inspect and search different kinds of custom file formats.

This article will share how to create a custom VBS-based DataPlugin using DIAdem to add metadata from a different data source into your test report.

  1. Launch DIAdem
  2. Select Settings >> Extensions >> Dataplugins 
    image.png
  3. Click on the grey plus icon to create a new VBS DataPlugin. 
    image.png
  4. Fill up the pop up dialog box accordingly. Details can be found at here . Click OK once done. 
    image.png
  5. Once the pop up dialog box closed, your DataPlugin will be shown in the DataPlugin Settings list. Double-click your DataPlugins.
  6. In the Configure New Dataplugin pop up dialog box, click Edit Script
    image.png
  7. Close the Configure New Dataplugin pop up dialog box and your DIAdem should now in SCRIPT, showing the script responsible for your DataPlugin.
  8. In NAVIGATOR, select File >> Open.
  9. In the Open dialog box, select your DataPlugin
    image.png
  10. Select data file provided as attachment in this article after download it to your environment and click Load
    image.png
  11. You will see the following data in your data portal. (Select Window >> Data Portal if data portal is not visible in your DIAdem environment.) 
    image.png
  12. Click sample1 and you will notice Storage data/time property is updated with time value the file is loaded into DIAdem. This is completed by line 13 of DataPlugin's script (refer to DataPlugin's script in SCRIPT). This is to demostrate properties in DIAdem's data portal are editable. 
    image.png
Adding the following API into the DataPlugin's script can add custom properties:
  • Add a custom property into file
Root.Properties.Add "File Custom Property Name", "File Custom Property Value"
  • Add a custom property into first channel group
Root.ChannelGroups(1).Properties.Add "ChannelGroup Custom Property Name", "ChannelGroup Custom Property Value"
  • Add a custom property into first channel of first channel group
Root.ChannelGroups(1).Channels(1).Properties.Add "Channel Custom Property Name", "Channel Custom Property Value"


These APIs can be used together with HTTP requests. This will ensure everytime when the data file is loaded, DataPlugin will retrieve the coresponded metadata from different data source and append into data portal.

  • Add a custom property into file
Root.Properties.Add "File Custom Property Name", "File Custom Property Value"

image.png

  • Add a custom property into first channel group
Root.ChannelGroups(1).Properties.Add "ChannelGroup Custom Property Name", "ChannelGroup Custom Property Value"

image.png

  • Add a custom property into first channel of first channel group
Root.ChannelGroups(1).Channels(1).Properties.Add "Channel Custom Property Name", "Channel Custom Property Value"

image.png

The following example retrieve Kuala Lumpur's datetime and add it as a custom property into file.
Option Explicit

Dim oRequest, res, oJsonParser, oVbsVariant
Set oRequest = CreateObject("MSXML2.ServerXMLHTTP.6.0")

Sub ReadStore(File)
  'Tell the file how the string data is formed.
  File.Formatter.Delimiters = ";"
  File.Formatter.LineFeeds = File.GetLineFeed()
 
  'Create a file accessor
  Dim Block : Set Block = File.GetStringBlock()
  Dim DirectAccessChannel : Set DirectAccessChannel = Block.Channels.Add("FileData", eString)

  'Provide the data to USI
  Root.Properties.Add "datetime", Now
  Dim ChannelGroup : Set ChannelGroup = Root.ChannelGroups.Add("MyChannelGroup1")
  Dim ImplicitChannel : Set ImplicitChannel = ChannelGroup.Channels.AddImplicitChannel("ValueIndex", 1, 1, DirectAccessChannel.Size(), eI32)
  ChannelGroup.Channels.AddDirectAccessChannel(DirectAccessChannel)
  
  res = sendRequest("get", "http://worldtimeapi.org/api/timezone/Asia/Kuala_Lumpur")

  Set oJsonParser = CreateJsonParser()
  Call oJsonParser.Deserialize(res, oVbsVariant)
  
  Root.Properties.Add "KL Time", oVbsVariant.Item("datetime")
End Sub

Function sendRequest(ByVal sType, byVal sUrl) 

  oRequest.open sType, sUrl, false 
  oRequest.setRequestHeader "Content-Type", "application/json" 
  oRequest.setRequestHeader "Accept", "application/json" 
  oRequest.setRequestHeader "User-Agent", "curl/7.50.1" 

  oRequest.send
  
  sendRequest = oRequest.responseText  
End Function
This is the outcome of the execution.
image.png

Attachments