{"id":15653791,"url":"https://github.com/flosse/node-plc","last_synced_at":"2025-03-09T15:31:08.008Z","repository":{"id":11181365,"uuid":"13558957","full_name":"flosse/node-plc","owner":"flosse","description":"Node.js module to connect to PLCs","archived":true,"fork":false,"pushed_at":"2017-11-27T20:28:08.000Z","size":154,"stargazers_count":28,"open_issues_count":3,"forks_count":11,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-02T17:06:19.203Z","etag":null,"topics":["javascript","logo","nodejs","plc","siemens"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flosse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-14T11:01:52.000Z","updated_at":"2024-10-23T03:23:06.000Z","dependencies_parsed_at":"2022-08-30T21:01:34.956Z","dependency_job_id":null,"html_url":"https://github.com/flosse/node-plc","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flosse%2Fnode-plc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flosse%2Fnode-plc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flosse%2Fnode-plc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flosse%2Fnode-plc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flosse","download_url":"https://codeload.github.com/flosse/node-plc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242711268,"owners_count":20173297,"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":["javascript","logo","nodejs","plc","siemens"],"created_at":"2024-10-03T12:47:03.923Z","updated_at":"2025-03-09T15:31:07.653Z","avatar_url":"https://github.com/flosse.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-plc\n\nNode.js module to communicate with PLCs.\nAt the moment only the Siemens LOGO! PLC (`0BA7`and `0BA8`) is supported.\n\n[![Build Status](https://secure.travis-ci.org/flosse/node-plc.svg)](http://travis-ci.org/flosse/node-plc)\n[![Dependency Status](https://gemnasium.com/flosse/node-plc.svg)](https://gemnasium.com/flosse/node-plc)\n[![NPM version](https://badge.fury.io/js/plc.svg)](http://badge.fury.io/js/plc)\n\n## Usage\n\n```shell\nnpm install --save plc\n```\n\n```javascript\nvar plc = require(\"plc\");\n```\n\n### Logo class\n\n```javascript\n\nvar myLogo = new plc.Logo(\"192.168.0.1\", {\n  markers: 6,   // default is 8\n  inputs: 4,    // default is 8\n  timeout: 500  // socket timeout in milliseconds\n});\n\nmyLogo.on(\"error\", function(err){\n  console.error(err.message);\n});\n\nmyLogo.on(\"connect\", function(){\n\n  var result = myLogo.getInputs();\n  if (result instanceof Error){\n    return console.error(result.message);\n  }\n  console.log(result); // [true, false, false, true, false, true]\n\n  result = myLogo.getMarkers();\n  if (result instanceof Error){\n    return console.error(result.message);\n  }\n  console.log(result); // [true, false, true, true]\n\n  result = myLogo.setMarker(2);\n  if (result instanceof Error){\n    return console.error(result.message);\n  }\n\n  myLogo.disconnect();\n});\n\nmyLogo.connect();\n```\n\n### Simulation\n\n```javascript\nvar plc  = require(\"plc\");\n\nvar myVirtualLogo = new plc.Logo(\"192.168.0.1\", { simulate: true });\n\nmyLogo.on(\"connect\", function(){\n\n /**\n  * Since we cannot manipulate the inputs of a real PLCs\n  * there is no \"setInput\" method. But within the simulation\n  * mode we can use the special methods \"setSimulatedInput\"\n  * and \"clearSimulatedInput\".\n  */\n\n  myVirtualLogo.setSimulatedInput(2);\n  myLogo.getInput(2); // true\n  myVirtualLogo.clearSimulatedInput(2);\n  myLogo.getInput(2); // false\n\n /**\n  * Markers can be used as usual.\n  */\n\n  myVirtualLogo.setMarker(1);\n  myVirtualLogo.getMarker(1); // true\n  myVirtualLogo.clearMarker(1);\n  myVirtualLogo.getMarker(1); // false\n\n});\n\nmyVirtualLogo.connect();\n```\n\n### Comfort features\n\nThe LOGO! can be configured with state and action schemata.\nA states could be described like this:\n\n```javascript\nvar myStates = {\n  stateOne:   { input:  0 },\n  stateTwo:   { marker: 2 },\n  stateThree: { input:  2 }\n};\n```\n\nAn action consists of an array with defined desired states:\n\n```javascript\nvar actions = {\n  actionOne:\n    [\n      { type: 'clear', marker: 1 },\n      { type: 'set',   marker: 3 }\n    ],\n  actionTwo:\n    [ { type: 'set', marker: 2 } ],\n  actionThree:\n    [ { type: 'alias', actions: ['actionOne','actionTwo'] } ]\n};\n```\n\nThis is a full example:\n\n```javascript\nvar config = {\n  timeout:  500   // connection timeout\n  interval: 250   // read state interval\n  states: {\n    x:   { input:  0 },\n    y:   { input:  2 },\n    foo: { marker: 0 },\n    bar: { input:  1 }\n  actions: {\n    switchOne:\n      [\n        { type: 'set', marker: 3 }\n      ],\n    switchTwo:\n      [\n        { type: 'set',   marker:   1             },\n        { type: 'alias', switches: ['switchOne'] }\n      ]\n    }\n  }\n};\n\nvar dev1 = new Device(\"192.168.0.201\", config);\n\ndev1.on(\"connect\", function(){\n  console.log(\"Device 1 connected\");\n});\n\ndev1.on(\"timeout\", function(){\n  console.log(\"Device 1 connection timeout occoured\");\n});\n\ndev1.on(\"disconnect\", function(){\n  console.log(\"Device 1 disconnected\");\n});\n\ndev1.on(\"error\", function(err){\n  console.error(\"something went wrong: \", err.message);\n});\n\ndev.on('state-change', function(state){\n  console.log(state);\n  // { x: true, y: false, foo: true, bar: false }\n});\n\ndev1.connect();\ndev1.startWatching();\n\n// ...\n\ndev1.stopWatching();\ndev1.disconnect();\n```\n\n### API\n\n#### Constructor\n\n```javascript\nnew require(\"plc\").Logo(ipAddress, options);\n```\n\nFollowing options are available\n\n- `inputs` - number of used inputs\n- `markers` - number of used markers\n- `simulate` - simulation mode\n- `timeout` - the socket timeout\n\n#### Properties\n\n- `ip`\n- `isConnected`\n\n#### Methods\n\n- `connect()`\n- `disconnect()`\n- `setMarker(nr)`\n- `clearMarker(nr)`\n- `getMarker(nr)`\n- `getMarkers()`\n- `getInput(nr)`\n- `getInputs()`\n- `setSimulatedInput(nr)`\n- `clearSimulatedInput(nr)`\n- `getState()`\n- `setSimulatedState(stateName, value)`\n- `setVirtualState(stateName, value)`\n- `triggerAction(action)`\n- `startWatching`\n- `stopWatching`\n\n#### Events\n\n- `error`\n- `connect`\n- `disconnect`\n- `timeout`\n- `state`\n- `state-change`\n\n## Test\n\n```\nnpm test\n```\n\n## License\n\nThis project is licensed under the LGPL license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflosse%2Fnode-plc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflosse%2Fnode-plc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflosse%2Fnode-plc/lists"}