feat(inputs.modbus): Add RS485 specific config options (#12786)

This commit is contained in:
Sven Rebhan 2023-03-07 19:29:59 +01:00 committed by GitHub
parent dcbd204195
commit 0a0cbc24d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 15 deletions

View File

@ -41,6 +41,7 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
controller = "tcp://localhost:502"
## Serial (RS485; RS232)
## For RS485 specific setting check the end of the configuration.
## For unix-like operating systems use:
# controller = "file:///dev/ttyUSB0"
## For Windows operating systems use:
@ -235,6 +236,21 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
machine = "impresser"
location = "main building"
## RS485 specific settings. Only take effect for serial controllers.
## Note: This has to be at the end of the modbus configuration due to
## TOML constraints.
# [inputs.modbus.rs485]
## Delay RTS prior to sending
# delay_rts_before_send = "0ms"
## Delay RTS after to sending
# delay_rts_after_send = "0ms"
## Pull RTS line to high during sending
# rts_high_during_send = false
## Pull RTS line to high after sending
# rts_high_after_send = false
## Enabling receiving (Rx) during transmission (Tx)
# rx_during_tx = false
## Enable workarounds required by some devices to work correctly
# [inputs.modbus.workarounds]
## Pause after connect delays the first request by the specified time.

View File

@ -33,23 +33,34 @@ type ModbusWorkarounds struct {
ReadCoilsStartingAtZero bool `toml:"read_coils_starting_at_zero"`
}
// According to github.com/grid-x/serial
type RS485Config struct {
DelayRtsBeforeSend config.Duration `toml:"delay_rts_before_send"`
DelayRtsAfterSend config.Duration `toml:"delay_rts_after_send"`
RtsHighDuringSend bool `toml:"rts_high_during_send"`
RtsHighAfterSend bool `toml:"rts_high_after_send"`
RxDuringTx bool `toml:"rx_during_tx"`
}
// Modbus holds all data relevant to the plugin
type Modbus struct {
Name string `toml:"name"`
Controller string `toml:"controller"`
TransmissionMode string `toml:"transmission_mode"`
BaudRate int `toml:"baud_rate"`
DataBits int `toml:"data_bits"`
Parity string `toml:"parity"`
StopBits int `toml:"stop_bits"`
Timeout config.Duration `toml:"timeout"`
Retries int `toml:"busy_retries"`
RetriesWaitTime config.Duration `toml:"busy_retries_wait"`
DebugConnection bool `toml:"debug_connection"`
Workarounds ModbusWorkarounds `toml:"workarounds"`
Log telegraf.Logger `toml:"-"`
// Register configuration
ConfigurationType string `toml:"configuration_type"`
Name string `toml:"name"`
Controller string `toml:"controller"`
TransmissionMode string `toml:"transmission_mode"`
BaudRate int `toml:"baud_rate"`
DataBits int `toml:"data_bits"`
Parity string `toml:"parity"`
StopBits int `toml:"stop_bits"`
RS485 *RS485Config `toml:"rs485"`
Timeout config.Duration `toml:"timeout"`
Retries int `toml:"busy_retries"`
RetriesWaitTime config.Duration `toml:"busy_retries_wait"`
DebugConnection bool `toml:"debug_connection"`
Workarounds ModbusWorkarounds `toml:"workarounds"`
ConfigurationType string `toml:"configuration_type"`
Log telegraf.Logger `toml:"-"`
// Configuration type specific settings
ConfigurationOriginal
ConfigurationPerRequest
@ -285,6 +296,14 @@ func (m *Modbus) initClient() error {
if m.DebugConnection {
handler.Logger = m
}
if m.RS485 != nil {
handler.RS485.Enabled = true
handler.RS485.DelayRtsBeforeSend = time.Duration(m.RS485.DelayRtsBeforeSend)
handler.RS485.DelayRtsAfterSend = time.Duration(m.RS485.DelayRtsAfterSend)
handler.RS485.RtsHighDuringSend = m.RS485.RtsHighDuringSend
handler.RS485.RtsHighAfterSend = m.RS485.RtsHighAfterSend
handler.RS485.RxDuringTx = m.RS485.RxDuringTx
}
m.handler = handler
case "ASCII":
handler := mb.NewASCIIClientHandler(path)
@ -296,6 +315,14 @@ func (m *Modbus) initClient() error {
if m.DebugConnection {
handler.Logger = m
}
if m.RS485 != nil {
handler.RS485.Enabled = true
handler.RS485.DelayRtsBeforeSend = time.Duration(m.RS485.DelayRtsBeforeSend)
handler.RS485.DelayRtsAfterSend = time.Duration(m.RS485.DelayRtsAfterSend)
handler.RS485.RtsHighDuringSend = m.RS485.RtsHighDuringSend
handler.RS485.RtsHighAfterSend = m.RS485.RtsHighAfterSend
handler.RS485.RxDuringTx = m.RS485.RxDuringTx
}
m.handler = handler
default:
return fmt.Errorf("invalid transmission mode %q for %q", m.TransmissionMode, u.Scheme)

View File

@ -24,6 +24,7 @@
controller = "tcp://localhost:502"
## Serial (RS485; RS232)
## For RS485 specific setting check the end of the configuration.
## For unix-like operating systems use:
# controller = "file:///dev/ttyUSB0"
## For Windows operating systems use:

View File

@ -1,3 +1,18 @@
## RS485 specific settings. Only take effect for serial controllers.
## Note: This has to be at the end of the modbus configuration due to
## TOML constraints.
# [inputs.modbus.rs485]
## Delay RTS prior to sending
# delay_rts_before_send = "0ms"
## Delay RTS after to sending
# delay_rts_after_send = "0ms"
## Pull RTS line to high during sending
# rts_high_during_send = false
## Pull RTS line to high after sending
# rts_high_after_send = false
## Enabling receiving (Rx) during transmission (Tx)
# rx_during_tx = false
## Enable workarounds required by some devices to work correctly
# [inputs.modbus.workarounds]
## Pause after connect delays the first request by the specified time.