{"id":34188233,"url":"https://github.com/aldas/go-modbus-client","last_synced_at":"2026-03-09T23:35:29.982Z","repository":{"id":45322991,"uuid":"344937469","full_name":"aldas/go-modbus-client","owner":"aldas","description":"Modbus client (TCP/RTU) over TCP/Serial for Go","archived":false,"fork":false,"pushed_at":"2025-11-07T06:27:57.000Z","size":229,"stargazers_count":26,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-12-18T15:09:08.598Z","etag":null,"topics":["go","modbus","modbus-client","modbus-rtu","modbus-tcp","rtu"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aldas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-03-05T21:22:30.000Z","updated_at":"2025-11-07T06:27:59.000Z","dependencies_parsed_at":"2024-01-07T20:38:24.748Z","dependency_job_id":"82fcc8e8-b5c6-4c7e-a5fc-181d7f53e6c6","html_url":"https://github.com/aldas/go-modbus-client","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/aldas/go-modbus-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aldas%2Fgo-modbus-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aldas%2Fgo-modbus-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aldas%2Fgo-modbus-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aldas%2Fgo-modbus-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aldas","download_url":"https://codeload.github.com/aldas/go-modbus-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aldas%2Fgo-modbus-client/sbom","scorecard":{"id":178378,"data":{"date":"2025-08-11","repo":{"name":"github.com/aldas/go-modbus-client","commit":"8ec1b3d9be0aa39309e2243e2ba506f6f90441a6"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.8,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":10,"reason":"GitHub workflow tokens follow principle of least privilege","details":["Info: topLevel 'contents' permission set to 'read': .github/workflows/main.yml:13","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/29 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/aldas/go-modbus-client/main.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/aldas/go-modbus-client/main.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/aldas/go-modbus-client/main.yml/main?enable=pin","Warn: goCommand not pinned by hash: scripts/.githooks/pre-commit:5","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   0 out of   1 goCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 15 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-16T18:18:00.009Z","repository_id":45322991,"created_at":"2025-08-16T18:18:00.009Z","updated_at":"2025-08-16T18:18:00.009Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30316772,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T20:05:46.299Z","status":"ssl_error","status_checked_at":"2026-03-09T19:57:04.425Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","modbus","modbus-client","modbus-rtu","modbus-tcp","rtu"],"created_at":"2025-12-15T15:30:59.144Z","updated_at":"2026-03-09T23:35:29.958Z","avatar_url":"https://github.com/aldas.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Modbus TCP and RTU protocol client\n\n[![License](https://img.shields.io/github/license/aldas/go-modbus-client)](LICENSE)\n[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg)](https://pkg.go.dev/github.com/aldas/go-modbus-client)\n[![Go Report Card](https://goreportcard.com/badge/github.com/aldas/go-modbus-client)](https://goreportcard.com/report/github.com/aldas/go-modbus-client)\n[![Codecov](https://codecov.io/gh/aldas/go-modbus-client/branch/main/graph/badge.svg)](https://codecov.io/gh/aldas/go-modbus-client)\n\nModbus client (TCP/RTU) over TCP/UDP/Serial for Golang.\n\n* Modbus TCP/IP specification: http://www.modbus.org/specs.php\n* Modbus TCP/IP and RTU simpler description: http://www.simplymodbus.ca/TCP.htm\n\nFor questions use Github [Discussions](https://github.com/aldas/go-modbus-client/discussions)\n\n## Installation\n\n```bash\ngo get github.com/aldas/go-modbus-client\n```\n\n## Supported functions\n\n* FC1 - Read Coils ([req](packet/readcoilsrequest.go)/[resp](packet/readcoilsresponse.go))\n* FC2 - Read Discrete Inputs ([req](packet/readdiscreteinputsrequest.go)/[resp](packet/readdiscreteinputsresponse.go))\n* FC3 - Read Holding Registers ([req](packet/readholdingregistersrequest.go)/[resp](packet/readholdingregistersresponse.go))\n* FC4 - Read Input Registers ([req](packet/readinputregistersrequest.go)/[resp](packet/readinputregistersresponse.go))\n* FC5 - Write Single Coil ([req](packet/writesinglecoilrequest.go)/[resp](packet/writesinglecoilresponse.go))\n* FC6 - Write Single Register ([req](packet/writesingleregisterrequest.go)/[resp](packet/writesingleregisterresponse.go))\n* FC15 - Write Multiple Coils ([req](packet/writemultiplecoilsrequest.go)/[resp](packet/writemultiplecoilsresponse.go))\n* FC16 - Write Multiple Registers ([req](packet/writemultipleregistersrequest.go)/[resp](packet/writemultipleregistersresponse.go))\n* FC17 - Read Server ID ([req](packet/readserveridrequest.go)/[resp](packet/readserveridresponse.go))\n* FC23 - Read / Write Multiple Registers ([req](packet/readwritemultipleregistersrequest.go)/[resp](packet/readwritemultipleregistersresponse.go))\n\n## Goals\n\n* Packets separate from Client implementation\n* Client (TCP/UDP +RTU) separated from Modbus packets\n* Convenience methods to convert register data to/from different data types (with endianess/word order)\n* Builders to group multiple fields into request batches\n* Poller to request batches request and parse response to field values with long-running process.\n\n## Examples\n\nHigher level API allows you to compose register requests out of arbitrary number of fields and extract those\nfield values from response registers with convenience methods\n\nAddresses without scheme (i.e. `localhost:5020`) are considered as TCP addresses. For UDP unicast use `udp://localhost:5020`.\n\n```go\nb := modbus.NewRequestBuilder(\"tcp://localhost:5020\", 1)\n\nrequests, _ := b.\n    AddField(modbus.Field{Name: \"test_do\", Type: modbus.FieldTypeUint16, Address: 18}).\n    AddField(modbus.Field{Name: \"alarm_do_1\", Type: modbus.FieldTypeInt64, Address: 19}).\n    ReadHoldingRegistersTCP() // split added fields into multiple requests with suitable quantity size\n\nclient := modbus.NewTCPClient()\nif err := client.Connect(context.Background(), \"tcp://localhost:5020\"); err != nil {\n    return err\n}\nfor _, req := range requests {\n    resp, err := client.Do(context.Background(), req)\n    if err != nil {\n        return err\n    }\n    // extract response as packet.Registers instance to have access to convenience methods to \n    // extracting registers as different data types\n    registers, _ := resp.(*packet.ReadHoldingRegistersResponseTCP).AsRegisters(req.StartAddress)\n    alarmDo1, _ := registers.Int64(19)\n    fmt.Printf(\"int64 @ address 19: %v\", alarmDo1)\n    \n    // or extract values to FieldValue struct\n    fields, _ := req.ExtractFields(resp, true)\n    assert.Equal(t, uint16(1), fields[0].Value)\n    assert.Equal(t, \"alarm_do_1\", fields[1].Field.Name)\n}\n```\n\n### Polling values with long-running process\n\nSee simple poller implementation [cmd/modbus-poller/main.go](cmd/modbus-poller/main.go).\n\n```go\nfunc main() {\n\tctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)\n\tdefer cancel()\n\n\tb := modbus.NewRequestBuilderWithConfig(modbus.BuilderDefaults{\n\t\tServerAddress: \"tcp://127.0.0.1:5022?invalid_addr=1000,12000-12100\u0026read_timeout=2s\",\n\t\tFunctionCode:  packet.FunctionReadHoldingRegisters, // fc3\n\t\tUnitID:        1,\n\t\tProtocol:      modbus.ProtocolTCP,\n\t\tInterval:      modbus.Duration(1 * time.Second), // send request every 1 second\n\t})\n\n\tbatches, _ := b.\n\t\tAddField(modbus.Field{Name: \"test_do\", Type: modbus.FieldTypeUint16, Address: 18}).\n\t\tAddField(modbus.Field{Name: \"alarm_do_1\", Type: modbus.FieldTypeInt64, Address: 19}).\n\t\tSplit() // split added fields into multiple requests with suitable quantity size\n\n\tp := poller.NewPoller(batches)\n\n\tgo func() {\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase result := \u003c-p.ResultChan:\n\t\t\t\tslog.Info(\"polled values\", \"values\", result)\n\t\t\tcase \u003c-ctx.Done():\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}()\n\n\tif err := p.Poll(ctx); err != nil {\n\t\tslog.Error(\"polling ended with failure\", \"err\", err)\n\t\treturn\n\t}\n}\n```\n\n### RTU over serial port\n\nRTU examples to interact with serial port can be found from [serial.md](serial.md)\n\nAddresses without scheme (i.e. `localhost:5020`) are considered as TCP addresses. For UDP unicast use `udp://localhost:5020`.\n\n### Low level packets\n\n```go\nclient := modbus.NewTCPClientWithConfig(modbus.ClientConfig{\n    WriteTimeout: 2 * time.Second,\n    ReadTimeout:  2 * time.Second,\n})\nif err := client.Connect(context.Background(), \"localhost:5020\"); err != nil {\n    return err\n}\ndefer client.Close()\nstartAddress := uint16(10)\nreq, err := packet.NewReadHoldingRegistersRequestTCP(0, startAddress, 9)\nif err != nil {\n    return err\n}\n\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\ndefer cancel()\nresp, err := client.Do(ctx, req)\nif err != nil {\n    return err\n}\n\nregisters, err := resp.(*packet.ReadHoldingRegistersResponseTCP).AsRegisters(startAddress)\nif err != nil {\n    return err\n}\nuint32Var, err := registers.Uint32(17) // extract uint32 value from register 17\n```\n\nTo create single TCP packet use following methods. Use `RTU` suffix to create RTU packets.\n\n```go\nimport \"github.com/aldas/go-modbus-client/packet\"\n\nreq, err := packet.NewReadCoilsRequestTCP(0, 10, 9)\nreq, err := packet.NewReadDiscreteInputsRequestTCP(0, 10, 9)\nreq, err := packet.NewReadHoldingRegistersRequestTCP(0, 10, 9)\nreq, err := packet.NewReadInputRegistersRequestTCP(0, 10, 9)\nreq, err := packet.NewWriteSingleCoilRequestTCP(0, 10, true)\nreq, err := packet.NewWriteSingleRegisterRequestTCP(0, 10, []byte{0xCA, 0xFE})\nreq, err := packet.NewWriteMultipleCoilsRequestTCP(0, 10, []bool{true, false, true})\nreq, err := packet.NewReadServerIDRequestTCP(0)\nreq, err := packet.NewWriteMultipleRegistersRequestTCP(0, 10, []byte{0xCA, 0xFE, 0xBA, 0xBE})\n```\n\n### Builder to group fields to packets\n\n```go\nb := modbus.NewRequestBuilder(\"localhost:5020\", 1)\n\nrequests, _ := b.\n   AddField(modbus.Field{Name: \"test_do\", Type: modbus.FieldTypeUint16, Address: 18}).\n   AddField(modbus.Field{Name: \"alarm_do_1\", Type: modbus.FieldTypeInt64, Address: 19}).\n   ReadHoldingRegistersTCP() // split added fields into multiple requests with suitable quantity size\n```\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md)\n\n## Tests\n\n```bash\nmake check\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faldas%2Fgo-modbus-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faldas%2Fgo-modbus-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faldas%2Fgo-modbus-client/lists"}