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

size: int = 1#

size of type in bytes

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

Signed 8-bit integer

code: int = 194#

0xC2

size: int = 1#

size of type in bytes

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

Signed 16-bit integer

code: int = 195#

0xC3

size: int = 2#

size of type in bytes

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

Signed 32-bit integer

code: int = 196#

0xC4

size: int = 4#

size of type in bytes

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

Signed 64-bit integer

code: int = 197#

0xC5

size: int = 8#

size of type in bytes

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

Unsigned 8-bit integer

code: int = 198#

0xC6

size: int = 1#

size of type in bytes

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

Unsigned 16-bit integer

code: int = 199#

0xC7

size: int = 2#

size of type in bytes

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

Unsigned 32-bit integer

code: int = 200#

0xC8

size: int = 4#

size of type in bytes

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

Unsigned 64-bit integer

code: int = 201#

0xC9

size: int = 8#

size of type in bytes

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

32-bit floating point

code: int = 202#

0xCA

size: int = 4#

size of type in bytes

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

64-bit floating point

code: int = 203#

0xCB

size: int = 8#

size of type in bytes

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

size: int = 8#

size of type in bytes

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 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 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

size: int = 1#

size of type in bytes

host_type#

alias of USINT

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

bit string - 16-bits

code: int = 210#

0xD2

size: int = 2#

size of type in bytes

host_type#

alias of UINT

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

bit string - 32-bits

code: int = 211#

0xD3

size: int = 4#

size of type in bytes

host_type#

alias of UDINT

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

bit string - 64-bits

code: int = 212#

0xD4

size: int = 8#

size of type in bytes

host_type#

alias of ULINT

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

character string, 2-bytes per character

code: int = 213#

0xD5

len_type#

alias of UINT

encoding = 'utf-16-le'#

encoding of string data

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 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

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

Base type for a structure

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 BOOL

sint#

alias of SINT

int#

alias of INT

dint#

alias of DINT

lint#

alias of LINT

usint#

alias of USINT

uint#

alias of UINT

udint#

alias of UDINT

ulint#

alias of ULINT

real#

alias of REAL

lreal#

alias of LREAL

stime#

alias of STIME

date#

alias of DATE

time_of_day#

alias of TIME_OF_DAY

date_and_time#

alias of DATE_AND_TIME

logix_string#

alias of LOGIX_STRING

string#

alias of STRING

byte#

alias of BYTE

word#

alias of WORD

dword#

alias of DWORD

lword#

alias of LWORD

string2#

alias of STRING2

ftime#

alias of FTIME

ltime#

alias of LTIME

itime#

alias of ITIME

stringn#

alias of STRINGN

short_string#

alias of SHORT_STRING

time#

alias of TIME

padded_epath#

alias of PADDED_EPATH

packed_epath#

alias of PACKED_EPATH

engunit#

alias of ENGUNIT

stringi#

alias of 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 Struct

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

Creates a custom string tag type

class pycomm3.custom_types.Revision(name=None)[source]#