-

Y_CO_ReName_CommandProcessor

Image

The Y_CO_ReName_CommandProcessor function block is a user customizable function block that parses data from a circular buffer and copies it into a user defined structure of data to operate the machine. To use this function, copy and paste it into the main project, rename it, and customize it and populate the MachineData structure. It's designed to identify variable length commands in the CircularByteBuffer and process them on a case by case basis.

Parameters

* Parameter Data Type Description Default
VAR_IN_OUT
V MachineData Yt_CO_MyMachineStruct Create a user defined type which suits the needs of the application.
V CircularByteBuffer Yt_CO_CircularBufferStruct A string of characters such as MV;1.0;-10.5;3.007
VAR_INPUT
B Enable BOOL The function will continue to execute every scan while Enable is held high and there are no errors. FALSE
VAR_OUTPUT
B Valid BOOL The Valid output indicates that the function block is operating normally and the outputs of the function block are valid.
B Error BOOL Set high if an error has occurred during the execution of the function block. This output is cleared when 'Execute' or 'Enable' goes low.
E ErrorID UINT If Error is true, this output provides the Error ID. This output is reset when 'Execute' or 'Enable' goes low.
V CommandCount UDINT Reports the number of commands processed since Enable was set high.

Notes

Error Description

See the Function Block ErrorID List.

Customization Steps

  1. Copy this Function block from the Comm Toolbox, paste it into your project, and rename with a different (but similar) name.
  2. Data type MyMachineStruct (VAR_IN_OUT ‘MachineData’) is only an example structure. A custom structure must be designed to uniquely match the needs of the application. An example is shown below.
  3. Change the ‘MachineData’ DataType in the CommandProcessor function block to match your structure name.
  4. Initialize the configuration elements in CircularByteBuffer.
    1. CmdDelimiters are used to mark the end of a complete command. Up to four characters can be specified. Typically,<cr>, which is BYTE#13 or <cr><lf>, which is BYTE#13 BYTE#10 are used. If CmdDelimiters not specified, will default functionality will automatically accept Carriage Return or Carriage Return & Line Feed.
    2. PrmDelimiter specifies the character that separatesindividual parameters within a command. If PrmDelimiteris not specified, the function will automatically default to a comma, (BYTE#44).
    3. Size must represent the defined size of the DataType definition for the CircularBufferStruct’s “Data? Element. If Size not specified, it will default to zero and the InputBufferManager function block will cause an error. Normally, this value is 8192 as the structure definition is in the CommToolbox itself. If this must be increased for any reason, modify the Comm Toolbox DataType definition and set the Size input accordingly.
  5. Locate the comments “Customize the code below" and “Customize the code above"
  6. Remove example commands to avoid potential errors in operation.
  7. Add commands. Two examples are shown below:
    1. Move Relative command:
      1. MR,<axisnumber>,<distance>,<speed>,<accel/decel>
      2. Calculate the CommandCode which corresponds to the ASCII characters ‘MR’. The equation is: CHAR_TO_INT(‘M’)* 256 + CHAR_TO_INT(‘R’) = 19794.
      3. Add the CommandCode to the case statement.
      4. Use the GetParameter function block to separate command parameters. The example below uses GetParameter with “Method#Parameter?
    2. Load Positions command:
      1. LP,<Position1>,<Position2>,…,<Position50>
      2. Calculate the CommandCode which corresponds to the ASCII characters ‘LP’. The equation is: CHAR_TO_INT(‘L’)* 256 + CHAR_TO_INT(‘P’) = 19536
      3. Add the CommandCode to the case statement.
      4. Use the GetParameter function block to separate command parameters. The example below uses GetParameter with “Method#Character".

Optional Customization Steps

The CommandProcessor can process one or many commands per scan. This is a performance tuning issue. If the host device must send several setting at once, the MPiec controller may seem slow to process all the commands based on the Task interval. If the Task Interval and priority are set such that the CommandProcessor will have time to continue scanning the CircularByteBuffer in one scan until ALL bytes have been processed, performance will be improved by changing the following CommandProcessor code:

  1. Remove AND NOT(CommandCreated) from main WHILE loop as shown.



 


This help information is valid for iCube Engineer Online Help 2025.6

Copyright © 2025 YASKAWA EUROPE GmbH and © 2025 YASKAWA America, Inc.