Queue Parts for Processing
medium
Queues up to four part IDs and releases them in arrival order.
What it teaches
When the next machine is busy, parts wait in line and leave in the order they arrived. In_Load and In_Unload act once each time they turn on. Holding one on does not load or unload again. A part ID can be 0, and empty slots are 0 too, so keep a count of stored parts rather than reading it off the array. Peek shows which part leaves next 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 oldest 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.