Skip to content

Commit

Permalink
Builder can handle FC1/FC2 request batching
Browse files Browse the repository at this point in the history
  • Loading branch information
aldas committed Oct 15, 2024
1 parent 9804df3 commit 8e32c40
Show file tree
Hide file tree
Showing 15 changed files with 886 additions and 305 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ permissions:

env:
# run coverage only with the latest Go version
LATEST_GO_VERSION: "1.22"
LATEST_GO_VERSION: "1.23"


jobs:
test:
strategy:
matrix:
go-version: [ "1.21", "1.22" ]
go-version: [ "1.22", "1.23" ]
platform: [ ubuntu-latest ]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.2] - unreleased
## [0.3.0] - unreleased

Breaking changes to following structs/methods/functions

* struct field `modbus.Field.RegisterAddress` was renamed to `Address`
* struct `modbus.RegisterRequest` was renamed to `BuilderRequest`
* method `BuilderRequest.ExtractFields()` signature changed

### Added

* Added FC1/FC2 support to builder. You can register coils with `b.Coild(address)` to be requested and extracted.
Builder has now following methods for splitting:
* `ReadCoilsTCP` combines fields into TCP Read Coils (FC1) requests
* `ReadCoilsRTU` combines fields into RTU Read Coils (FC1) requests
* `ReadDiscreteInputsTCP` combines fields into TCP Read Discrete Inputs (FC2) requests
* `ReadDiscreteInputsRTU` combines fields into RTU Read Discrete Inputs (FC2) requests


## [0.2.0] - unreleased

### Added

Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ check: lint vet race ## check project
init:
git config core.hooksPath ./scripts/.githooks
@go install golang.org/x/lint/golint@latest
@go install honnef.co/go/tools/cmd/staticcheck@latest

lint: ## Lint the files
@staticcheck ${PKG_LIST}
@golint -set_exit_status ${PKG_LIST}

vet: ## Vet the files
Expand All @@ -21,8 +23,8 @@ vet: ## Vet the files
test: ## Run unittests
@go test -short ${PKG_LIST}

goversion ?= "1.21"
test_version: ## Run tests inside Docker with given version (defaults to 1.21). Example: make test_version goversion=1.21
goversion ?= "1.23"
test_version: ## Run tests inside Docker with given version (defaults to 1.23). Example: make test_version goversion=1.23
@docker run --rm -it -v $(shell pwd):/project golang:$(goversion) /bin/sh -c "cd /project && make init check"

race: ## Run data race detector
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ for _, req := range requests {
fmt.Printf("int64 @ address 18: %v", alarmDo1)

// or extract values to FieldValue struct
fields, _ := req.ExtractFields(resp.(modbus.RegistersResponse), true)
fields, _ := req.ExtractFields(resp, true)
assert.Equal(t, uint16(1), fields[0].Value)
assert.Equal(t, "alarm_do_1", fields[1].Field.Name)
}
Expand Down
Loading

0 comments on commit 8e32c40

Please sign in to comment.