diff --git a/Makefile b/Makefile index 1f276e4..8a9bd0a 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ CFLAGS += -fno-common -ffunction-sections -fdata-sections -Wunused-function CFLAGS += -I$(INCL_DIR) CFLAGS += -DSCPI_FINE_ERRORS -CFLAGS += -DSCPI_WEIRD_ERRORS +#CFLAGS += -DSCPI_WEIRD_ERRORS ############################################################################### diff --git a/example/example.c b/example/example.c index 1c74e4f..5f973f3 100644 --- a/example/example.c +++ b/example/example.c @@ -35,6 +35,7 @@ int main(void) // test chardata send_cmd("CHARD FOOBAR123_MOO_abcdef_HELLO, 12\n"); + send_cmd("SINGLE_STR_ARG \n"); send_cmd("SYST:ERR:ALL?\n"); } @@ -132,6 +133,13 @@ void cmd_ERROR_FALLBACK_cb(const SCPI_argval_t *args) } +void cmd_SINGLE_STR_ARG_cb(const SCPI_argval_t *args) +{ + (void) args; + + printf("Single str arg = %s", args[0].STRING); +} + // Command definition (mandatory commands are built-in) const SCPI_command_t scpi_commands[] = { { @@ -159,6 +167,11 @@ const SCPI_command_t scpi_commands[] = { .levels = {"ERROR_FALLBACK"}, .callback = cmd_ERROR_FALLBACK_cb }, + { + .levels = {"SINGLE_STR_ARG"}, + .params = {SCPI_DT_STRING}, + .callback = cmd_SINGLE_STR_ARG_cb + }, { .levels = {"CHARData"}, .params = {SCPI_DT_CHARDATA, SCPI_DT_INT}, diff --git a/source/scpi_parser.c b/source/scpi_parser.c index b9a1fae..5b7def8 100644 --- a/source/scpi_parser.c +++ b/source/scpi_parser.c @@ -791,12 +791,12 @@ static void pars_arg_eol_do(bool keep_levels) { int req_cnt = cmd_param_count(pst.matched_cmd); - if (pst.arg_i < req_cnt) { + if (pst.arg_i + (pst.charbuf_i ? 1 : 0) < req_cnt) { // not the last arg yet - fail if (pst.charbuf_i > 0) pst.arg_i++; // acknowledge the last arg - sprintf(ebuf, "Required %d, got %d.", req_cnt, pst.arg_i); + sprintf(ebuf, "Required %d arg, got %d.", req_cnt, pst.arg_i); scpi_add_error(E_CMD_MISSING_PARAMETER, ebuf); pst.state = PARS_DISCARD_LINE;