Add line response feature

Add a simple line response feature to make it possible to send e.g. a
command string to your serial device and easily receive and parse a line
response.

This is a convenience feature for simple request/response interaction
based on lines. For more advanced interaction the socket feature should
be used instead.

The line response feature is detailed via the following options:

 -r, --response-wait

Wait for line response then quit. A line is considered any string ending
with either CR or NL character. If no line is received tio will quit
after response timeout.

Any tio text is automatically muted when piping a string to tio while in
response mode to make it easy to parse the response.

 --response-timeout <ms>

Set timeout [ms] of line response (default: 100).

Example:

Sending a string (SCPI command) to a test instrument (Korad PSU) and
print line response:

 $ echo "*IDN?" | tio /dev/ttyACM0 --response-wait
 KORAD KD3305P V4.2 SN:32477045
This commit is contained in:
Martin Lund 2022-08-13 00:04:00 +02:00
parent a75e04b883
commit e837fd0303
9 changed files with 143 additions and 7 deletions

View file

@ -33,53 +33,65 @@ extern char ansi_format[];
#define ansi_printf(format, args...) \
{ \
if (!option.mute) { \
if (option.color < 0) \
fprintf (stdout, "\r" format "\r\n", ## args); \
else \
fprintf (stdout, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \
} \
}
#define ansi_error_printf(format, args...) \
{ \
if (!option.mute) { \
if (option.color < 0) \
fprintf (stderr, "\r" format "\r\n", ## args); \
else \
fprintf (stderr, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \
fflush(stderr); \
} \
}
#define ansi_printf_raw(format, args...) \
{ \
if (!option.mute) { \
if (option.color < 0) \
fprintf (stdout, format, ## args); \
else \
fprintf (stdout, "%s" format ANSI_RESET, ansi_format, ## args); \
} \
}
#define tio_warning_printf(format, args...) \
{ \
if (!option.mute) { \
if (print_tainted) \
putchar('\n'); \
if (option.color < 0) \
fprintf (stdout, "\r[%s] Warning: " format "\r\n", current_time(), ## args); \
else \
ansi_printf("[%s] Warning: " format, current_time(), ## args); \
} \
}
#define tio_printf(format, args...) \
{ \
if (!option.mute) { \
if (print_tainted) \
putchar('\n'); \
ansi_printf("[%s] " format, current_time(), ## args); \
print_tainted = false; \
} \
}
#define tio_printf_raw(format, args...) \
{ \
if (!option.mute) { \
if (print_tainted) \
putchar('\n'); \
ansi_printf_raw("[%s] " format, current_time(), ## args); \
print_tainted = false; \
} \
}
#ifdef DEBUG