Support for string variable in MODBUS TCP Adapter

From Datonis
Revision as of 10:21, 4 December 2017 by Mayank (talk | contribs)
Jump to: navigation, search

Use Case:

Read the ISBN barcode as string from the MODBUS using Datonis Edge Modbus Adapter and send it to Datonis. ISBN barcode is of 13 character string and these 13 characters are stored in 7 registers of Modbus having base address as 1.

e.g. ISBN barcode string is "9781400067909" and its data(in decimal format) in 7 registers of MODBUS are 14647 14385 13360 12336 13879 14640 14592 respectively.

Solution:

There are following steps through which you can achieve above use case:

  1. First create the four read tags tag_chars_1_4, tag_chars_5_8, tag_chars_9_12 and tag_chars_13 inside MODBUS config json 'thing_configs -> source_tags -> read_tags'. These will store the 1st to 4th character, 5th to 8th character, 9th to 12th character and 13th character of ISBN barcode respectively.
  2. Set the read_count for first three read tags as 2(to read 4 characters of barcode) and for last read tag as 1(to read 2 characters of barcode).
  3. Set the proper ref_addr for each read tags as shown in below sample MODBUS config json. Here it is assumed that base address for ISBN barcode string in MODBUS is 1.
  4. Set the val_type as long for each read tags.
  5. Set the other required config in read tags if required.
  6. Now create a derived tag barcode inside thing_configs -> derived_tags. Set the expression_js as shown in sample MODBUS config json. This expression has a toStr function which convert the input long to string of given count length. Expression toStr(tag_chars_1_4,4) will return the 4 character string which is "9781" in our case. Similarly toStr(tag_chars_5_8,4) and toStr(tag_chars_9_12,4) will return "4000" and "6790". Expression toStr(tag_chars_13_14,2).substring(0,1) will return "9". Now concatenate the all 4 string to make the full ISBN barcode.
  7. Now map this derived barcode with datonis metric inside thing_configs -> metric_mappings.

Sample MODBUS config json: