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 aDataError
from it. Fordecode
,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 ofstream.read
, so thatBufferEmptyError
exceptions are raised appropriately.
- 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
andFalse
andTrue
otherwise.True
encoded as0xFF
andFalse
as0x00
- 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_AND_TIME(name=None)[source]#
Date and time of day
- code: int = 207#
0xCF
- size: int = 8#
size of type in 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
- class pycomm3.cip.data_types.STRING(name=None)[source]#
Character string, 1-byte per character, 2-byte length
- code: int = 208#
0xD0
- pycomm3.cip.data_types.n_bytes(count, name='')[source]#
Create an instance of a byte string of
count
length. Settingcount
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
- 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
- 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
- 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
- class pycomm3.cip.data_types.STRING2(name=None)[source]#
character string, 2-bytes per character
- code: int = 213#
0xD5
- 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.STRINGN(name=None)[source]#
character string, n-bytes per character
- code: int = 217#
0xD9
- class pycomm3.cip.data_types.SHORT_STRING(name=None)[source]#
character string, 1-byte per character, 1-byte length
- code: int = 218#
0xDA
- 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
tobytes
.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
ofbytes
Note
Any subclass overriding this method must catch any exception and re-raise as a
DataError
. ExceptBufferEmptyErrors
they must be re-raised as such, array decoding relies on this.- Return type:
Sequence
[CIPSegment
]
- class pycomm3.cip.data_types.STRINGI(name=None)[source]#
international character string
- code: int = 222#
0xDE
- classmethod decode(buffer)[source]#
Deserializes a Python object from the
buffer
ofbytes
Note
Any subclass overriding this method must catch any exception and re-raise as a
DataError
. ExceptBufferEmptyErrors
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.CIPSegment(name=None)[source]#
Base type for a CIP path segment
Segment Type
Segment Format
7
6
5
4
3
2
1
0
- 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.DataSegment(data, name='')[source]#
Segment Type
Segment Sub-Type
7
6
5
4
3
2
1
0
- class pycomm3.cip.data_types.DataTypes[source]#
Lookup table/map of elementary data types. Reverse lookup is by CIP code for data type.
- time_of_day#
alias of
TIME_OF_DAY
- date_and_time#
alias of
DATE_AND_TIME
- logix_string#
alias of
LOGIX_STRING
- short_string#
alias of
SHORT_STRING
- padded_epath#
alias of
PADDED_EPATH
- packed_epath#
alias of
PACKED_EPATH
Custom Types#
- pycomm3.custom_types.StructTemplateAttributes#
alias of
Struct