Two Numbers From a Reply
medium
Reads a setpoint and an actual value from a controller reply such as 'fg500-34900'.
What it teaches
STOD reads the first number it finds and stops, so it reads 500 from 'fg500-34900' and never reaches 34900. The second number has to be taken out of the text after the separator before it is converted, without the '-', or STOD reads '-34900' as minus 34900. A reply without the '-', such as 'fg500', is not valid, and STOD of text with no digits gives 0, which looks like a real reading.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| Out_Setpoint | Output | DINT | 0 | The number before the dash |
| Out_Actual | Output | DINT | 0 | The number after the dash |
| Sts_Valid | Output | BOOL | 0 | The reply has a dash |
| Ref_Reply | InOut | STRING | — | A controller reply such as 'fg500-34900' |
Required behavior
- A temperature controller answers with two letters, its setpoint, a '-' and its actual value: 'fg500-34900' is setpoint 500 and actual value 34900. Either number can have any number of digits.
- Every scan, Out_Setpoint and Out_Actual hold the two numbers and Sts_Valid is 1.
- STOD reads only the first number in a text, so it reads 500 from the whole reply. To read the actual value, take the text after the '-' first. The '-' is a separator, not a minus sign.
- A reply with no '-' is not valid: Sts_Valid is 0 and both numbers are 0.
- Never change Ref_Reply.