Encode Binary Buffer

The Encode Binary Buffer action writes multiple variable values into a single output binary buffer. The source variables, data types, offsets into the destination 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 encode into a binary buffer will be defined in the Rules in JSON parameter.
  • Staging File - To indicate the variables to encode into 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 encode into 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 Input 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.
    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 written into 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 binary buffer.
  • 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.
    • process.bit - Set specific bit ("bit_offset") from each offset starting from the current offset up to the total number of offsets ("count"). Only 1 bit in each offset is set. 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 - Set all bits starting from "bit_offset" of the current offset up to the total number of bits ("count"). Bits are set 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" } }
      { "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 encode into 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 There are two types:
  • Little Endian - Stores the value of the least significant byte(the "little end") into the destination binary buffer variable at the highest address.
  • Big Endian - Stores the value of the most significant byte (the "big end") into the destination binary buffer variable at the lowest address.

Input tab

Parameter Description
Binary Buffer Specifies the source binary buffer. This source binary buffer is copied to an internal buffer before the encoding (writing) of the individual source variables.
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 destination buffer needs to be accounted for.
Input 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 Input tab.
In the Value column, specify the source variable. The variable can be a constant, trigger macro, event variable, trigger variable or device variable.

Output tab

Parameter Description
Binary Buffer Specifies the destination binary buffer that stores the result of the Encode Binary Buffer action.
The result of the Encode Binary Buffer action is copied from the internal replica of the source binary buffer to the destination binary buffer.
If you want to update a source binary buffer directly with the variable values specified, then the Output tab Binary Buffer parameter should be set to the same variable as the Input tab Binary Buffer parameter.

Encode Binary Buffer example

This example shows the JSON description of the variables and the placement of the data as it is written into the output 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 }
}

Encode 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 written into the output 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" }
}

Related Topics Link IconRelated Topics