{"id":20808848,"url":"https://github.com/mazurel/modbus","last_synced_at":"2025-04-09T10:05:43.512Z","repository":{"id":175901334,"uuid":"248357513","full_name":"Mazurel/Modbus","owner":"Mazurel","description":"Modbus library for modern C++ ","archived":false,"fork":false,"pushed_at":"2024-11-16T14:47:59.000Z","size":1137,"stargazers_count":71,"open_issues_count":8,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T09:07:29.256Z","etag":null,"topics":["cpp","cpp17","modbus","modbus-library","object-oriented","raspberrypi"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mazurel.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":"2020-03-18T22:32:21.000Z","updated_at":"2025-03-25T08:19:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"1eed8779-9157-4a98-88ee-fc9743e0f7f3","html_url":"https://github.com/Mazurel/Modbus","commit_stats":null,"previous_names":["mazurel/modbus"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mazurel%2FModbus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mazurel%2FModbus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mazurel%2FModbus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mazurel%2FModbus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mazurel","download_url":"https://codeload.github.com/Mazurel/Modbus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248018060,"owners_count":21034048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cpp","cpp17","modbus","modbus-library","object-oriented","raspberrypi"],"created_at":"2024-11-17T19:56:24.527Z","updated_at":"2025-04-09T10:05:43.487Z","avatar_url":"https://github.com/Mazurel.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003eModbus library for modern C++\u003c/h1\u003e\n\n[![CMake on multiple platforms](https://github.com/Mazurel/Modbus/actions/workflows/cmake-multi-platform.yml/badge.svg?branch=master)](https://github.com/Mazurel/Modbus/actions/workflows/cmake-multi-platform.yml)\n[![Clang formatting checker](https://github.com/Mazurel/Modbus/actions/workflows/clang-format.yml/badge.svg?branch=master)](https://github.com/Mazurel/Modbus/actions/workflows/clang-format.yml)\n\n\nLibrary for high level Modbus frame/packet manipulation, including encoding and decoding, all written in modern C++17.\n\nAdditionally, library contains reference TCP and RTU implementation (on Linux only !),\nthat you can use as a starting point for you application !\nUntil there will some reliable way to test it, it will be treated as such.\n\n\u003cdetails\u003e\n\n\u003csummary\u003eMore informations for Windows users\u003c/summary\u003e\n\nIf you are interested in Windows RTU implementation, you can look at to pull request: https://github.com/Mazurel/Modbus/pull/5 .\nI am currently unable to merge it, as I do not have required hardware for testing.\n\n\u003c/details\u003e\n\n\n# Table of content\n- [Why](#why)\n- [Important Concept](#important-concept)\n- [Possibilities](#possibilities)\n- [Dependencies](#dependencies)\n- [Status](#status)\n- [Installation](#how-to-install-it-)\n- [Api](#api)\n\n# Why\n\nWhen I was working on my last project and tried to find a good C++ Modbus library (other than Qt) I was unable to find it.\nThat is why I have decided to share my own implementation of Modbus.\n\n# Important Concept\n\nThis library is **mainly** for providing Modbus logic.\nIt doesnt aim to have best communication implementation, as it is usually HW-specific.\nIt gives user ability to create Modbus frames using high level api and convert them to raw bytes or show them as string.\nThat is why *Modbus Core* is OS independent and can be easily used with other communication frameworks,\nassuming that you compiler supports at least C++17.\n\nModbus communiaction module is **enabled** by default and works pretty well on linux.\nIf you are using your own communication, be sure to disable it via cmake variable.\n\n# Possibilities\n\nQuick example of what Modbus Core can do:\n\nCode:\n\n```c++\n#include \"MB/modbusException.hpp\"\n#include \"MB/modbusRequest.hpp\"\n#include \"MB/modbusResponse.hpp\"\n\n// Create simple request\nMB::ModbusRequest request(1, MB::utils::ReadDiscreteOutputCoils, 100, 10);\n\nstd::cout \u003c\u003c \"Stringed Request: \" \u003c\u003c request.toString() \u003c\u003c std::endl;\n\nstd::cout \u003c\u003c \"Raw request:\" \u003c\u003c std::endl;\n\n// Get raw represenatation for request\nstd::vector\u003cuint8_t\u003e rawed = request.toRaw();\n\n// Method for showing byte\nauto showByte = [](const uint8_t \u0026byte) {\n    std::cout \u003c\u003c \" 0x\" \u003c\u003c std::hex \u003c\u003c std::setw(2) \u003c\u003c std::setfill('0')\n                \u003c\u003c static_cast\u003cint\u003e(byte);\n};\n\n// Show all bytes\nstd::for_each(rawed.begin(), rawed.end(), showByte);\nstd::cout \u003c\u003c std::endl;\n\n// Create CRC and pointer to its bytes\nuint16_t CRC = MB::utils::calculateCRC(rawed);\nauto CRCptr  = reinterpret_cast\u003cuint8_t *\u003e(\u0026CRC);\n\n// Show byted CRC for request\nstd::cout \u003c\u003c \"CRC for the above code: \";\nstd::for_each(CRCptr, CRCptr + 2, showByte);\nstd::cout \u003c\u003c std::endl;\n\nauto request1 = MB::ModbusRequest::fromRaw(rawed);\nstd::cout \u003c\u003c \"Stringed Request 1 after rawed: \" \u003c\u003c request1.toString() \u003c\u003c std::endl;\n\n// Add CRC to the end of raw request so that it can be loaded with CRC check\nrawed.insert(rawed.end(), CRCptr, CRCptr + 2);\nauto request2 = MB::ModbusRequest::fromRawCRC(rawed); // Throws on invalid CRC\nstd::cout \u003c\u003c \"Stringed Request 2 after rawed: \" \u003c\u003c request2.toString() \u003c\u003c std::endl;\n```\n\nOutput:\n```bash\nStringed Request: Read from output coils, from slave 1, starting from address 100, on 10 registers\nRaw request:\n 0x01 0x01 0x00 0x64 0x00 0x0a\nCRC for the above code:  0xfd 0xd2\nStringed Request 1 after rawed: Read from output coils, from slave 1, starting from address 100, on 10 registers\nStringed Request 2 after rawed: Read from output coils, from slave 1, starting from address 100, on 10 registers\n```\n\n# Dependencies\n\nLibrary core is dependency free - except for C++ standard library.\n\nFor communication module, you may need:\n\n- libnet - only for tcp communication (not needed if communication is disabled)\n\n# STATUS\n\nCurrently Modbus Core is fully functional and (I belive) it doesn't have any bugs.\n\nModbus Communication is working *currently* only for linux, it works well on TCP and Serial (tested on raspberry pi).\n\n# How to learn Modbus ?\n\nJust use [Simply modbus](http://www.simplymodbus.ca/FAQ.htm).\n\n# How to install it ?\n\n### Using CMAKE and git\n\nFirst go to directory that will contain this library.\n\n```bash\ngit clone https://github.com/Mazurel/Modbus\ngit submodule update --init --recursive # Fetch submodules (google tests)\n```\n\nThen add to your CMakeLists.txt\n```cmake\nadd_subdirectory(Modbus)\ntarget_link_libraries(\u003cyour exec/lib\u003e Modbus)\n```\nYou should be able to use library.\n\n**NOTE**\nIf you are on other os then gnu/linux you should disable communication part of modbus via cmake variable MODBUS_COMMUNICATION.\n\n# API\n\nAPI documentation is generated using [Doxygen](https://www.doxygen.nl) and it is available online under this [link](https://mazurel.github.io/docs/modbus/index.html).\nIf you want, you can also generate it yourself !\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazurel%2Fmodbus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmazurel%2Fmodbus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazurel%2Fmodbus/lists"}