# Change Recipe Through the PLC

You can swap the currently loaded spreadsheet configuration (or "recipe") of the running job with another recipe while the vision system is Online. Swapping recipes has several advantages over swapping entire jobs:

- Recipes are swapped relatively quickly, compared to changing the entire job.
- You can change the current recipe with the PLC when the system is Online or PausedPaused.
- The WebHMI of the job remains available during the recipe change, resulting in minimal operational outage.

Therefore, if you expect to use multiple acquisition settings and inspections configured on the spreadsheet, but you prefer to retain the IO settings and the WebHMI across the spreadsheet configurations, Cognex recommends setting up multiple recipes in the job in advance, so that you can quickly swap them when needed.

Note:

- You can change recipes only if the list of named spreadsheet cells is exactly the same in both recipes. If the list of named cells in the recipe configuration to load differs from the list of named cells the job has gone Online with, then the recipe configuration change will fail. In such cases, the failure of the change is indicated with the Recipe configuration is incompatible with component error message in the Output window.
- Persistent Tags cannot be changed by swapping recipes. Therefore, if you need to change such job elements as well, you must prepare separate job files with their own Tags.

You can change between recipes stored in the Products recipe group of the job by two means:

- By name: You can change recipes by specifying their name. In this case, the PLC supplies the ASCII character string in the userdata segment corresponding to the name of the spreadsheet configuration you want to switch to.

  For example, if you supply the string "myconfig1" in the userdata segment, then the vision system will load recipe Products.myconfig1 once the PLC executes the load command (0x4001 in hexadecimal, or 16385 in decimal value)

- By ID: You can also change recipes by specifying their ID (an integer between 0x3E8-0x7CF in hexadecimal, or 1000-1999 in decimal value). Once the PLC executes the load command, the vision system loads the recipe if it finds one with the specified ID in the Products recipe group.

  For example, if you have a recipe with the ID and name of 1340_myconfig within the Products recipe group, then specifying command 1340 will load that recipe.

See the below table for a summary of the available recipe commands and command IDs:

Action | CommandID (Hex) | CommandID (Dec)
Load Recipe by Name | 0x4001 | 16385
Load Recipe by ID | 0x3E8-0x7CF | 1000-1999

Note: If you specify a recipe that does not exist (that is, the current job contains no recipes with the name or ID corresponding to the ones specified in the userdata segment or with the decimal ID), then an error is flagged to the PLC with errorID 0x0402.

See the applicable protocol-specific topic for more information on how to change the currently loaded recipe:

- For Ethernet/IP, see: Load a Job or Recipe Through an Ethernet/IP PLC
- For PROFINET, see: Load a Job or Recipe Through a PROFINET PLC