feat(inputs.modbus): Add RS485 specific config options (#12786)
This commit is contained in:
parent
dcbd204195
commit
0a0cbc24d5
|
|
@ -41,6 +41,7 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
controller = "tcp://localhost:502"
|
controller = "tcp://localhost:502"
|
||||||
|
|
||||||
## Serial (RS485; RS232)
|
## Serial (RS485; RS232)
|
||||||
|
## For RS485 specific setting check the end of the configuration.
|
||||||
## For unix-like operating systems use:
|
## For unix-like operating systems use:
|
||||||
# controller = "file:///dev/ttyUSB0"
|
# controller = "file:///dev/ttyUSB0"
|
||||||
## For Windows operating systems use:
|
## For Windows operating systems use:
|
||||||
|
|
@ -235,6 +236,21 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
machine = "impresser"
|
machine = "impresser"
|
||||||
location = "main building"
|
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
|
## Enable workarounds required by some devices to work correctly
|
||||||
# [inputs.modbus.workarounds]
|
# [inputs.modbus.workarounds]
|
||||||
## Pause after connect delays the first request by the specified time.
|
## Pause after connect delays the first request by the specified time.
|
||||||
|
|
|
||||||
|
|
@ -33,23 +33,34 @@ type ModbusWorkarounds struct {
|
||||||
ReadCoilsStartingAtZero bool `toml:"read_coils_starting_at_zero"`
|
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
|
// Modbus holds all data relevant to the plugin
|
||||||
type Modbus struct {
|
type Modbus struct {
|
||||||
Name string `toml:"name"`
|
Name string `toml:"name"`
|
||||||
Controller string `toml:"controller"`
|
Controller string `toml:"controller"`
|
||||||
TransmissionMode string `toml:"transmission_mode"`
|
TransmissionMode string `toml:"transmission_mode"`
|
||||||
BaudRate int `toml:"baud_rate"`
|
BaudRate int `toml:"baud_rate"`
|
||||||
DataBits int `toml:"data_bits"`
|
DataBits int `toml:"data_bits"`
|
||||||
Parity string `toml:"parity"`
|
Parity string `toml:"parity"`
|
||||||
StopBits int `toml:"stop_bits"`
|
StopBits int `toml:"stop_bits"`
|
||||||
Timeout config.Duration `toml:"timeout"`
|
RS485 *RS485Config `toml:"rs485"`
|
||||||
Retries int `toml:"busy_retries"`
|
Timeout config.Duration `toml:"timeout"`
|
||||||
RetriesWaitTime config.Duration `toml:"busy_retries_wait"`
|
Retries int `toml:"busy_retries"`
|
||||||
DebugConnection bool `toml:"debug_connection"`
|
RetriesWaitTime config.Duration `toml:"busy_retries_wait"`
|
||||||
Workarounds ModbusWorkarounds `toml:"workarounds"`
|
DebugConnection bool `toml:"debug_connection"`
|
||||||
Log telegraf.Logger `toml:"-"`
|
Workarounds ModbusWorkarounds `toml:"workarounds"`
|
||||||
// Register configuration
|
ConfigurationType string `toml:"configuration_type"`
|
||||||
ConfigurationType string `toml:"configuration_type"`
|
Log telegraf.Logger `toml:"-"`
|
||||||
|
|
||||||
|
// Configuration type specific settings
|
||||||
ConfigurationOriginal
|
ConfigurationOriginal
|
||||||
ConfigurationPerRequest
|
ConfigurationPerRequest
|
||||||
|
|
||||||
|
|
@ -285,6 +296,14 @@ func (m *Modbus) initClient() error {
|
||||||
if m.DebugConnection {
|
if m.DebugConnection {
|
||||||
handler.Logger = m
|
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
|
m.handler = handler
|
||||||
case "ASCII":
|
case "ASCII":
|
||||||
handler := mb.NewASCIIClientHandler(path)
|
handler := mb.NewASCIIClientHandler(path)
|
||||||
|
|
@ -296,6 +315,14 @@ func (m *Modbus) initClient() error {
|
||||||
if m.DebugConnection {
|
if m.DebugConnection {
|
||||||
handler.Logger = m
|
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
|
m.handler = handler
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid transmission mode %q for %q", m.TransmissionMode, u.Scheme)
|
return fmt.Errorf("invalid transmission mode %q for %q", m.TransmissionMode, u.Scheme)
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
controller = "tcp://localhost:502"
|
controller = "tcp://localhost:502"
|
||||||
|
|
||||||
## Serial (RS485; RS232)
|
## Serial (RS485; RS232)
|
||||||
|
## For RS485 specific setting check the end of the configuration.
|
||||||
## For unix-like operating systems use:
|
## For unix-like operating systems use:
|
||||||
# controller = "file:///dev/ttyUSB0"
|
# controller = "file:///dev/ttyUSB0"
|
||||||
## For Windows operating systems use:
|
## For Windows operating systems use:
|
||||||
|
|
|
||||||
|
|
@ -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
|
## Enable workarounds required by some devices to work correctly
|
||||||
# [inputs.modbus.workarounds]
|
# [inputs.modbus.workarounds]
|
||||||
## Pause after connect delays the first request by the specified time.
|
## Pause after connect delays the first request by the specified time.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue