Starts the server and binds it to the IP address specified in the previous call of StartTo(). If StartTo() was not previously called, 0.0.0.0 is assumed as IP address.
- The optional
callbackparameter will be executed after completion
If callback is not set the function is blocking and returns true on success or false on error.
If callback is set the function is non-blocking and an error argument is given to the callback.
Starts the server and binds it to the specified IP address and the IsoTCP port.
ipPLC/Equipment IPV4 Address ex. “192.168.1.12”- The optional
callbackparameter will be executed after completion
If callback is not set the function is blocking and returns the CPU status on success or false on error.
If callback is set the function is non-blocking and an error argument is given to the callback.
Stops the server, disconnects gracefully all clients, destroys al S7 workers and unbinds the listener socket from its address.
- The optional
callbackparameter will be executed after completion
If callback is not set the function is blocking and returns the CPU status on success or false on error.
If callback is set the function is non-blocking and an error argument is given to the callback.
Returns an internal server parameter.
paramNumberOne from the parameter list below
| Name | Value | Description |
|---|---|---|
S7Server.LocalPort |
1 | Socket local port |
S7Server.WorkInterval |
6 | Socket worker interval |
S7Server.PDURequest |
10 | Initial PDU length request |
S7Server.MaxClients |
11 | Max clients allowed |
Returns the parameter value on success or false on error.
Sets an internal server parameter.
paramNumberOne from the parameter list abovevalueNew parameter value
Returns true on success or false on error.
Sets the server to resourceless mode.
valuenew value
Returns true on success or false on error.
Registers a memory area in the server. That memory block will be visible by the clients.
areaCodeArea identifier (see table below)indexDB number ifareaCodeequalssrvAreaDB, otherwise ignoredbufferUser buffer
Returns true on success or false on error.
Unregisters a memory area in the server.
areaCodeArea identifier (see table below)indexDB number ifareaCodeequalssrvAreaDB, otherwise ignored
Returns true on success or false on error.
Gets the content of a previously registered memory area block.
areaCodeArea identifier (see table below)indexDB number ifareaCodeequalssrvAreaDB, otherwise ignored
Returns a buffer object.
Sets the content of a previously registered memory area block.
areaCodeArea identifier (see table below)indexDB number ifareaCodeequalssrvAreaDB, otherwise ignoredbufferBuffer object
Locks the memory area so that a server worker thread is blocked on access attempt until the lock is released with UnlockArea().
areaCodeArea identifier (see table below)indexDB number ifareaCodeequalssrvAreaDB, otherwise ignored
Unlocks a previously locked memory area.
areaCodeArea identifier (see table below)indexDB number ifareaCodeequalssrvAreaDB, otherwise ignored
| Area | Value | Description |
|---|---|---|
S7Server.srvAreaPE |
0 | Process inputs |
S7Server.srvAreaPA |
1 | Process outputs |
S7Server.srvAreaMK |
2 | Merkers |
S7Server.srvAreaCT |
3 | Counters |
S7Server.srvAreaTM |
4 | Timers |
S7Server.srvAreaDB |
5 | DB |
Emitted on server events.
eventEvent object
{
EvtTime; // <Date> Date
EvtSender; // <String> Sender
EvtCode; // <Number> Event code
EvtRetCode; // <Number> Event result
EvtParam1; // <Number> Param 1 (if available)
EvtParam2; // <Number> Param 2 (if available)
EvtParam3; // <Number> Param 3 (if available)
EvtParam4; // <Number> Param 4 (if available)
}Example:
var s7server = new snap7.S7Server();
s7server.on("event", function(event) {
console.log(s7server.EventText(event));
});
s7server.StartTo('127.0.0.1');Emitted on every read/write event. Only available in resourceless mode.
senderIPv4 address of the senderoperationOperation typetagObjTag objectbufferBuffer objectcallbackCallback function
The server worker thread is blocked until callback is called. Therefore calling is crucial, to prevent a deadlock in the worker thread.
On a read event the callback expects a buffer as argument that is provided to the client. You can use the buffer argument which is an empty buffer of the correct size.
| Operation type | Value | Description |
|---|---|---|
S7Server.operationRead |
0x00 | Read operation |
S7Server.operationWrite |
0x01 | Write operation |
{
Area; // <Number> Area code (DB, MK,…)
DBNumber; // <Number> DB number (if any or 0)
Start; // <Number> Offset start
Size; // <Number> Number of elements
WordLen; // <Number> Tag WordLength
}Example:
var s7server = new snap7.S7Server();
s7server.SetResourceless(true);
s7server.on("readWrite", function(sender, operation, tagObj, buffer, callback) {
console.log((operation === s7server.operationRead ? 'Read' : 'Write') + ' event from ' + sender);
console.log('Area : ' + tagObj.Area);
console.log('DBNumber : ' + tagObj.DBNumber);
console.log('Start : ' + tagObj.Start);
console.log('Size : ' + tagObj.Size);
console.log('WordLen : ' + tagObj.WordLen);
if (operation === s7server.operationRead) {
buffer.fill(255);
return callback(buffer);
} else {
console.log('Buffer : ' + buffer);
return callback();
}
});
s7server.StartTo('127.0.0.1');Returns the server event filter mask.
Sets the server event filter mask.
maskBit mask (see table below)
| Event code | Value |
|---|---|
S7Server.evcAll |
0xFFFFFFFF |
S7Server.evcNone |
0x00000000 |
S7Server.evcServerStarted |
0x00000001 |
S7Server.evcServerStopped |
0x00000002 |
S7Server.evcListenerCannotStart |
0x00000004 |
S7Server.evcClientAdded |
0x00000008 |
S7Server.evcClientRejected |
0x00000010 |
S7Server.evcClientNoRoom |
0x00000020 |
S7Server.evcClientException |
0x00000040 |
S7Server.evcClientDisconnected |
0x00000080 |
S7Server.evcClientTerminated |
0x00000100 |
S7Server.evcClientsDropped |
0x00000200 |
S7Server.evcPDUincoming |
0x00010000 |
S7Server.evcDataRead |
0x00020000 |
S7Server.evcDataWrite |
0x00040000 |
S7Server.evcNegotiatePDU |
0x00080000 |
S7Server.evcReadSZL |
0x00100000 |
S7Server.evcClock |
0x00200000 |
S7Server.evcUpload |
0x00400000 |
S7Server.evcDownload |
0x00800000 |
S7Server.evcDirectory |
0x01000000 |
S7Server.evcSecurity |
0x02000000 |
S7Server.evcControl |
0x04000000 |
Returns the last job result.
Returns a textual explanation of a given event.
eventObjEvent object (example here)
Returns a textual explanation of a given error number.
errNumError number
Returns the server status. (see table below)
| Status | Value | Description |
|---|---|---|
S7Server.SrvStopped |
0x00 | The Server is stopped |
S7Server.SrvRunning |
0x01 | The Server is Running |
S7Server.SrvError |
0x02 | Server Error |
Returns the number of clients connected to the server.
Returns the Virtual CPU status. (see table below)
Sets the Virtual CPU status.
cpuStatusStatus value (see table below)
| Status | Value | Description |
|---|---|---|
S7Server.S7CpuStatusUnknown |
0x00 | The CPU status is unknown |
S7Server.S7CpuStatusRun |
0x08 | The CPU is running |
S7Server.S7CpuStatusStop |
0x04 | The CPU is stopped |