mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
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:
parent
a75e04b883
commit
e837fd0303
9 changed files with 143 additions and 7 deletions
12
src/print.h
12
src/print.h
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue