!!! node-snap7 is still a work in progress !!!
This is a node.js wrapper for snap7. Snap7 is an open source, 32/64 bit, multi-platform Ethernet communication suite for interfacing natively with Siemens S7 PLCs (See compatibility).
Install with:
npm install node-snap7
Requirements:
- Windows:
- Visual Studio 2010 Express or higher e.g Visual Studio 2013 Express
- Python 2.7
- Linux:
- gcc & make
- Python 2.7
- Davide Nardella for creating snap7
var snap7 = require('node-snap7');
var s7client = new snap7.S7Client();
s7client.ConnectTo('127.0.0.1', 0, 1, function(err) {
if(err)
return console.log(' >> Connection failed. Code #' + err + ' - ' + s7client.ErrorText(err));
// Read the first byte from PLC process outputs...
s7client.ABRead(0, 1, function(err, res) {
if(err)
return console.log(' >> ABRead failed. Code #' + err + ' - ' + s7client.ErrorText(err));
// ... and write it to stdout
console.log(res)
});
});
- Control functions
- Data I/O functions
- Directory function
- Block oriented functions
- Date/Time functions
- System info functions
- PLC control functions
- Security functions
- Properties
Connects the client to the PLC with the parameters specified in the previous call of ConnectTo()
or SetConnectionParams()
.
- The optional
callback
parameter will be executed after connection attempt
If callback
is not set the function returns true
on success or false
on error.
If callback
is set an error
argument is given to the callback
Connects the client to the hardware at (IP
, Rack
, Slot
) Coordinates.
ip
PLC/Equipment IPV4 Address ex. “192.168.1.12”rack
PLC Rack numberslot
PLC Slot number- The optional
callback
parameter will be executed after connection attempt
If callback
is not set the function returns true
on success or false
on error.
If callback
is set an error
argument is given to the callback
Sets internally (IP, LocalTSAP, RemoteTSAP) Coordinates.
ipP
PLC/Equipment IPV4 Address ex. “192.168.1.12”localTSAP
Local TSAP (PC TSAP)remoteTSAP
Remote TSAP (PLC TSAP)
Returns true
on success or false
on error.
Disconnects “gracefully” the Client from the PLC.
Returns true
on success or false
on error.
Reads an internal Client object parameter.
paramNumber
One from the parameter list below
Name | Value | Description |
---|---|---|
S7Client.RemotePort |
2 | Socket remote Port. |
S7Client.PingTimeout |
3 | Client Ping timeout. |
S7Client.SendTimeout |
4 | Socket Send timeout. |
S7Client.RecvTimeout |
5 | Socket Recv timeout. |
S7Client.SrcRef |
7 | ISOTcp Source reference. |
S7Client.DstRef |
8 | ISOTcp Destination reference |
S7Client.SrcTSap |
9 | ISOTcp Source TSAP. |
S7Client.PDURequest |
10 | Initial PDU length request. |
Returns the parameter value
on success or false
on error.
Sets an internal Client object parameter.
paramNumber
One from the parameter list abovevalue
New parameter value
Returns true
on success or false
on error.
This is the main function to read data from a PLC. With it you can read DB, Inputs, Outputs, Merkers, Timers and Counters.
area
dbNumber
start
amount
wordLen
callback
This is the main function to write data into a PLC.
area
dbNumber
start
amount
wordLen
buffer
callback
This is a lean function of ReadArea()
to read PLC DB.
It simply internally calls ReadArea()
with area = S7Client.S7AreaDB
and wordLen = s7client.S7WLByte
.
dbNumber
start
size
callback
This is a lean function of WriteArea()
to write PLC DB.
It simply internally calls WriteArea()
with area = S7Client.S7AreaDB
and wordLen = s7client.S7WLByte
.
dbNumber
start
size
buffer
callback
This is a lean function of ReadArea()
to read PLC process outputs.
It simply internally calls ReadArea()
with area = S7Client.S7AreaPA
and wordLen = s7client.S7WLByte
.
start
size
callback
This is a lean function of WriteArea()
to write PLC process outputs.
It simply internally calls WriteArea()
with area = S7Client.S7AreaPA
and wordLen = s7client.S7WLByte
.
start
size
buffer
callback
This is a lean function of ReadArea()
to read PLC process inputs.
It simply internally calls ReadArea()
with area = S7Client.S7AreaPE
and wordLen = s7client.S7WLByte
.
start
size
callback
This is a lean function of WriteArea()
to write PLC process inputs.
It simply internally calls WriteArea()
with area = S7Client.S7AreaPE
and wordLen = s7client.S7WLByte
.
start
size
buffer
callback
This is a lean function of ReadArea()
to read PLC Merkers.
It simply internally calls ReadArea()
with area = S7Client.S7AreaMK
and wordLen = s7client.S7WLByte
.
start
size
callback
This is a lean function of WriteArea()
to write PLC Merkers.
It simply internally calls WriteArea()
with area = S7Client.S7AreaMK
and wordLen = s7client.S7WLByte
.
start
size
buffer
callback
This is a lean function of ReadArea()
to read PLC Timers.
It simply internally calls ReadArea()
with area = S7Client.S7AreaTM
and wordLen = S7Client.S7WLTimer
.
start
amount
callback
This is a lean function of WriteArea()
to write PLC Timers.
It simply internally calls WriteArea()
with area = S7Client.S7AreaTM
and wordLen = S7Client.S7WLTimer
.
start
amount
buffer
callback
This is a lean function of ReadArea()
to read PLC Counters.
It simply internally calls ReadArea()
with area = S7Client.S7AreaCT
and wordLen = S7Client.S7WLCounter
.
start
amount
callback
This is a lean function of WriteArea()
to write PLC Counters.
It simply internally calls WriteArea()
with area = S7Client.S7AreaCT
and wordLen = S7Client.S7WLCounter
.
start
amount
buffer
callback
This is function allows to read different kind of variables from a PLC in a single call. With it you can read DB, Inputs, Outputs, Merkers, Timers and Counters.
- ...
This is function allows to write different kind of variables into a PLC in a single call. With it you can write DB, Inputs, Outputs, Merkers, Timers and Counters.
- ...
This function returns the AG blocks amount divided by type.
This function returns the AG list of a specified block type.
blockType
Returns detailed information about an AG given block. This function is very useful if you need to read or write data in a DB which you do not know the size in advance (see MC7Size field)
blockType
blockNum
Returns detailed information about a block present in a user buffer. This function is usually used in conjunction with FullUpload()
.
An uploaded block saved to disk, could be loaded in a user buffer and checked with this function.
buffer
Uploads a block from AG. The whole block (including header and footer) is copied into the user buffer.
blockType
blockNum
callback
Uploads a block body from AG. Only the block body (but header and footer) is copied into the user buffer.
blockType
blockNum
callback
Downloads a block into AG. A whole block (including header and footer) must be available into the user buffer.
blockNum
buffer
callback
Deletes a block into AG.
!!! There is no undo function available. !!!
blockType
blockNum
callback
Uploads a DB from AG. This function is equivalent to Upload()
with BlockType = Block_DB
but it uses a different approach so it’s not subject to the security level set. Only data is uploaded.
dbNumber
callback
Fills a DB in AG with a given byte without the need of specifying its size.
dbNumber
fillChar
callback
Reads PLC date and time.
Sets the PLC date and time.
dateTime
Sets the PLC date and time in accord to the PC system Date/Time.
Reads a partial list of given ID and INDEX.
Reads the directory of the partial lists.
Gets CPU order code and version info.
Gets CPU module name, serial number and other info.
Gets CP (communication processor) info.
Puts the CPU in RUN mode performing an HOT START.
Puts the CPU in RUN mode performing a COLD START.
Puts the CPU in STOP mode.
Performs the Copy Ram to Rom action.
Performs the Memory compress action.
Send the password to the PLC to meet its security level.
Clears the password set for the current session (logout).
Gets the CPU protection level info.
Returns the last job execution time in milliseconds.
Returns the last job result.
Returns info about the PDU length.
Returns the CPU status (running/stopped).
Returns the connection status
Returns a textual explanation of a given error number.
errNum
Copyright (c) 2015, Mathias Küsel
node-snap7 is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
node-snap7 builds on the excellent work of the snap7 framework from Davide Nardella. Snap7 is issued under the GPL/LGPLv3 (see ./deps/snap7/gpl.txt ./deps/snap7/lgpl-3.0.txt
).