This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

scanf() and syntax checking

I need to syntax check incomming queries/commands on the UART and i would like some idears on how to do it.
The syntax of the commands are as follow:

Syntax required for a query is:
@<device address><query>?;FF

Syntax required for a command is:
@<device address><command>!<parameter>;FF

Examples:
Query current baud rate: @253BR?;FF
Change baud rate to 19200: @253BR!19200;FF
where:
@ <attention character>
253 <device address>
BR? <query> (for query syntax)
BR!19200 <command>!<parameter> (for command syntax)
;FF <terminator>

Please note the termination is ;FF and not CR or LF.

Is it possible to use the scanf() function for this task?
Something like this perhaps:

scanf("@%3s%2s?;FF", adr, command);

Parents
  • "actual", the number of bytes that were actually matched from the input

    Not quite. Actual will be the number of "conversions" successfully completed. Unless all specifiers in the format string match only one single character, that's not the same as the number of characters matched.

    If you want the length of successfully matched input, you need the %n format specifier.

Reply
  • "actual", the number of bytes that were actually matched from the input

    Not quite. Actual will be the number of "conversions" successfully completed. Unless all specifiers in the format string match only one single character, that's not the same as the number of characters matched.

    If you want the length of successfully matched input, you need the %n format specifier.

Children
No data