Skip to main content
Version: Next

LMES Generate Code Process Logic

This document details the processing logic of the Generate Code activity (GenerateCodeActivity), which is responsible for generating unique barcodes based on a series of rules and inputs.

Flowchart​

Detailed Processing Steps​

1. Start and Function Check​

When the flow transitions to the "Generate Code" activity, the system first determines whether the GenerateCode function is in the Enable state from the flow's context data (ProcessModel).

  • Yes: If the function is enabled, the flow continues execution.
  • No: If the function is disabled, the system records a description of "Generate code function is disabled" in the flow variable and directly ends the current activity.

2. Read Context Information​

The system reads the following key information from the flow data (Flow.DataItems) for subsequent barcode generation:

  • Product Identification Code (GenerateCodeProductVariableValue): Code used to uniquely identify the product, highest priority.
  • Customer Name (GenerateCodeCustomerNameVariableValue): Used to filter specific barcode rules in certain scenarios.
  • Barcode Rule ID (GenerateCodeBarcodeRule): Directly specifies the GUID of the barcode generation rule to be used.

3. Determine Barcode Generation Rule​

The system determines which barcode generation rule (barcodeId) to use based on the read information, in the following priority order:

3.1. Based on "Product Identification Code"​

If a Product Identification Code is provided:

  1. The system uses this identification code to query the corresponding product model (ProductModel).
  2. If the product model is not found, the flow will record an error message and terminate.
  3. If the product is found, the system will query the most matching barcode generation rule combining Work Section ID and Product ID.

3.2. Based on "Barcode Rule ID" (Hidden Feature, Secondary Development Extension)​

If no product identification code is provided, but a Barcode Rule ID is directly specified:

  1. The system attempts to parse the string into a GUID.
  2. If parsing fails, the flow will record an error message and terminate.
  3. If parsing is successful, this GUID is directly used as the barcode generation rule ID.

3.3. Based on Current Context (Order/Recipe)​

If none of the above information is provided:

  1. The system calls the GetCurrentProduct method to attempt to infer the product currently being produced from the currently applied Recipe (Formula), Order (Order), or Inspection Task.
  2. If the current product cannot be determined, the flow will record an error message and terminate.
  3. If the product information is successfully obtained, the system will use this Product ID and Process ID and optional Customer Name to query the matching barcode generation rule.

4. Generate Barcode​

After successfully determining the barcode generation rule ID (barcodeId):

  1. If barcodeId is empty (i.e., no applicable rule is found), the flow will record an error message and terminate.
  2. The system calls the barcode service (IBarcodeProvider.GenerateAsync), passing in barcodeId, Process ID, and Station ID, to request the generation of a new barcode.

5. Distribute Generation Result​

The return result of the barcode generation service will determine the final state of the flow:

  • Success:
    • The generated barcode string will be written into the flow data GenerateCodeBarcodeVariableValue.
    • The system will record a success log containing the generated code content.
  • Failure:
    • The failure reason and related error information will be written into the flow data GenerateCodeDescriptionValue.
    • The system will record a warning log containing the detailed failure reason.

6. End​

After completing the result distribution, the logic execution of the GenerateCodeActivity activity is finished, and the flow will continue to transition to the next step according to the design. Subsequent operations such as signal reset and result clearing are handled by other activities in the flow.