Skip to content

Commit 596bf3d

Browse files
committed
Initial commit
0 parents  commit 596bf3d

17 files changed

+2633
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.vscode
2+
node_modules
3+
deps
4+
build
5+
prebuilds

.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.gitignore
2+
.npmignore
3+
.vscode
4+
.travis.yml
5+
appveyor.yml
6+
node_modules

.travis.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- node
5+
addons:
6+
apt:
7+
sources:
8+
- ubuntu-toolchain-r-test
9+
packages:
10+
- g++-4.8
11+
- gcc-4.8-multilib
12+
- g++-4.8-multilib
13+
- gcc-multilib
14+
- g++-multilib
15+
os:
16+
- osx
17+
- linux
18+
before_deploy:
19+
- ARCHIVE_NAME="${TRAVIS_TAG:-latest}-$TRAVIS_OS_NAME-`uname -m`.tar"
20+
- npm run prebuild
21+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ARCH=ia32 npm run prebuild; fi
22+
- tar --create --verbose --file="$ARCHIVE_NAME" --directory "$TRAVIS_BUILD_DIR/prebuilds"
23+
.
24+
deploy:
25+
provider: releases
26+
draft: false
27+
prerelease: true
28+
file: "$ARCHIVE_NAME"
29+
skip_cleanup: true
30+
on:
31+
tags: true
32+
node: node
33+
api_key:
34+
secure: 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

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 Fabio Riva
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# napi-snap7
2+
3+
[![Build status](https://ci.appveyor.com/api/projects/status/github/fabioriva/napi-snap7?svg=true)](https://ci.appveyor.com/project/fabioriva/napi-snap7/branch/master)
4+
5+
Asyncronous, non-blocking [Snap7](http://snap7.sourceforge.net) bindings for Node.js
6+
7+
```
8+
npm install napi-snap7
9+
```
10+
11+
## About Snap7
12+
13+
Snap7 is an open source, 32/64 bit, multi-platform Ethernet communication suite for interfacing natively with **Siemens S7 PLCs** (See [compatibility](http://snap7.sourceforge.net/snap7_client.html#target_compatibility)).
14+
15+
## Motivation
16+
17+
I have been using the [node-snap7](https://github.com/mathiask88/node-snap7) module since the first releases.
18+
So this writing was inspired by the great work done previously by the author of the node-snap7 module.
19+
As a member of the open source community I decided to contribute writing my own addon using the modern [node-addon-api](https://github.com/nodejs/node-addon-api) module.
20+
node-addon-api is based on [Node-API](https://nodejs.org/api/n-api.html) and supports using different Node-API versions.
21+
22+
## Features
23+
24+
All the I/O functions in the module have synchronous, callback, and promise-based forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).
25+
26+
Prebuilt binaries shipped with [prebuildify](https://github.com/prebuild/prebuildify).
27+
28+
## Acknowledgements
29+
30+
Davide Nardella for creating Snap7 and Mathias Küsel for creating node-snap7
31+
32+
## License
33+
34+
MIT

appveyor.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
build: false
2+
3+
skip_branch_with_pr: true
4+
5+
environment:
6+
matrix:
7+
- nodejs_version: "Current"
8+
9+
configuration: Release
10+
platform:
11+
- x86
12+
- x64
13+
14+
image:
15+
- Ubuntu
16+
- Visual Studio 2015
17+
18+
install:
19+
- npm install
20+
21+
test_script:
22+
- node --version
23+
- npm --version
24+
- npm test
25+
26+
deploy:
27+
release: napi-snap7-v$(APPVEYOR_BUILD_VERSION)
28+
description: 'Release description'
29+
provider: GitHub
30+
artifact: /.*\.zip/
31+
auth_token:
32+
secure: Pb1VVfUoXOiHwF9pioEKnqB8gig3lZbtazZ/YiOeASnSTipWoI5xz78luZ8QOe98
33+
draft: false
34+
prerelease: false
35+
on:
36+
branch: master # release from master branch only
37+
APPVEYOR_REPO_TAG: false # deploy on tag push only
38+
39+
# after_test:
40+
# - ps: If ($env:nodejs_version -eq "Current") { npm run prebuild }
41+
42+
# artifacts:
43+
# - path: prebuilds
44+
# name: $(APPVEYOR_REPO_TAG_NAME)-win-$(PLATFORM)
45+
# type: zip
46+
47+
# deploy:
48+
# - provider: GitHub
49+
# artifact: /.*\.zip/
50+
# draft: false
51+
# prerelease: true
52+
# auth_token:
53+
# secure: v2.k1227ospkeaoh22pdotk
54+
# on:
55+
# appveyor_repo_tag: true
56+
# nodejs_version: "Current"

binding.gyp

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "snap7_client",
5+
"sources": [
6+
"src/addon.cc",
7+
"src/snap7_client.cpp",
8+
"src/snap7.cpp"
9+
],
10+
"include_dirs": [
11+
"<!@(node -p \"require('node-addon-api').include\")"
12+
],
13+
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")", "snap7"],
14+
"cflags!": [ "-fno-exceptions" ],
15+
"cflags_cc!": [ "-fno-exceptions" ],
16+
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS"],
17+
"conditions": [
18+
["OS=='win'", {
19+
"libraries": ["-lws2_32.lib", "-lwinmm.lib"],
20+
"defines": ["_WINSOCK_DEPRECATED_NO_WARNINGS", "_HAS_EXCEPTIONS=0"] # Make sure the STL doesn't try to use exceptions
21+
}]
22+
],
23+
},
24+
{
25+
"target_name": "snap7",
26+
"type": "static_library",
27+
"sources": [
28+
"./deps/snap7/src/sys/snap_msgsock.cpp",
29+
"./deps/snap7/src/sys/snap_sysutils.cpp",
30+
"./deps/snap7/src/sys/snap_tcpsrvr.cpp",
31+
"./deps/snap7/src/sys/snap_threads.cpp",
32+
"./deps/snap7/src/core/s7_client.cpp",
33+
"./deps/snap7/src/core/s7_isotcp.cpp",
34+
"./deps/snap7/src/core/s7_partner.cpp",
35+
"./deps/snap7/src/core/s7_peer.cpp",
36+
"./deps/snap7/src/core/s7_server.cpp",
37+
"./deps/snap7/src/core/s7_text.cpp",
38+
"./deps/snap7/src/core/s7_micro_client.cpp",
39+
"./deps/snap7/src/lib/snap7_libmain.cpp"
40+
],
41+
"include_dirs": [
42+
"./deps/snap7/src/sys",
43+
"./deps/snap7/src/core",
44+
"./deps/snap7/src/lib"
45+
],
46+
"cflags!": [ "-fno-exceptions" ],
47+
"cflags_cc!": ["-fno-exceptions"],
48+
"conditions": [
49+
["OS=='linux' or OS=='freebsd'", {
50+
"cflags_cc": ["-fPIC", "-pedantic", "-fexceptions"],
51+
"cflags_cc!": ["-fno-exceptions"]
52+
}],
53+
["OS=='win'", {
54+
"msvs_settings": {
55+
"VCCLCompilerTool": {
56+
"ExceptionHandling": 1,
57+
"AdditionalOptions": ["/EHsc"] # ExceptionHandling=1 is not enough for some versions
58+
}
59+
},
60+
"defines!": ["_HAS_EXCEPTIONS=0"],
61+
"defines": ["_WINSOCK_DEPRECATED_NO_WARNINGS"]
62+
}],
63+
["OS=='mac'", {
64+
"xcode_settings": {
65+
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
66+
"GCC_DYNAMIC_NO_PIC": "NO",
67+
"OTHER_CFLAGS": ["-pedantic"]
68+
}
69+
}]
70+
]
71+
}
72+
]
73+
}

examples/sync.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const snap7 = require('napi-snap7')
2+
3+
const client = new snap7.S7Client()
4+
5+
const time = (ms) => console.log('| Execution time : %d ms', ms)
6+
7+
const res = client.ConnectTo('192.168.20.55', 0, 1)
8+
console.log('ConnectTo', res)
9+
time(client.ExecTime())
10+
console.log('Connected', client.GetConnected())
11+
12+
const data = client.ReadAreaSync(0x84, 510, 0, 20, 0x04)
13+
console.log('Data', data)
14+
time(client.ExecTime())
15+
16+
client.Disconnect()

lib/binding.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const snap7 = require('node-gyp-build')(__dirname)
2+
3+
module.exports = snap7

package.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "napi-snap7",
3+
"version": "0.1.0",
4+
"description": "Node-API addon for Snap7 library",
5+
"keywords": [
6+
"Snap7",
7+
"S7",
8+
"Simatic",
9+
"PLC"
10+
],
11+
"main": "lib/binding.js",
12+
"dependencies": {
13+
"node-addon-api": "^4.3.0",
14+
"node-gyp-build": "^4.3.0"
15+
},
16+
"devDependencies": {
17+
"prebuildify": "^5.0.0"
18+
},
19+
"author": "Fabio Riva <f.riva@sotefin.ch>",
20+
"license": "MIT",
21+
"scripts": {
22+
"install": "node-gyp-build",
23+
"test": "echo \"Error: no test specified\"",
24+
"prebuild": "prebuildify --napi"
25+
},
26+
"repository": {
27+
"type": "git",
28+
"url": "https://github.com/fabioriva/napi-snap7.git"
29+
}
30+
}

src/addon.cc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <napi.h>
2+
#include "snap7_client.h"
3+
4+
Napi::Object InitAll(Napi::Env env, Napi::Object exports)
5+
{
6+
return S7Client::Init(env, exports);
7+
}
8+
9+
NODE_API_MODULE(addon, InitAll)

0 commit comments

Comments
 (0)