Use the Base Conversion Function
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.
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.
Follow the steps to Connect a Device and configure the following parameters.
- Device Type: Simulator
- Driver Name: Generator
- Enable Alias Topics: Select the checkbox.
After connecting the device, Add Tags to the device. Create the following tags.
- 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.
- 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.
- 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.
You can now create the analytics flows using data from the device and tags you previously created.
To create the analytics flow:
- Navigate to Analytics.
- On the analytics canvas, click Add processor. The Create a processor dialog displays.
On the analytics canvas, click Add processor. The Create a processor dialog displays.
- Select DataHub Subscribe.
In the Topic field, click the Search icon, select the device you previously created, and then select the alias topic for Tag 1.
- Click Save.
- Click Add processor again and select Base Conversion.
- In the Conversion field, make sure the default value decimal -> binary is selected, and click Save.
Connect the two processors, select Events, and enter a definition of tag1 for the connection.
- 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 tag2 for the connection.
- 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 tag3 for the connection.
- On the analytics canvas, click Save.
The configured analytics flows should look like the following.
You can view data on the analytics canvas by clicking the View icon in each Base Conversion processor.
The original decimal value of 200 is converted to a binary value of 11001000.
The original decimal value of 300 is converted to a hexadecimal value of 12c.
The original decimal value of 400 is converted to a octadecimal value of 620.