{"id":25830874,"url":"https://github.com/lab5e/mtool","last_synced_at":"2026-06-11T11:31:08.065Z","repository":{"id":65594764,"uuid":"595241299","full_name":"lab5e/mtool","owner":"lab5e","description":"Modbus tool","archived":false,"fork":false,"pushed_at":"2023-02-24T14:22:10.000Z","size":8284,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-28T22:38:50.262Z","etag":null,"topics":["modbus","modbus-rtu","modbus-rtu-master","rs-485"],"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/lab5e.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2023-01-30T17:27:31.000Z","updated_at":"2023-07-04T14:30:37.000Z","dependencies_parsed_at":"2024-06-21T08:52:03.644Z","dependency_job_id":null,"html_url":"https://github.com/lab5e/mtool","commit_stats":{"total_commits":29,"total_committers":2,"mean_commits":14.5,"dds":0.03448275862068961,"last_synced_commit":"7339f5bac0a0d172ac54c98e18136429462c12e6"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/lab5e/mtool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab5e%2Fmtool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab5e%2Fmtool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab5e%2Fmtool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab5e%2Fmtool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lab5e","download_url":"https://codeload.github.com/lab5e/mtool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab5e%2Fmtool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34197393,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["modbus","modbus-rtu","modbus-rtu-master","rs-485"],"created_at":"2025-02-28T19:34:22.971Z","updated_at":"2026-06-11T11:31:08.047Z","avatar_url":"https://github.com/lab5e.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mtool - modbus tool\n\nThis is a command line tool for experimenting with modbus.  **Please note that this is a work in progress**.\n\n## Installing\n\nIf you have Go installed on your system you can fetch the latest version of this utility using:\n\n```shell\ngo install github.com/lab5e/mtool/cmd/mtool@latest\n```\n\n## Usage\n\nThe `mtool` utility has several subcommands. You can list these, and the global command line options, by runnig `mtool -h`.  \n\n```shell\n$ mtool -h\nUsage:\n  mtool [OPTIONS] \u003ccommand\u003e\n\nApplication Options:\n      --device=        serial device [$MTOOL_DEVICE]\n      --baud=          baud rate (default: 9600) [$MTOOL_BAUD]\n      --databits=      data bits (default: 8) [$MTOOL_DATABITS]\n      --parity=[N|E|O] parity (default: N) [$MTOOL_PARITY]\n      --stop=[1|2]     stop bits (default: 1) [$MTOOL_STOPBITS]\n      --id=            device id (default: 1) [$MTOOL_DEVICE_ID]\n      --timeout=       timeout (default: 5s)\n      --debug          enable debug output\n\nHelp Options:\n  -h, --help           Show this help message\n\nAvailable commands:\n  doc   print documentation\n  rc    read coils\n  rd    read discrete input\n  rh    read holding register\n  ri    read input register\n  scan  scan modbus for devices\n  wh    write holding register\n```\n\nNote that some of the command line options have default values (which the help `-h` option will list).  The idea is to cut down on the number of command line options you have to specify by hopefully providing sensible defaults.  For instance the modbus device ID defaults to 1 since a lot of devices have this ID right out of the box.\n\n### Environment variables\n\nFor the global (application) options we have provided environment variables which can make using `mtool` a bit more convenient.  For instance it may be preferable to at least set the `MTOOL_DEVICE` to the serial device you are speaking to so you don't have to clutter the command line by having to include this every time.  The `-h` help output will list the other command line parameters that have environment variables you can set.\n\n### Device id\n\nThe device ID (`-id`) is the (hopefully) unique device ID on the modbus loop.  Before hooking up your devices, please make sure that each device is given a unique ID and that you have noted these somewhere.  \n\n### Addresses\n\nNote that modbus addresses (specified by the `--addr` flag) are one-based while the protocol itself is zero-based.  This means that the documentation will give an address as 10, while what is expected by the device is 9.  `mtool` subtracts 1 from the address you give it before putting it on the wire.\n\n### Output base\n\nSometimes you may want the values returned expressed in some other base than base 10.  To do this you can specify the `--base` option with `2` (binary), `8` (octal), `10` (decimal) or `16` (hexadecimal) as the base.\n\n### Repeatedly reading values\n\nAll of the reading commands support the `--repeat` flag.  When this flag is not specified the read command will be executed only once.  If it is set to a value it will repeat the read operation every time unit specified.\n\nTime is expressed as a number followed by a unit.  Valid units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\".\n\nThis example reads holding register with address 1 every 500 milliseconds:\n\n```shell\n$ bin/mtool rh --addr 1 --repeat 500ms\n2023-02-01T13:17:06Z [holding_register] deviceID=1 addr=1 count=1 data={230}\n2023-02-01T13:17:07Z [holding_register] deviceID=1 addr=1 count=1 data={230}\n2023-02-01T13:17:08Z [holding_register] deviceID=1 addr=1 count=1 data={230}\n2023-02-01T13:17:08Z [holding_register] deviceID=1 addr=1 count=1 data={230}\n```\n\n### Debug output\n\nIf you want to see the messages that are sent and received on the bus, you can add the `--debug` flag.  This will print out messages prefixed with `modbus:` showing the bytes that are being transmitted and received. *The debug output is not affected by the `--base` option*.\n\n## Subcommands\n\nThe mtool command itself does nothing.  To make it do things you have to specify *subcommands*. The following sections specify the subcommands.  In order to list the options available to each subcommand you should use the built-in help for each subcommand.  You can do this by issuing a command of the form\n\n```shell\nmtool \u003csubcommand\u003e -h\n```\n\n### `scan` -scan bus for devices\n\nScan the bus for devices by trying to read data from it.  Per default it will try to read holding register 1.  You can change what to read by setting the `--type` command line option to one of `holding`, `discrete`, `input` or `coil`.  You can change the address used for scanning by setting the `--addr` command line option.\n\nDepending on the devices you may have to configure how long the scanning process should wait for response from each device.  This can be done with the `--scan-timeout` option.  The default timeout is 100ms.  If you don't find any devices during a scan, try to increase the timeout value.\n\n### `rh` - read holding register\n\nRead the holding register identified by `--addr`.\n\nThis example reads holding register 1\n\n```shell\n$ mtool rh --addr 1\n2023-02-01T13:05:28Z [holding_register] deviceID=1 addr=1 count=1 data={230}\n```\n\n### `wh` - write holding register\n\nWrite holding register identified by `--addr`.\n\nThis example writes the `int16` value `230` to holding register 1\n\n```shell\n$ mtool wh --addr 1 --value 230\ndeviceID=1 addr=1 res={230}\n```\n\nYou can check that the value has indeed been changed by reading the holding register back using the `rh` subcommand.\n\n### `ri` - read input register\n\nRead input register identified by `--addr`.\n\nThis example reads input register 4:\n\n```shell\n$ mtool ri --addr 4\n2023-02-01T13:03:50Z [input_register] deviceID=1 addr=4 count=1 data={2574}\n```\n\n### `rd` - read discrete input\n\nRead discrete input identified by `--addr`.  Note that this is a bit field.\n\nThis example reads discrete input 4. Note that the output is in binary per default.  You can change the base with the `--base` command line option.\n\n```shell\n$ mtool rd --addr 1 \n2023-02-01T13:06:48Z [discrete_input] deviceID=1 addr=1 count=1 data={11111011, 0000000000011101}\n```\n\n### `rc` - read coils\n\nRead coils identified by `-addr`.  Note that this is a bit field.  You can change the output base with the `--base` command line flag.\n\n### `doc` - output this documentation\n\nFor convenience sake this README.md file is included in the binary.  You can spit it out as original markup or as HTML.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flab5e%2Fmtool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flab5e%2Fmtool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flab5e%2Fmtool/lists"}