{"id":24641049,"url":"https://github.com/etactica/lua-libmodbus","last_synced_at":"2025-05-12T14:59:03.235Z","repository":{"id":65612861,"uuid":"57212785","full_name":"etactica/lua-libmodbus","owner":"etactica","description":"lua bindings to libmodbus","archived":false,"fork":false,"pushed_at":"2022-12-02T11:53:39.000Z","size":99,"stargazers_count":33,"open_issues_count":1,"forks_count":27,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-31T23:35:57.709Z","etag":null,"topics":["libmodbus","lua","lua-bindings","lua-libmodbus","modbus"],"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/etactica.png","metadata":{"files":{"readme":"README.md","changelog":"changelog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-27T12:47:03.000Z","updated_at":"2024-11-11T02:02:44.000Z","dependencies_parsed_at":"2023-01-31T19:15:16.611Z","dependency_job_id":null,"html_url":"https://github.com/etactica/lua-libmodbus","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etactica%2Flua-libmodbus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etactica%2Flua-libmodbus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etactica%2Flua-libmodbus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etactica%2Flua-libmodbus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/etactica","download_url":"https://codeload.github.com/etactica/lua-libmodbus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253761013,"owners_count":21960052,"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":["libmodbus","lua","lua-bindings","lua-libmodbus","modbus"],"created_at":"2025-01-25T12:12:06.084Z","updated_at":"2025-05-12T14:59:03.202Z","avatar_url":"https://github.com/etactica.png","language":"C","readme":"lua-libmodbus\n=============\n\nLua bindings to [libmodbus](http://www.libmodbus.org/)\n\nParameters are mostly as per libmodbus documentation, but values are returned\ndirectly, in tables, rather than in pointers and return codes.  Instead of\na return code, you would get a lua style \"nil, error_msg\" return pair.\n\nOf particular relevance to modbus, is that tables are addressed with lua\nstyle 1 based counting, but converted to zero based internally.  ie:\n\n```\n\tres = dev:read_registers(0x2000, 2)\n\tprint(#res) -- prints 2\n\tprint(res[1]) - prints register address 0x2000, _not_ 0x2001\n```\n\n[API documentation](http://etactica.github.io/lua-libmodbus/) (Generated from last release)\n\nStatus\n------\n\n* Client bindings for RTU/TCP and almost all operations.\n* Some helpers for working with 16/32bit signed/unsigned and floats in multiple registers\n  (API is not necessarily nailed down, comments welcome)\n* Server side limited to receive and reply exception.\n  Needs thoughts on how to handle the mapping objects.\n* Compatible with both 3.0.x and 3.1.x but you must run with the version you compiled with.\n\nCompile\n-------\nYou need Lua and libmodbus development packages (headers and libs) to\nbuild lua-libmodbus.\n\nCompile with\n\n    make\n\nYou can override the pkg-config package name to set a specific Lua version.\nFor example:\n\n    make LUAPKG=lua-5.1\n\nExample usage\n-------------\n\nSee demo.lua and other sample files.\n\nHere is a simple example printing out 10 registers at 0x2000,\nthen writing 5 registers back to that address\n\n```Lua\nmb = require(\"libmodbus\")\nlocal dev = mb.new_tcp_pi(\"192.168.255.74\", 1502)\nlocal base_address = 0x2000\ndev:connect()\nlocal regs, err = dev:read_registers(base_address, 10)\nif not regs then error(\"read failed: \" .. err) end\nfor r,v in ipairs(regs) do\n        print(string.format(\"register (offset %d) %d: %d (%#x): %#x (%d)\",\n                r, r, r + base_address - 1, r + base_address -1, v, v))\nend\n```\n\nAnother example writing registers instead\n\n```Lua\nmb = require(\"libmodbus\")\nlocal dev = mb.new_tcp_pi(\"192.168.255.74\", 1502)\ndev:connect()\n\n-- will autoround 32.98 to 32.  no magic support for writing floats yet :|\n-- numbers are cast to uint16_t internally.\nlocal res, err = dev:write_registers(0x2000, { 0xabcd, 32.98, 0xfffe, 0xabcd, -1 })\nif not res then print(err) end\n```\n\n\nTesting\n-------\nSome spec files for use with busted are provided.  Some of them expect to have\nreal hardware to talk to, so you may wish to disable them.\n\n```\nbusted --exclude-tags=real\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fetactica%2Flua-libmodbus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fetactica%2Flua-libmodbus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fetactica%2Flua-libmodbus/lists"}