mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Add experimental RS-485 support
Many modern RS-485 serial devices such as the ones from FTDI already operate in RS-485 mode by default and will work with tio out of the box. However, there are some RS-232/485 devices which need to be switched from e.g. RS-232 to RS-485 mode to operate accordingly on the physical level. This commit implements the switching mechanism and interface required to enable RS-485 mode. It only works on Linux and with serial devices which use device drivers that support the Linux RS-485 control interface. The RS-485 feature is detailed via the following options: --rs-485 Enable RS-485 mode --rs-485-config <config> Set RS-485 configuration Set the RS-485 configuration using the following key or key value pair format in the configuration field: RTS_ON_SEND=value Set logical level (0 or 1) for RTS pin when sending RTS_AFTER_SEND=value Set logical level (0 or 1) for RTS pin after sending RTS_DELAY_BEFORE_SEND=value Set RTS delay (ms) before sending RTS_DELAY_AFTER_SEND=value Set RTS delay (ms) after sending RX_DURING_TX Receive data even while sending data If defining more than one key or key value pair, they must be comma separated. Example use: $ tio /dev/ttyUSB0 --rs-485 --rs-r485-config=RTS_DELAY_AFTER_SEND=50,RX_DURING_TX
This commit is contained in:
parent
a58d406a3c
commit
ee46686fb6
13 changed files with 351 additions and 11 deletions
|
|
@ -35,6 +35,7 @@
|
|||
#include "misc.h"
|
||||
#include "print.h"
|
||||
#include "tty.h"
|
||||
#include "rs485.h"
|
||||
|
||||
enum opt_t
|
||||
{
|
||||
|
|
@ -44,6 +45,8 @@ enum opt_t
|
|||
OPT_LOG_STRIP,
|
||||
OPT_LINE_PULSE_DURATION,
|
||||
OPT_RESPONSE_TIMEOUT,
|
||||
OPT_RS485,
|
||||
OPT_RS485_CONFIG,
|
||||
};
|
||||
|
||||
/* Default options */
|
||||
|
|
@ -78,6 +81,10 @@ struct option_t option =
|
|||
.response_wait = false,
|
||||
.response_timeout = 100,
|
||||
.mute = false,
|
||||
.rs485 = false,
|
||||
.rs485_config_flags = 0,
|
||||
.rs485_delay_rts_before_send = -1,
|
||||
.rs485_delay_rts_after_send = -1,
|
||||
};
|
||||
|
||||
void print_help(char *argv[])
|
||||
|
|
@ -109,6 +116,8 @@ void print_help(char *argv[])
|
|||
printf(" -x, --hexadecimal Enable hexadecimal mode\n");
|
||||
printf(" -r, --response-wait Wait for line response then quit\n");
|
||||
printf(" --response-timeout <ms> Response timeout (default: 100)\n");
|
||||
printf(" --rs-485 Enable RS-485 mode\n");
|
||||
printf(" --rs-485-config <config> Set RS-485 configuration\n");
|
||||
printf(" -v, --version Display version\n");
|
||||
printf(" -h, --help Display help\n");
|
||||
printf("\n");
|
||||
|
|
@ -295,6 +304,8 @@ void options_parse(int argc, char *argv[])
|
|||
{"hexadecimal", no_argument, 0, 'x' },
|
||||
{"response-wait", no_argument, 0, 'r' },
|
||||
{"response-timeout", required_argument, 0, OPT_RESPONSE_TIMEOUT },
|
||||
{"rs-485", no_argument, 0, OPT_RS485 },
|
||||
{"rs-485-config", required_argument, 0, OPT_RS485_CONFIG },
|
||||
{"version", no_argument, 0, 'v' },
|
||||
{"help", no_argument, 0, 'h' },
|
||||
{0, 0, 0, 0 }
|
||||
|
|
@ -437,6 +448,14 @@ void options_parse(int argc, char *argv[])
|
|||
option.response_timeout = string_to_long(optarg);
|
||||
break;
|
||||
|
||||
case OPT_RS485:
|
||||
option.rs485 = true;
|
||||
break;
|
||||
|
||||
case OPT_RS485_CONFIG:
|
||||
rs485_parse_config(optarg);
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
printf("tio v%s\n", VERSION);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue