Data Types

class pycomm3.cip.data_types.DataType(name=None)[source]

Base class to represent a CIP data type. Instances of a type are only used when defining the members of a structure.

Each type class provides encode / decode class methods. If overriding them, they must catch any unhandled exception and raise a DataError from it. For decode, BufferEmptyError should be reraised immediately without modification. The buffer empty error is needed for decoding arrays of unknown length. Typically for custom types, overriding the private _encode/_decode methods are sufficient. The private methods do not need to do any exception handling if using the base public methods. For _decode use the private _stream_read method instead of stream.read, so that BufferEmptyError exceptions are raised appropriately.

classmethod encode(value)[source]

Serializes a Python object value to bytes.

Note

Any subclass overriding this method must catch any exception and re-raise a DataError

Return type

bytes

classmethod decode(buffer)[source]

Deserializes a Python object from the buffer of bytes

Note

Any subclass overriding this method must catch any exception and re-raise as a DataError. Except BufferEmptyErrors they must be re-raised as such, array decoding relies on this.

Return type

Any

class pycomm3.cip.data_types.ElementaryDataType(name=None)[source]

Type that represents a single primitive value in CIP.

code: int = 0

CIP data type identifier

size: int = 0

size of type in bytes

class pycomm3.cip.data_types.BOOL(name=None)[source]

A boolean value, decodes 0x00 and False and True otherwise. True encoded as 0xFF and False as 0x00

code: int = 193

0xC1

class pycomm3.cip.data_types.SINT(name=None)[source]

Signed 8-bit integer

code: int = 194

0xC2

class pycomm3.cip.data_types.INT(name=None)[source]

Signed 16-bit integer

code: int = 195

0xC3

class pycomm3.cip.data_types.DINT(name=None)[source]

Signed 32-bit integer

code: int = 196

0xC4

class pycomm3.cip.data_types.LINT(name=None)[source]

Signed 64-bit integer

code: int = 197

0xC5

class pycomm3.cip.data_types.USINT(name=None)[source]

Unsigned 8-bit integer

code: int = 198

0xC6

class pycomm3.cip.data_types.UINT(name=None)[source]

Unsigned 16-bit integer

code: int = 199

0xC7

class pycomm3.cip.data_types.UDINT(name=None)[source]

Unsigned 32-bit integer

code: int = 200

0xC8

class pycomm3.cip.data_types.ULINT(name=None)[source]

Unsigned 64-bit integer

code: int = 201

0xC9

class pycomm3.cip.data_types.REAL(name=None)[source]

32-bit floating point

code: int = 202

0xCA

class pycomm3.cip.data_types.LREAL(name=None)[source]

64-bit floating point

code: int = 203

0xCB

class pycomm3.cip.data_types.STIME(name=None)[source]

Synchronous time information

code: int = 204

0xCC

class pycomm3.cip.data_types.DATE(name=None)[source]

Date information

code: int = 205

0xCD

class pycomm3.cip.data_types.TIME_OF_DAY(name=None)[source]

Time of day

code: int = 206

0xCE

class pycomm3.cip.data_types.DATE_AND_TIME(name=None)[source]

Date and time of day

code: int = 207

0xCF

classmethod encode(time, date, *args, **kwargs)[source]

Serializes a Python object value to bytes.

Note

Any subclass overriding this method must catch any exception and re-raise a DataError

Return type

bytes

class pycomm3.cip.data_types.StringDataType(name=None)[source]

Base class for any string type

len_type = None

data type of the string length

encoding = 'iso-8859-1'

encoding of string data

class pycomm3.cip.data_types.LOGIX_STRING(name=None)[source]

Character string, 1-byte per character, 4-byte length

len_type

alias of pycomm3.cip.data_types.UDINT

class pycomm3.cip.data_types.STRING(name=None)[source]

Character string, 1-byte per character, 2-byte length

code: int = 208

0xD0

len_type

alias of pycomm3.cip.data_types.UINT

class pycomm3.cip.data_types.BytesDataType(name=None)[source]

Base type for placeholder bytes.

pycomm3.cip.data_types.n_bytes(count, name='')[source]

Create an instance of a byte string of count length. Setting count to -1 will consume the entire remaining buffer.

class pycomm3.cip.data_types.BitArrayType(name=None)[source]

Array of bits (Python bools) for host_type integer value

class pycomm3.cip.data_types.BYTE(name=None)[source]

bit string - 8-bits

code: int = 209

0xD1

host_type

alias of pycomm3.cip.data_types.USINT

class pycomm3.cip.data_types.WORD(name=None)[source]

bit string - 16-bits

code: int = 210

0xD2

host_type

alias of pycomm3.cip.data_types.UINT

class pycomm3.cip.data_types.DWORD(name=None)[source]

bit string - 32-bits

code: int = 211

0xD3

host_type

alias of pycomm3.cip.data_types.UDINT

class pycomm3.cip.data_types.LWORD(name=None)[source]

bit string - 64-bits

code: int = 212

0xD4

host_type

alias of pycomm3.cip.data_types.ULINT

class pycomm3.cip.data_types.STRING2(name=None)[source]

character string, 2-bytes per character

code: int = 213

0xD5

len_type

alias of pycomm3.cip.data_types.UINT

class pycomm3.cip.data_types.FTIME(name=None)[source]

duration - high resolution

code: int = 214

0xD6

class pycomm3.cip.data_types.LTIME(name=None)[source]

duration - long

code: int = 215

0xD7

class pycomm3.cip.data_types.ITIME(name=None)[source]

duration - short

code: int = 216

0xD8

class pycomm3.cip.data_types.STRINGN(name=None)[source]

character string, n-bytes per character

code: int = 217

0xD9

classmethod encode(value, char_size=1)[source]

Serializes a Python object value to bytes.

Note

Any subclass overriding this method must catch any exception and re-raise a DataError

Return type

bytes

class pycomm3.cip.data_types.SHORT_STRING(name=None)[source]

character string, 1-byte per character, 1-byte length

code: int = 218

0xDA

len_type

alias of pycomm3.cip.data_types.USINT

class pycomm3.cip.data_types.TIME(name=None)[source]

duration - milliseconds

code: int = 219

0xDB

class pycomm3.cip.data_types.EPATH(name=None)[source]

CIP path segments

code: int = 220

0xDC

classmethod encode(segments, length=False, pad_length=False)[source]

Serializes a Python object value to bytes.

Note

Any subclass overriding this method must catch any exception and re-raise a DataError

Return type

bytes

classmethod decode(buffer)[source]

Deserializes a Python object from the buffer of bytes

Note

Any subclass overriding this method must catch any exception and re-raise as a DataError. Except BufferEmptyErrors they must be re-raised as such, array decoding relies on this.

Return type

Sequence[CIPSegment]

class pycomm3.cip.data_types.PACKED_EPATH(name=None)[source]
class pycomm3.cip.data_types.PADDED_EPATH(name=None)[source]
class pycomm3.cip.data_types.ENGUNIT(name=None)[source]

engineering units

code: int = 221

0xDD

class pycomm3.cip.data_types.STRINGI(name=None)[source]

international character string

code: int = 222

0xDE

classmethod encode(*strings)[source]

Encodes strings to bytes

Return type

bytes

classmethod decode(buffer)[source]

Deserializes a Python object from the buffer of bytes

Note

Any subclass overriding this method must catch any exception and re-raise as a DataError. Except BufferEmptyErrors they must be re-raised as such, array decoding relies on this.

Return type

Tuple[Sequence[str], Sequence[str], Sequence[int]]

class pycomm3.cip.data_types.DerivedDataType(name=None)[source]

Base type for types composed of ElementaryDataType

class pycomm3.cip.data_types.ArrayType(name=None)[source]

Base type for an array

pycomm3.cip.data_types.Array(length_, element_type_)[source]

Creates a new array type from element_type_ of length_.

length_ can be 3 possible types:
  • int - fixed length of the array

  • DataType - length read from beginning of buffer as type

  • None - unbound array, consumes entire buffer on decode

Return type

Type[ArrayType]

class pycomm3.cip.data_types.StructType(name=None)[source]

Base type for a structure

pycomm3.cip.data_types.Struct(*members_)[source]

Creates a new structure type comprised of members_. Members can be instances of a DataType with a name. The decoded value of a struct will a dictionary of {member.name: value}, members without names will be excluded from the return value. To encode a struct, the value should be a dict of {member.name: value} or a sequence of just values (nesting as needed). Avoid multiple no-name members if planning on encoding the struct using a dict.

Return type

Type[StructType]

class pycomm3.cip.data_types.CIPSegment(name=None)[source]

Base type for a CIP path segment

Segment Type

Segment Format

7

6

5

4

3

2

1

0

classmethod encode(segment, padded=False)[source]

