Y_CO_ReName_CommandProcessor
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
- This function block is a template for designing a unique commandline interpreter and requires customization. See the customizationsteps below.
- The command streaming tools provided in the Comm Toolbox aredesigned to interpret commands starting with a twocharacter (two byte) command code followed by either delimiterseparated parameters or no parameters. The reason for thisis because two ASCII bytes can easily be converted to an INT,which is used with the CASE statement in this function block. Example commands are located in the customization stepsbelow.
Error Description
See the
Function Block ErrorID List.
Customization Steps
- Copy this Function block from the Comm Toolbox, paste it into your project, and rename with a different (but similar) name.
- 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.
- Change the ‘MachineData’ DataType in the CommandProcessor function block to match your structure name.
- Initialize the configuration elements in CircularByteBuffer.
- 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.
- PrmDelimiter specifies the character that separatesindividual parameters within a command. If PrmDelimiteris not specified, the function will automatically default to a comma, (BYTE#44).
- 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.
- Locate the comments “Customize the code below" and “Customize the code above"
- Remove example commands to avoid potential errors in operation.
- Add commands. Two examples are shown below:
- Move Relative command:
- MR,<axisnumber>,<distance>,<speed>,<accel/decel>
- Calculate the CommandCode which corresponds to the ASCII characters ‘MR’. The equation is: CHAR_TO_INT(‘M’)* 256 + CHAR_TO_INT(‘R’) = 19794.
- Add the CommandCode to the case statement.
- Use the GetParameter function block to separate command parameters. The example below uses GetParameter with “Method#Parameter?
- Load Positions command:
- LP,<Position1>,<Position2>,…,<Position50>
- Calculate the CommandCode which corresponds to the ASCII characters ‘LP’. The equation is: CHAR_TO_INT(‘L’)* 256 + CHAR_TO_INT(‘P’) = 19536
- Add the CommandCode to the case statement.
- Use the GetParameter function block to separate command parameters. The example below uses GetParameter with “Method#Character".
- Move Relative command:
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:
- Remove AND NOT(CommandCreated) from main WHILE loop as shown.