Find the Recipe
medium
Looks up a scanned code in a table of recipe codes and reports its line speed.
What it teaches
FIND searches inside one STRING; it cannot search an array of them, so a lookup compares the code with the table's elements one by one. 'RCP-104' is element 3, and when a code appears twice the first one wins. When nothing matches, the result has to say so, or element 0 looks like a match. An empty scan matches nothing, not even an empty slot in the table, where '' equals ''. The comparison is exact, so 'rcp-104' and a scan still ending in $r match nothing; clean the scan first, as the reply was cleaned in Strip the Terminator.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| Sts_Found | Output | BOOL | 0 | A recipe code matches the scan |
| Out_Index | Output | DINT | 0 | The matching element, or -1 |
| Out_Speed | Output | DINT | 0 | The matching recipe line speed, or 0 |
| Ref_Scan | InOut | STRING | — | The scanned recipe code |
| Ref_Codes | InOut | STRING[8] | — | The recipe codes |
| Ref_Speeds | InOut | DINT[8] | — | Line speed for each recipe |
Required behavior
- Every scan, look for Ref_Scan in Ref_Codes. When Ref_Codes[i] is exactly Ref_Scan, Sts_Found is 1, Out_Index is i and Out_Speed is Ref_Speeds[i].
- When two codes match, the first one wins. When none matches, Sts_Found is 0, Out_Index is -1 and Out_Speed is 0.
- An empty Ref_Scan means nothing was scanned. It never matches, not even an empty code.
- FIND searches inside one STRING and cannot search an array, so compare each code in turn.
- Never change Ref_Scan, Ref_Codes or Ref_Speeds.