Partner

Snap7 code for partnering with a siemens 7 server.

This allows you to create a S7 peer to peer communication. Unlike the client-server model, where the client makes a request and the server replies to it, the peer to peer model sees two components with same rights, each of them can send data asynchronously. The only difference between them is the one who is requesting the connection.

class snap7.partner.Partner(active: bool = False)[source]

A snap7 partner.

as_b_send() → int[source]

Sends a data packet to the partner. This function is asynchronous, i.e. it terminates immediately, a completion method is needed to know when the transfer is complete.

b_recv() → int[source]

Receives a data packet from the partner. This function is synchronous, it waits until a packet is received or the timeout supplied expires.

b_send() → int[source]

Sends a data packet to the partner. This function is synchronous, i.e. it terminates when the transfer job (send+ack) is complete.

check_as_b_recv_completion() → int[source]

Checks if a packed received was received.

check_as_b_send_completion() → Tuple[str, ctypes.c_int][source]

Checks if the current asynchronous send job was completed and terminates immediately.

create(active: bool = False)[source]

Creates a Partner and returns its handle, which is the reference that you have to use every time you refer to that Partner.

Parameters:active – 0
Returns:a pointer to the partner object
destroy()[source]

Destroy a Partner of given handle. Before destruction the Partner is stopped, all clients disconnected and all shared memory blocks released.

get_last_error() → ctypes.c_int[source]

Returns the last job result.

get_param(number) → int[source]

Reads an internal Partner object parameter.

get_stats() → Tuple[ctypes.c_uint, ctypes.c_uint, ctypes.c_uint, ctypes.c_uint][source]

Returns some statistics.

Returns:a tuple containing bytes send, received, send errors, recv errors
get_status() → ctypes.c_int[source]

Returns the Partner status.

get_times() → Tuple[ctypes.c_int, ctypes.c_int][source]

Returns the last send and recv jobs execution time in milliseconds.

set_recv_callback() → int[source]

Sets the user callback that the Partner object has to call when a data packet is incoming.

set_send_callback() → int[source]

Sets the user callback that the Partner object has to call when the asynchronous data sent is complete.

stop() → int[source]

Stops the Partner, disconnects gracefully the remote partner.

snap7.partner.error_wrap(func)[source]

Parses a s7 error code returned the decorated function.