Skip to content

Commit

Permalink
Handle default register type correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Rebhan committed Jul 23, 2021
1 parent 0e462ee commit 688c970
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions plugins/inputs/modbus/configuration_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ func (c *ConfigurationPerRequest) Check() error {

// Check register type
switch def.RegisterType {
case "", "coil", "discrete", "holding", "input":
case "":
def.RegisterType = "holding"
case "coil", "discrete", "holding", "input":
default:
return fmt.Errorf("unknown register-type %q", def.RegisterType)
}
Expand Down Expand Up @@ -186,6 +188,11 @@ func (c *ConfigurationPerRequest) Process() (map[byte]requestSet, error) {
result := map[byte]requestSet{}

for _, def := range c.Requests {
// Set default
if def.RegisterType == "" {
def.RegisterType = "holding"
}

// Construct the fields
isTyped := def.RegisterType == "holding" || def.RegisterType == "input"
fields, err := c.initFields(def.Fields, isTyped, def.ByteOrder)
Expand All @@ -211,7 +218,7 @@ func (c *ConfigurationPerRequest) Process() (map[byte]requestSet, error) {
case "discrete":
requests := newRequestsFromFields(fields, maxQuantityDiscreteInput)
set.discrete = append(set.discrete, requests...)
case "", "holding":
case "holding":
requests := newRequestsFromFields(fields, maxQuantityHoldingRegisters)
set.holding = append(set.holding, requests...)
case "input":
Expand Down

0 comments on commit 688c970

Please sign in to comment.