Server

If you just need a quick server with some default values initalised, this package provides a default implementation. To use it you first need to install some aditional dependencies, using:

pip install python-snap7[cli]

Now you can start it using one of the following commands:

python -m snap7.server
# or, if your Python `Scripts/` folder is on PATH:
snap7-server

You can optionally provide the port to be used as an argument, like this:

python -m snap7.server --port 102

Snap7 server used for mimicking a siemens 7 server.

class snap7.server.Server(log: bool = True)[source]

A fake S7 server.

__init__(log: bool = True)[source]
Create a fake S7 server. set log to false if you want to disable

event logging to python logging.

Parameters:

logTrue for enabling the event logging.

create() None[source]

Create the server.

destroy() None[source]

Destroy the server.

event_text(event: SrvEvent) str[source]

Returns a textual explanation of a given event object

Parameters:

event – an PSrvEvent struct object

Returns:

The error string

get_mask(kind: int) c_uint[source]

Reads the specified filter mask.

Parameters:

kind

Returns:

Mask

get_param(number: int) int[source]

Reads an internal Server object parameter.

Parameters:

number – number of the parameter to be set.

Returns:

Value of the parameter.

get_status() Tuple[str, str, int][source]
Reads the server status, the Virtual CPU status and the number of

the clients connected.

Returns:

Server status, cpu status, client count

pick_event() SrvEvent | None[source]

Extracts an event (if available) from the Events queue.

Returns:

Server event.

snap7.server.mainloop(tcp_port: int = 1102, init_standard_values: bool = False) None[source]

Init a fake Snap7 server with some default values.

Parameters:
  • tcp_port – port that the server will listen.

  • init_standard_values – if True will init some defaults values to be read on DB0.


The __main__ module is used as an entrypoint when calling the module from the terminal using python -m flag. It contains functions providing a comandline interface to the server module.

Its main() function is also exported as an consol-entrypoint.

snap7.server.__main__.main(port, dll)

Start a S7 dummy server with some default values.