Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-2276: fix for same Item.Start but different Item.Bit access #108

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion s7comm_plugin/s7comm.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import (
"context"
"errors"
"fmt"
"reflect"
"regexp"
"strconv"
"time"
@@ -179,7 +180,7 @@ func ParseAddresses(addresses []string, batchMaxSize int) ([][]S7DataItemWithAdd
if i == j {
continue
}
if a.Item.Area == b.Item.Area && a.Item.DBNumber == b.Item.DBNumber && a.Item.Start == b.Item.Start {
if reflect.DeepEqual(a.Item, b.Item) {
return nil, fmt.Errorf("duplicate address %v", a)
}
}
51 changes: 51 additions & 0 deletions s7comm_plugin/s7comm_test.go
Original file line number Diff line number Diff line change
@@ -59,6 +59,57 @@ var _ = Describe("S7Comm Plugin Unittests", func() {
}
})
})

type S7Addresses struct {
addresses []string
expectedErrMsg []string
}

DescribeTable("Parsing duplicate Addresses", func(entries S7Addresses) {
batchMaxSize := 1

_, err := s7comm_plugin.ParseAddresses(entries.addresses, batchMaxSize)

if entries.expectedErrMsg != nil {
Expect(err).To(HaveOccurred())
for _, containedErrStr := range entries.expectedErrMsg {
Expect(err.Error()).To(ContainSubstring(containedErrStr))
}
return
}
Expect(err).NotTo(HaveOccurred())
},
Entry("same DBNumber but different Item.Start",
S7Addresses{
addresses: []string{"DB2.W0", "DB2.W2"},
expectedErrMsg: nil,
}),
Entry("same DBNumber but different Item.Bit",
S7Addresses{
addresses: []string{"DB2.X0.0", "DB2.X0.1"},
expectedErrMsg: nil,
}),
Entry("same Bit but different Item.DBNumber",
S7Addresses{
addresses: []string{"DB2.X0.0", "DB3.X0.0"},
expectedErrMsg: nil,
}),
Entry("same Area but different Item.Bit",
S7Addresses{
addresses: []string{"PE2.X0.0", "PE2.X0.1"},
expectedErrMsg: nil,
}),
Entry("same DBNumber and same Item.Area",
S7Addresses{
addresses: []string{"DB2.W0", "DB2.W2", "DB2.W0"},
expectedErrMsg: []string{"duplicate address", "DB2.W0"},
}),
Entry("same DBNumber and same Item.Bit",
S7Addresses{
addresses: []string{"DB2.X0.0", "DB2.W2", "DB2.X0.0"},
expectedErrMsg: []string{"duplicate address", "DB2.X0.0"},
}),
)
})

var _ = Describe("S7Comm Test Against Local PLC", func() {
Loading