Decode Binary Buffer

The Decode Binary Buffer action uses a single input binary buffer to retrieve data values and then writes the values to multiple output variables. The source binary buffer variables, data types, offsets in the input buffer, counts, intervals, lengths and special handling options can be specified.

Parameter descriptions

The action provides these parameters:

Parameter Description
Rules Input Type The options are:
  • Manual - To indicate the variables to decode from a binary buffer will be defined in the Rules in JSON parameter.
  • Staging File - To indicate the variables to decode from a binary buffer will be defined in the File parameter.
Rules in JSON When Rules Input Type is Manual, this parameter is used to specify the JSON description of the variables to decode from a binary buffer. Each variable is specified as shown in the example with:
  • Map variable name - The name of the map variable, which will be added as a row on the Output tab.
  • offset - The location where the data will start in the binary buffer.  This is a required field.
  • type - The type of the source variable in the binary buffer.
    The supported types are:
    BOOL, INT1, INT2, INT4, INT8, UINT1, UINT2, UINT4, UINT8, FLOAT4, FLOAT8, STRING, and BINARY.
    For the Mitsubishi MESInterface IT product:
    BIT, BYTE, WORD, DWORD, LWORD, UBYTE, UWORD, UDWORD, ULWORD, REAL, LREAL, STRING,and BINARY.
    The special types listed below are also supported.
  • count - The number of variable elements. Specify a 1 for a single (scalar) element or a value greater than 1 for an array.
  • interval - The distance between the starting of each element of an array. This field is only used when an array is specified.
    • For example: if the offset is 30, the interval is 6, and the count is 4, the data will be read from the binary buffer at offsets 30, 36, 42, and 48 regardless of the data type.
    • If the interval is not specified, or specified as a zero, the distance will be the length of the element. Each element will start immediately after the end of the previous element.
  • length - The length of data. This is only specified if the type is STRING or BINARY.
  • swap - A boolean value to indicate whether the data byte/word order should be swapped before writing into the destination variable.
  • special - Custom handling of the data types:
    • melco.timestamp - A 6 byte BCD representation of time used by some Mitsubishi MELCO Laser machines.
    • rockwell.logix.string - A 4 byte length value, followed by the string data.
    • rockwell.logix.INT4bool - A single or multi-byte integer that represents a stand-alone boolean tag or a group of stand-alone boolean tags. Individual boolean values are stored in the byte. The bit_offset value indicates which bit in the integer is associated with the boolean. These items can be written individually as boolean data types.
    • rockwell.logix.packedbool - A boolean array tag, represented as a 4 byte integer. Each element in the array of booleans is represented as a bit within the 4 byte integer. The 4 byte integer must be kept to maintain integrity with the representation of the boolean array on the Rockwell PLC.
    • siemens.string - The 1st byte is the full string length, the 2nd byte is the current string length, followed by the string data.

    • string.end_of_buffer - A variable length string that reads data from the "offset" to the end of the binary buffer. The "type" must be "STRING" or "BINARY", "count" must be 1, and "length" must be 0.

    • process.bit - Get specific bit ("bit_offset") from each offset starting from the current offset up to the total number of offsets ("count"). Gets only 1 bit in each offset. The next offset is then processed depending on the count (in bytes).
      • The range of bit_offset allowed is 0 to 7. Each offset only has 8 bits to process.
      • The type must be "BOOL". Interval, length, and swap are not used.
    • process.all.bits - Get all bits starting from "bit_offset" of the current offset up to the total number of bits ("count"). Bits are processed consecutively bit by bit and starting at bit_offset 0 in the next offset depending on the count (in bits).

      • The range of bit_offset allowed is 0 to 7. Increase the offset to process from the next byte.

      • The type must be "BOOL". Interval, length, and swap are not used.

      Examples of using the custom data types:

      { "melco_timestamp_var" : {"offset":12, "type":"INT8", "count":1, "special":"melco.timestamp" } }
      { "rockwell_string_var" : {"offset":12, "type":"STRING", "count":1, "length":50, "special":"rockwell.logix.string" } }
      { "bool1" : {"offset":0, "count":1, "type":"BOOL", "bit_offset":0, "special":"rockwell.logix.INT4bool" }}
      { "bool2" : {"offset":0, "count":1, "type":"BOOL", "bit_offset":1, "special":"rockwell.logix.INT4bool" }}
      { "boolArray" : {"offset":0, "count":1, "type":"INT4", "special":"rockwell.logix.packedbool" }}
      { "siemens_string_var" : {"offset":12, "type":"STRING", "count":1, "length":50, "special":"siemens.string" } }
      { "end_of_buffer_var" : {"offset": 12, "type":"STRING", "count":1, "length":0 , "special":"string.end_of_buffer" } } 
      { "process_bit_var" : {"offset":0, "type":"BOOL", "count":3, "bit_offset":1, "special":"process.bit" } }
      { "process_all_bits_var" : {"offset":3, "type":"BOOL", "count":10, "bit_offset":1, "special":"process.all.bits" } }

      The multi-line input icon can be used to display a larger input area for the JSON variable description.

File When Rules Input Type is Staging File, this parameter is used to specify a file in the Staging Browser area that contains the JSON description of the variables to decode from a binary buffer.
This file is read when the trigger is edited. The description of the variables in the file is handled in the same manner as the Rules in JSON parameter. The file is only read when the trigger is edited, so changes to the file's content do not impact a started trigger's definition or function. To change a trigger's function, the trigger must be stopped, edited (the file is read) to make any necessary changes, and then restarted.
Byte Order The options are:
  • Little Endian - The low-order byte/word of the value in the binary buffer is stored at the highest address.
  • Big Endian - The high-order byte/word of the value in the binary buffer is stored at the highest address.

Input tab

Parameter Description
Binary Buffer Specifies the source binary buffer.
Offset An optional offset used in addition to each variable's offset value.
This can be used, for example, when a variable length header in the source buffer needs to be accounted for.

Output tab

Parameter Description
Output map variables The map variables identified in the JSON variable description.
Each variable in the JSON variable description will be added as a map variable row in the Output tab.
In the Value column specify the destination variable. The variable can be trigger variable or device variable.

Decode Binary Buffer example

This example shows the JSON description of the variables and the placement of the data as it is read from the source binary buffer.

{
 "First" : {"offset":8, "type":"FLOAT4", "count":1 },
 "Second" : {"offset": 12, "type":"STRING", "count":2, "length":4 },
 "Third" : {"offset":30, "type":"INT4", "count":4, "interval":6 }
}

Decode Binary Buffer example using process.bit and process.all.bits

This example shows the JSON description of the variables and the placement of the data as it is read from the source binary buffer.

{
 "First" : {"offset":0, "type":"BOOL", "count":3, "bit_offset":1, "special":"process.bit" },
 "Second" : {"offset":2, "type":"BOOL", "count":10, "bit_offset":2, "special":"process.all.bits"}
}