aComRx_fGetNum pp,fw [D>=29]
Return a decimal number from the head of the Rx buffer for the serial port at address pp
. Skip any leading spaces. Process leading + or - sign if present. Terminate on anything thereafter that's not a decimal digit or decimal point, or after processing fw
characters in total (including spaces, sign and decimal point). Consume the characters used but not the terminating character. Result in W, NaN if nothing there. R register signals outcome. 0 = OK, 1 = no valid decimal number present.
Notes:
- This differs from the same instruction without the leading 'a' in that it explicitly nominates a serial port address (pp) rather than the default serial port.
- This instruction will only process characters that have already been received. You should therefore ensure that either a known terminating character, or the required number of characters, have been received before attempting to execute this instruction.
- The character count
fw
includes leading spaces, signs and decimal point. - The only characters removed from the buffer are leading spaces plus the characters that form the number. Hence, if a terminating character is encountered before
fw
characters are used, less thanfw
characters will be removed from the buffer. - Conversion will end on the first unexpected character, including a trailing space, a second sign character or a second decimal point. This overrides the field width.
- The valid range for
fw
is 1 to 255.fw
= 255 disables character counting. - Anything more than 7 digits of input is meaningless, as the floating point number representation is only accurate to 6 or 7 decimal places. Excess digits will be nevertheless be consumed, up to the limits of
fw
.
Can only exist on boards that have an uncommitted serial port other than the programming port.
See also COMRx_GetHex, COMRx_BufLen, COMRx_FindXInBuf
Examples
The following shows the result of the instruction ComRx_fGetNum 8
for various receive buffer contents.
Receive buffer contents before (Shown as ASCII (printable) characters. | Result returned in W | Receive buffer contents after conversion | Comment |
| 23.456 |
| |
| 123 |
| Leading spaces are counted in the field width. The decimal point "makes it", |
| -123.456 |
| All good, got it all |
| -123.45 | The last digit is excluded, because the field width of 8 terminates conversion. Furthermore, a subsequent conversion (with | |
| -12.3 |
| The second decimal point terminates conversion. If the same instruction were executed again (with |
Dialect exclusions: Not available in dialects before 29