How-To Guides
Analytics Guides

Use the Base Conversion Function

12min

Base conversion is the process of converting a number from one numeral system to another.

You have the following base conversion options:

  • decimal -> binary
  • decimal -> hexaDecimal
  • decimal -> octaDecimal
  • binary -> decimal
  • octaDecimal -> decimal
  • hexaDecimal -> decimal

Notes:

  • For conversion of various units to decimal, it is expected that the input is a string value.
  • Your input needs to have a field named value if you are converting from binary, octadecimal, or hexadecimal to decimal.

Video



User Scenario

Review the following user scenario for using the Base Conversion processor. In manufacturing plants, engineers need to work with machines that use different protocols. If a machine produces diagnostic data in one type of format, and the monitoring software requires decimal format for analysis, the Base Conversion Function can convert the data quickly. This allows for seamless integration between the machine and the monitoring system.

For this guide, you will simulate data coming from a PLC and generate the decimal values 200, 300, and 400. You will then convert them accordingly using base conversion.

Step 1: Add a Device

Follow the steps to Connect a Device and configure the following parameters.

  • Device Type: Simulator
  • Driver Name: Generator
  • Enable Alias Topics: Select the checkbox.

Step 2: Add Tags

After connecting the device, Add Tags to the device. Create the following tags.

Tag 1

  • Name: Select S - Random value generator.
  • Value Type: Select int64.
  • Polling Interval: Enter 5.
  • Tag Name: Enter Tag 1.
  • Min_value: Enter 200.
  • Max_value: Enter 200.

Tag 2

  • Name: Select S - Random value generator.
  • Value Type: Select int64.
  • Polling Interval: Enter 5.
  • Tag Name: Enter Tag 2.
  • Min_value: Enter 300.
  • Max_value: Enter 300.

Tag 3

  • Name: Select S - Random value generator.
  • Value Type: Select int64.
  • Polling Interval: Enter 5.
  • Tag Name: Enter Tag 3.
  • Min_value: Enter 400.
  • Max_value: Enter 400.

Step 3: Create Analytics Flows

You can now create the analytics flows using data from the device and tags you previously created.

To create the analytics flow:

  1. Navigate to Analytics.
  2. On the analytics canvas, click Add processor. The Create a processor dialog displays.

    The Add processor option
    The Add processor option
    
  3. Select DataHub Subscribe.
  4. In the Topic field, click the search icon, select the device you previously created, and then select the alias topic for Tag 1.

    Topic search icon
    Topic search icon
    
  5. Click Save.
  6. Click Add processor again and select Base Conversion.
  7. In the Conversion field, make sure the default value decimal -> binary is selected, and click Save.
  8. Connect the two processors, select Events, and enter a definition of Tag 1 for the connection.

    Processor flow for Tag 1
    Processor flow for Tag 1
    
  9. Repeat steps 2-8 for Tag 2 and configure the following:
    • In the DataHub Subscribe processor, select the alias topic for Tag 2.
    • In the Base Conversion processor, select a conversion of decimal -> hexaDecimal.
    • When you connect the two processors, select Events and enter a definition of Tag 2 for the connection.
  10. Repeat steps 2-8 for Tag 3 and configure the following:
    • In the DataHub Subscribe processor, select the alias topic for Tag 3.
    • In the Base Conversion processor, select a conversion of decimal -> octaDecimal.
    • When you connect the two processors, select Events and enter a definition of Tag 3 for the connection.
  11. On the analytics canvas, click Save.

The configured analytics flows should look like the following.

Document image


Step 4: View Base Conversion Data

You can view data on the analytics canvas by clicking the View icon in each Base Conversion processor.

View icons for Base Conversion processors
View icons for Base Conversion processors


Base Conversion Data for Tag 1

The original decimal value of 200 is converted to a binary value of 11001000.

Tag 1 value after base conversion
Tag 1 value after base conversion


Base Conversion Data for Tag 2

The original decimal value of 300 is converted to a hexadecimal value of 12c.

Tag 2 value after base conversion
Tag 2 value after base conversion


Base Conversion Data for Tag 3

The original decimal value of 400 is converted to a octadecimal value of 620.

Tag 3 value after base conversion
Tag 3 value after base conversion