Encodes an instance of a CIPSegment to bytes

Return type

bytes

classmethod decode(buffer)[source]

Attention

Not Implemented

Return type

Any

class pycomm3.cip.data_types.PortSegment(port, link_address, name='')[source]

Port segment of a CIP path.

Segment Type

Extended Link Addr

Port Identifier

7

6

5

4

3

2

1

0

port_segments = {'backplane': 1, 'bp': 1, 'cnet': 2, 'dh485-a': 2, 'dh485-b': 3, 'dhrio-a': 2, 'dhrio-b': 3, 'dnet': 2, 'enet': 2}

available port names for use in a CIP path

class pycomm3.cip.data_types.LogicalSegment(logical_value, logical_type, *args, **kwargs)[source]

Logical segment of a CIP path

Segment Type

Logical Type

Logical Format

7

6

5

4

3

2

1

0

logical_types = {'attribute_id': 16, 'class_id': 0, 'connection_point': 12, 'instance_id': 4, 'member_id': 8, 'service_id': 24, 'special': 20}

available logical types

class pycomm3.cip.data_types.NetworkSegment(name=None)[source]
class pycomm3.cip.data_types.SymbolicSegment(name=None)[source]
class pycomm3.cip.data_types.DataSegment(data, name='')[source]

Segment Type

Segment Sub-Type

7

6

5

4

3

2

1

0

class pycomm3.cip.data_types.ConstructedDataTypeSegment(name=None)[source]
class pycomm3.cip.data_types.ElementaryDataTypeSegment(name=None)[source]
class pycomm3.cip.data_types.DataTypes[source]

Lookup table/map of elementary data types. Reverse lookup is by CIP code for data type.

bool

alias of pycomm3.cip.data_types.BOOL

sint

alias of pycomm3.cip.data_types.SINT

int

alias of pycomm3.cip.data_types.INT

dint

alias of pycomm3.cip.data_types.DINT

lint

alias of pycomm3.cip.data_types.LINT

usint

alias of pycomm3.cip.data_types.USINT

uint

alias of pycomm3.cip.data_types.UINT

udint

alias of pycomm3.cip.data_types.UDINT

ulint

alias of pycomm3.cip.data_types.ULINT

real

alias of pycomm3.cip.data_types.REAL

lreal

alias of pycomm3.cip.data_types.LREAL

stime

alias of pycomm3.cip.data_types.STIME

date

alias of pycomm3.cip.data_types.DATE

time_of_day

alias of pycomm3.cip.data_types.TIME_OF_DAY

date_and_time

alias of pycomm3.cip.data_types.DATE_AND_TIME

logix_string

alias of pycomm3.cip.data_types.LOGIX_STRING

string

alias of pycomm3.cip.data_types.STRING

byte

alias of pycomm3.cip.data_types.BYTE

word

alias of pycomm3.cip.data_types.WORD

dword

alias of pycomm3.cip.data_types.DWORD

lword

alias of pycomm3.cip.data_types.LWORD

string2

alias of pycomm3.cip.data_types.STRING2

ftime

alias of pycomm3.cip.data_types.FTIME

ltime

alias of pycomm3.cip.data_types.LTIME

itime

alias of pycomm3.cip.data_types.ITIME

stringn

alias of pycomm3.cip.data_types.STRINGN

short_string

alias of pycomm3.cip.data_types.SHORT_STRING

time

alias of pycomm3.cip.data_types.TIME

padded_epath

alias of pycomm3.cip.data_types.PADDED_EPATH

packed_epath

alias of pycomm3.cip.data_types.PACKED_EPATH

engunit

alias of pycomm3.cip.data_types.ENGUNIT

stringi

alias of pycomm3.cip.data_types.STRINGI

Custom Types

class pycomm3.custom_types.IPAddress(name=None)[source]
class pycomm3.custom_types.ModuleIdentityObject(name=None)[source]
class pycomm3.custom_types.ListIdentityObject(name=None)[source]
pycomm3.custom_types.StructTemplateAttributes

alias of pycomm3.cip.data_types.Struct.<locals>.Struct

pycomm3.custom_types.FixedSizeString(size_, len_type_=UDINT)[source]

Creates a custom string tag type

class pycomm3.custom_types.Revision(name=None)[source]
pycomm3.custom_types.StructTag(*members, bool_members, host_members, struct_size)[source]

bool_members = {member name: (host member, bit)}

Return type

Type[StructType]