CIPDriver API#

class pycomm3.CIPDriver(path, *args, **kwargs)[source]#

A base CIP driver for the SLCDriver and LogixDriver classes. Implements common CIP services like (un)registering sessions, forward open/close, generic messaging, etc.

__init__(path, *args, **kwargs)[source]#
property connected: bool#

Read-Only Property to check whether or not a connection is open.

Return type:

bool

Returns:

True if a connection is open, False otherwise

property connection_size#

CIP connection size, 4000 if using Extended Forward Open else 500

property socket_timeout#

Socket open connection timeout, in seconds

classmethod list_identity(path)[source]#

Uses the ListIdentity service to identify the target

Return type:

Optional[Dict[str, Any]]

Returns:

device identity if reply contains valid response else None

classmethod discover(broadcast_address='255.255.255.255')[source]#

Discovers available devices on the current network(s). Returns a list of the discovered devices Identity Object (as dict).

Return type:

List[Dict[str, Any]]

get_module_info(slot)[source]#

Get the Identity object for a given slot in the rack of the current connection

Return type:

dict

open()[source]#

Creates a new Ethernet/IP socket connection to target device and registers a CIP session.

Returns:

True if successful, False otherwise

close()[source]#

Closes the current connection and un-registers the session.

generic_message(service, class_code, instance, attribute=b'', request_data=b'', data_type=None, name='generic', connected=True, unconnected_send=False, route_path=True, **kwargs)[source]#

Perform a generic CIP message. Similar to how MSG instructions work in Logix.

Parameters:
  • service (Union[int, bytes]) – service code for the request (single byte)

  • class_code (Union[int, bytes]) – request object class ID

  • instance (Union[int, bytes]) – ID for an instance of the class If set with 0, request class attributes.

  • attribute (Union[int, bytes]) – (optional) attribute ID for the service/class/instance

  • request_data (Any) – (optional) any additional data required for the request.

  • data_type (Union[Type[DataType], DataType, None]) – a DataType class that will be used to decode the response, None to return just bytes

  • name (str) – return Tag.tag value, arbitrary but can be used for tracking returned Tags

  • connected (bool) – True if service required a CIP connection (forward open), False to use UCMM

  • unconnected_send (bool) – (Unconnected Only) wrap service in an UnconnectedSend service

  • route_path (Union[bool, Sequence[CIPSegment], bytes, str]) – (Unconnected Only) True to use current connection route to destination, False to ignore, Or provide a path string, list of segments to be encoded as a PADDED_EPATH, or an already encoded path.

Return type:

Tag

Returns:

a Tag with the result of the request. (Tag.value for writes will be the request_data)