# Event Handling ## Overview This feature is responsible for integrating PFC equipment events and requests received over TCP/IP, as well as commands sent through it. !!! note "Supported Requests" BCTOP, BCBOTTOM, TRANSFER. ### Message Reference #### PFC → Connect IoT Messages | Message | Meaning | | ------------------------ | ------------------------------------------------- | | `#!STATUS ` | Current operation mode of the PFC device | | `#!BCTOP ` | Top barcode scanner read serial number | | `#!BCBOTTOM ` | Bottom barcode scanner read serial number | | `#!TRANSFER ` | Board transferred successfully | | `#!NOBOARD` | Board removed before validation | | `#!PONG` | Response to a PING keep-alive request | !!! info "TRANSFER is retransmitted by the PFC device up to 10 times every 4 seconds until the host acknowledges with COMPLETE." #### Connect IoT → PFC Commands | Command | Meaning | | -------------------- | ------------------------------------------------------------ | | `#!GO ` | Authorise board transfer | | `#!CONFIRM ` | Duplicate or exception handling — operator must check | | `#!COMPLETE ` | Acknowledge transfer completion | | `#!PING` | Keep-alive request | | `#!MESSAGE ` | Display a message on the PFC device screen | | `#!MSGBEEP ` | Display a message with a beep on the PFC device screen | #### Typical Sequence ``` txt 1. PFC → Host : #!BCTOP 2. Host → PFC : #!GO 3. (Board moves) 4. PFC → Host : #!TRANSFER 5. Host → PFC : #!COMPLETE ``` !!! warning "The host must send GO within **20 seconds** of receiving BCTOP or BCBOTTOM, otherwise the PFC device restarts the process." ### How to Configure #### Relevant Artifacts The table below describes the properties for this entity type: | Name | Type | Is Mandatory | Data Type | Description | | :-------------------- | :--------- | :----------: | :-------- | :----------------------------------------------- | | IoTMetadataDefinition | SmartTable | Yes | | Metadata configuration for equipment integration | #### IoTMetadataDefinition Resource Level Configuration At the **Resource** level, there are several configuration we can make to define how each PFC event is processed. | Resource | Resource Type | Area | Name | Value | Description | | ------------------ | ------------- | ---- | ---------------------------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | *MES PFC Resource* | | | **PFC_EventName_useService** | | On event call a Service. Format: `TypeSignature, Assembly | api/Route | ResourceName`. Example:`Cmf.Custom.ProjectName.Orchestration.InputObjects.PFCRequestInput, Cmf.Custom.ProjectName.Orchestration | api/Customer/PFCRequest | AOI01`. If the resource name segment is omitted, the MES Resource name linked to the controller will be used. | | *MES PFC Resource* | | | **PFC_EventName_useDEE** | | On event call a DEE. Format: `DEEName` or `DEEName | ResourceName`. Example:`CustomSimpleNotification | AOI01`. If the resource name segment is omitted, the MES Resource name linked to the controller will be used. | | *MES PFC Resource* | | | **PFC_useMESSAGE** | | Semicolon-separated list of event names for which the controller should send a **MESSAGE** command to the equipment when a service or DEE call fails. Example: `BCTOP; TRANSFER`. | | *MES PFC Resource* | | | **PFC_useMSGBEEP** | | Semicolon-separated list of event names for which the controller should send a **MSGBEEP** command to the equipment when a service or DEE call fails. Example: `BCTOP; TRANSFER`. | | *MES PFC Resource* | | | **PFC_useConfirm** | | The controller should send a **CONFIRM** command when it is configured in the IoTMetadata table. | --- ## How It Works When a new **PFC Event** is received it will be parsed and processed according to the configured workflow. ### Input Parameters The DEE or Service receives the following inputs: | Input | Description | | -------------- | ------------------------------------------------------------------------------------------------- | | `ResourceName` | Name of the MES Resource linked to the controller, or the resource defined in the metadata value. | | `EventType` | Name of the received PFC event (e.g. `BCTOP`). | | `SerialNumber` | Serial number extracted from the event message. | ### Output Parameters The DEE or Service should send the following outputs: | Input | Description | | --------- | --------------------------------------------------------------------------------------------- | | `Result` | Result of the operation performed by MES. | | `Message` | Message to be sent in case of controlled failure (max 16 characters). Default: `MES BLOCKED`. | ### Result Handling The DEE or Service must return a `Result` output that drives the controller response: | Result value | Controller response | | ------------------- | ---------------------------------------------------- | | `true` or `Success` | **GO** (BCTOP / BCBOTTOM) or **COMPLETE** (TRANSFER) | | Any other value | **CONFIRM**, **MESSAGE** or **MSGBEEP** | !!! warning "If the event is not a request, the controller will not send a response." ## Processing Modes When a request is received the normal process is: - Request received - MES call: - `true` or `Success` → **GO** / **COMPLETE** - Other response values or error → [See error handling section](#error-handling) Other Events behavior: - Event received - MES call: - `true` or `Success` → Finish execution - Other response values or error → [See error handling section](#error-handling) ### 1. Using a Service (`PFC__useService`) ??? Example "Configuration Example: BCTOP with Service" | Resource | ResourceType | Area | Name | Value | | -------- | ------------ | ---- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | AOI01 | | | PFC_BCTOP_useService | Cmf.Custom.ProjectName.Orchestration.InputObjects.PFCRequestInput, Cmf.Custom.ProjectName.Orchestration \| api/Customer/PFCRequest \| AOI01 | With this configuration, when a BCTOP event is received, the controller will call `api/Customer/PFCRequest` with the following inputs: * **$type**: `Cmf.Custom.ProjectName.Orchestration.InputObjects.PFCRequestInput, Cmf.Custom.ProjectName.Orchestration` * **Resource**: AOI01 * **EventType**: BCTOP * **SerialNumber**: *serial number from the event* If the service returns `Result = "Success"`, the controller will send a **GO** message back to the equipment. ### 2. Using a DEE (`PFC__useDEE`) ??? Example "Configuration Example: BCTOP with DEE" | Resource | ResourceType | Area | Name | Value | | -------- | ------------ | ---- | -------------------- | ----------------------------- | | AOI01 | | | PFC_BCTOP_useDEE | CustomSimpleNotification\|AOI01 | With this configuration, when a BCTOP event is received, the controller will call the DEE `CustomSimpleNotification` with the following inputs: * **ResourceName**: AOI01 * **EventType**: BCTOP * **SerialNumber**: *serial number from the event* If the DEE returns `Result = true`, the controller will send a **GO** message back to the equipment. ??? Example "Configuration Example: TRANSFER with DEE" | Resource | ResourceType | Area | Name | Value | | -------- | ------------ | ---- | ---------------------- | ------------------------ | | AOI01_Scanner | | | PFC_TRANSFER_useDEE | CustomTrackOutOperation | With this configuration, when a TRANSFER event is received, the controller will call `CustomTrackOutOperation` and, upon success, reply with **COMPLETE**. ### 3. No Configuration If no configuration is found: - The event is logged as missing in **IoTMetadataDefinition Smart Table** - No DEE or Service is invoked - Default behavior applies: - Events expecting a response → **GO** --- ### Error Handling When error messaging or confirm command are enabled via: - `PFC_useMESSAGE` - `PFC_useMSGBEEP` - `PFC_useCONFIRM` #### Behavior on Failure If a DEE or Service call fails for a configured event: 1. Send **CONFIRM** (If the key is set in the metadata table) 2. Send `MESSAGE` or `MSGBEEP` to equipment (If the key is set in the metadata table) - Contains error message (max 16 characters) The message content is retrieved from the DEE or Service output `Message` in case of a controlled error. Default is `MES BLOCKED`. For uncontrolled errors `MES ERROR!` will be sent. ??? Example "Configuration Example: MESSAGE on failure" | Resource | ResourceType | Area | Name | Value | | ------------- | ------------ | ---- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | AOI01_Scanner | | | PFC_BCTOP_useService | Cmf.Custom.ProjectName.Orchestration.InputObjects.PFCRequestInput, Cmf.Custom.ProjectName.Orchestration \| api/Customer/PFCRequest \| AOI01 | | AOI01_Scanner | | | PFC_useMESSAGE | BCTOP; TRANSFER | | AOI01_Scanner | | | PFC_useCONFIRM | True | With this configuration, if the service call fails for a BCTOP or TRANSFER event, the controller will: * Send `#!CONFIRM ` to the equipment. * Then send `#!MESSAGE ` to the equipment.