{"id":15639279,"url":"https://github.com/tootallnate/node-modbus-stack","last_synced_at":"2025-06-27T22:05:29.826Z","repository":{"id":1200048,"uuid":"1107903","full_name":"TooTallNate/node-modbus-stack","owner":"TooTallNate","description":"A `StreamStack` implementation of the MODBUS protocol, for NodeJS.","archived":false,"fork":false,"pushed_at":"2012-10-05T14:53:49.000Z","size":181,"stargazers_count":88,"open_issues_count":5,"forks_count":37,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-27T22:03:56.565Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/TooTallNate.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}},"created_at":"2010-11-24T02:45:30.000Z","updated_at":"2024-09-17T03:39:18.000Z","dependencies_parsed_at":"2022-08-16T12:35:06.620Z","dependency_job_id":null,"html_url":"https://github.com/TooTallNate/node-modbus-stack","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/TooTallNate/node-modbus-stack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TooTallNate%2Fnode-modbus-stack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TooTallNate%2Fnode-modbus-stack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TooTallNate%2Fnode-modbus-stack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TooTallNate%2Fnode-modbus-stack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TooTallNate","download_url":"https://codeload.github.com/TooTallNate/node-modbus-stack/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TooTallNate%2Fnode-modbus-stack/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262341622,"owners_count":23296069,"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":[],"created_at":"2024-10-03T11:25:15.946Z","updated_at":"2025-06-27T22:05:29.806Z","avatar_url":"https://github.com/TooTallNate.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"node-modbus-stack\n=================\n### A [StreamStack][] implementation of the [MODBUS][Modbus] protocol for [Node][].\n\nThis module exposes two concrete `StreamStack` implementations:\n`ModbusRequestStack` can be used as a MODBUS client (i.e. Master), and can write\nMODBUS compliant requests and listen for the response.\n`ModbusResponseStack` can be used to create a MODBUS server (i.e. Slave), by\nlistening for requests and providing a convenient API to respond with.\n\n[MODBUS][ModbusWiki] is an open building automation protocol that is widely used\nin various monitoring and controlling equipment. It's used with a variety of\ndifferent transports, including TCP.\n\nCurrently only communication through the TCP protocol is supported, however\nRS-485 serial support should be possible with [node-serialport]. I haven't\nhad a chance to look into it yet.\n\n\nA MODBUS Master (Client)\n------------------------\n\nYou will need to know which _Function Code_ (defined in the MODBUS specification)\nyou are invoking on the remote MODBUS slave. In this example, we'll request to\nread from the current values of the first 50 __Input Registers__ on the slave:\n\n    // 'RIR' contains the \"Function Code\" that we are going to invoke on the remote device\n    var RIR = require('modbus-stack').FUNCTION_CODES.READ_INPUT_REGISTERS;\n    \n    // IP and port of the MODBUS slave, default port is 502\n    var client = require('modbus-stack/client').createClient(502, '10.0.1.50');\n    \n    // 'req' is an instance of the low-level `ModbusRequestStack` class\n    var req = client.request(RIR, // Function Code: 4\n                             0,    // Start at address 0\n                             50);  // Read 50 contiguous registers from 0\n    \n    // 'response' is emitted after the entire contents of the response has been received.\n    req.on('response', function(registers) {\n      // An Array of length 50 filled with Numbers of the current registers.\n      console.log(registers);\n      client.end();\n    });\n\n\nA MODBUS Slave (Server)\n-----------------------\n\n`node-modbus-stack` makes it dead simple to create a compliant MODBUS Slave (or Server)\nwritten in pure JavaScript. Here's an example of a server that would respond to the\nrequest above:\n\n    var FC = require('modbus-stack').FUNCTION_CODES;\n    \n    // 'handlers' is an Object with keys containing the \"Function Codes\" that your MODBUS\n    // server will handle. Anything function code requested without a handler defined here\n    // will have the Server transparently respond with Exception Code 1 (\"Illegal Function\")\n    var handlers = {};\n    \n    // Define a handler for \"Read Input Registers\". We'll just respond with the register\n    // number requested. In a real-world situation, you'd probably look up these values from\n    // a database, etc.\n    handlers[FC.READ_INPUT_REGISTERS] = function(request, response) {\n      var start = request.startAddress;\n      var length = request.quantity;\n      \n      var resp = new Array(length);\n      for (var i=0; i\u003clength; i++) {\n        resp[i] = start + i;\n      }\n      response.writeResponse(resp);\n    }\n\n    require('modbus-stack/server').createServer(handlers).listen(502);\n\nA \"catch-all\" function can be passed to `createServer()` instead of a \"handlers\" object, if you'd\nrather have a single callback invoked for _all_ MODBUS requests. Just be sure to call\n`writeException()` manually for any \"Function Codes\" your server isn't going to handle.\n\n\n[StreamStack]: http://github.com/TooTallNate/node-stream-stack\n[node-serialport]: https://github.com/voodootikigod/node-serialport\n[ModbusWiki]: http://en.wikipedia.org/wiki/Modbus\n[Modbus]: http://www.modbus.org\n[Node]: http://nodejs.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftootallnate%2Fnode-modbus-stack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftootallnate%2Fnode-modbus-stack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftootallnate%2Fnode-modbus-stack/lists"}