Manage a Tray Stack
medium
Stores up to four tray IDs and removes the most recently added tray first.
What it teaches
Trays go on the top of the pile and come off the top, so the last one loaded is the first one out. Reuse the request and capacity rules from Queue Parts for Processing, but now the newest tray leaves and nothing has to shift down. Peek shows the tray on top without removing it.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| In_Load | Input | BOOL | 0 | Request to add an ID |
| In_Unload | Input | BOOL | 0 | Request to remove an ID |
| In_PartId | Input | DINT | 101 | ID to add; every DINT value, including 0, is valid |
| In_Reset | Input | BOOL | 0 | Clear storage and results |
| Out_PartId | Output | DINT | 0 | Last successfully removed ID |
| Out_Peek | Output | DINT | 0 | Next ID to remove, or 0 when empty |
| Out_Count | Output | DINT | 0 | Number of stored IDs |
| Sts_Empty | Output | BOOL | 0 | 1 when no IDs are stored |
| Sts_Full | Output | BOOL | 0 | 1 when four IDs are stored |
| Ref_Parts | InOut | DINT[4] | — | Four IDs in loading order, oldest at index 0; unused slots are 0 |
Required behavior
- Start empty with a zero-filled Ref_Parts array. The caller observes this array but does not edit it while operating. Each distinct instance owns its own count.
- In_Load and In_Unload act once on their rising edges. Held requests do not repeat.
- An unload removes the newest stored ID. Preserve loading order among remaining IDs, keep them packed from index 0, and clear the vacated slot.
- A load appends In_PartId when there is space. Every DINT value, including 0 and negative IDs, is valid. Capacity is four.
- When both requests rise together, unload first, then load. Empty unload and full load are rejected without changing the buffer or Out_PartId.
- Out_PartId retains the last successful unload; Out_Peek, Out_Count, Sts_Empty and Sts_Full describe the resulting buffer every scan.
- In_Reset clears storage, count and result IDs every scan, sets Empty, and clears Full. Reset wins; held requests are consumed during reset and need a new edge afterward.