Client

Snap7 client used for connection to a siemens7 server.

class snap7.client.Client[source]

A snap7 client

ab_read(start, size)[source]

This is a lean function of Cli_ReadArea() to read PLC process outputs.

ab_write(start, data)[source]

This is a lean function of Cli_WriteArea() to write PLC process outputs

as_ab_read(start, size)[source]

This is the asynchronous counterpart of client.ab_read().

as_ab_write(start, data)[source]

This is the asynchronous counterpart of Cli_ABWrite.

as_ct_read()[source]
as_ct_write()[source]
as_db_fill()[source]
as_db_get(db_number)[source]

This is the asynchronous counterpart of Cli_DBGet.

as_db_read(db_number, start, size)[source]

This is the asynchronous counterpart of Cli_DBRead.

Returns:user buffer.
as_db_write(db_number, start, data)[source]
copy_ram_to_rom()[source]
create()[source]

create a SNAP7 client.

db_get(db_number)[source]

Uploads a DB from AG.

db_read(db_number, start, size)[source]

This is a lean function of Cli_ReadArea() to read PLC DB.

Returns:user buffer.
destroy()[source]

destroy a client.

full_upload(_type, block_num)[source]

Uploads a full block body from AG. The whole block (including header and footer) is copied into the user buffer.

Parameters:block_num – Number of Block
get_block_info(blocktype, db_number)[source]

Returns the block information for the specified block.

get_connected()[source]

Returns the connection status

Returns:a boolean that indicates if connected.
get_cpu_info()[source]

Retrieves CPU info from client

get_cpu_state()[source]

Retrieves CPU state from client

get_param(number)[source]

Reads an internal Client object parameter.

get_pdu_length()[source]

Returns info about the PDU length.

list_blocks()[source]

Returns the AG blocks amount divided by type.

Returns:a snap7.types.BlocksList object.
list_blocks_of_type(blocktype, size)[source]

This function returns the AG list of a specified block type.

plc_cold_start()[source]

cold starts a client

plc_hot_start()[source]

hot starts a client

plc_stop()[source]

stops a client

read_area(area, dbnumber, start, size)[source]

This is the main function to read data from a PLC. With it you can read DB, Inputs, Outputs, Merkers, Timers and Counters.

Parameters:
  • dbnumber – The DB number, only used when area= S7AreaDB
  • start – offset to start writing
  • size – number of units to read
read_multi_vars(items)[source]

This function read multiple variables from the PLC.

Parameters:items – list of S7DataItem objects
Returns:a tuple with the return code and a list of data items
set_connection_params(address, local_tsap, remote_tsap)[source]

Sets internally (IP, LocalTSAP, RemoteTSAP) Coordinates. This function must be called just before Cli_Connect().

Parameters:
  • address – PLC/Equipment IPV4 Address, for example “192.168.1.12”
  • local_tsap – Local TSAP (PC TSAP)
  • remote_tsap – Remote TSAP (PLC TSAP)
set_connection_type(connection_type)[source]

Sets the connection resource type, i.e the way in which the Clients connects to a PLC.

Parameters:connection_type – 1 for PG, 2 for OP, 3 to 10 for S7 Basic
upload(block_num)[source]

Uploads a block body from AG

Parameters:data – bytearray
snap7.client.error_wrap(func)[source]

Parses a s7 error code returned the decorated function.