Master (Client)#

IEC104_Master is the client API most callers should use; it is layered over IEC104_Connection, which implements the APCI state machine.

IEC104_Master - client API layered over IEC104_Connection.

Cause Of Transmission conventions:

  • General/counter interrogation and every command (C_SC_NA_1 etc.) are sent with ACTIVATION and confirmed with ACTIVATION_CON; interrogation additionally streams monitor data and finishes with ACTIVATION_TERMINATION.

  • The read command (C_RD_NA_1) is the one exception: both the request and its reply use REQUEST instead.

Unsolicited/spontaneous monitor-direction ASDUs (COT=SPONTANEOUS) can arrive at any time, including interleaved with a pending request’s replies. Rather than silently dropping them, blocking methods forward any non-matching ASDU seen while waiting to the optional on_unsolicited callback (or log it at TRACE level if unset). When no request is pending, simply iterate a IEC104_Master instance (for asdu in master: ...) to consume the incoming ASDU stream directly.

class icspacket.proto.iec104.master.IEC104_Master(connection: IEC104_Connection | None = None, *, on_unsolicited: Callable[[ASDU], None] | None = None)[source]#

Ergonomic IEC 60870-5-104 client (controlling station) API.

Parameters:
  • connection (IEC104_Connection | None) – Existing IEC104_Connection to use; a new one (with default timers) is created if omitted.

  • on_unsolicited (Callable[[ASDU], None] | None) – Optional callback invoked with any ASDU observed while a blocking method is waiting for its own reply, but which does not match that reply (e.g. a spontaneous data change interleaved with a pending general interrogation). If omitted, such ASDUs are only logged at TRACE level.

connect(address: tuple[str, int]) None[source]#

Connect and perform the STARTDT handshake; see connect().

close() None[source]#

Perform the STOPDT handshake and close the connection; see close().

read_next(timeout: float | None = None) ASDU[source]#

Return the next incoming ASDU, whatever it is.

Only meaningful when no other blocking method (interrogation, command, …) is concurrently waiting on the same connection - both ultimately consume the same single incoming-ASDU queue.

Parameters:

timeout (float | None) – Maximum seconds to wait, or None to block forever.

Raises:
  • TimeoutError – If no ASDU arrives within timeout seconds.

  • ConnectionClosedError – If the connection closes while waiting.

general_interrogation(common_address: int, qoi: QOI = QOI.STATION, timeout: float | None = None) Iterator[ASDU][source]#

Issue a general (or group) interrogation and stream back the reply.

Parameters:
  • common_address (int) – Target station address.

  • qoi (QOI) – Interrogation scope (default: whole station).

  • timeout (float | None) – Maximum seconds to wait for each successive reply ASDU, or None to block forever.

Raises:
  • IEC104ProtocolError – If the activation is negatively confirmed.

  • TimeoutError – If a reply does not arrive in time.

Returns:

An iterator yielding the ACTIVATION_CON first, then every monitor-direction ASDU as it arrives, ending with (and including) the ACTIVATION_TERMINATION ASDU.

Return type:

Iterator[ASDU]

counter_interrogation(common_address: int, request: QCC_Request = QCC_Request.GENERAL, freeze: QCC_Freeze = QCC_Freeze.READ, timeout: float | None = None) Iterator[ASDU][source]#

Issue a counter interrogation and stream back the reply.

Parameters:
  • common_address (int) – Target station address.

  • request (QCC_Request) – Counter group to request (default: all groups).

  • freeze (QCC_Freeze) – Freeze/reset behavior (default: read without freezing).

  • timeout (float | None) – Maximum seconds to wait for each successive reply ASDU, or None to block forever.

Raises:
  • IEC104ProtocolError – If the activation is negatively confirmed.

  • TimeoutError – If a reply does not arrive in time.

Returns:

An iterator yielding the ACTIVATION_CON first, then every counter-value ASDU as it arrives, ending with (and including) the ACTIVATION_TERMINATION ASDU.

Return type:

Iterator[ASDU]

clock_sync(common_address: int, when: datetime | None = None, timeout: float | None = None) ASDU[source]#

Synchronize the outstation’s clock.

Unlike interrogation, a clock sync only ever produces a single ACTIVATION_CON reply - there is no termination/streaming phase.

Parameters:
  • common_address (int) – Target station address.

  • when (datetime.datetime | None) – Timestamp to send; defaults to the current local time.

  • timeout (float | None) – Maximum seconds to wait for the confirmation.

Raises:
  • IEC104ProtocolError – If the activation is negatively confirmed.

  • TimeoutError – If the confirmation does not arrive in time.

Returns:

The ACTIVATION_CON ASDU (its decoded object carries the timestamp actually applied, per some outstations’ behavior).

Return type:

ASDU

test_command(common_address: int, timeout: float | None = None) ASDU[source]#

Send a test command (exercises the link without side effects).

Parameters:
  • common_address (int) – Target station address.

  • timeout (float | None) – Maximum seconds to wait for the confirmation.

Raises:
  • IEC104ProtocolError – If the activation is negatively confirmed, or the confirmation’s fixed test pattern does not match.

  • TimeoutError – If the confirmation does not arrive in time.

Returns:

The ACTIVATION_CON ASDU.

Return type:

ASDU

reset_process(common_address: int, qualifier: QRP = QRP.GENERAL_RESET, timeout: float | None = None) ASDU[source]#

Send a reset process command.

Parameters:
  • common_address (int) – Target station address.

  • qualifier (QRP) – Reset scope (default: reset the entire process).

  • timeout (float | None) – Maximum seconds to wait for the confirmation.

Raises:
  • IEC104ProtocolError – If the activation is negatively confirmed.

  • TimeoutError – If the confirmation does not arrive in time.

Returns:

The ACTIVATION_CON ASDU.

Return type:

ASDU

read(common_address: int, ioa: int, timeout: float | None = None) ASDU[source]#

Poll the current value of a single information object.

Parameters:
  • common_address (int) – Target station address.

  • ioa (int) – Information Object Address to read.

  • timeout (float | None) – Maximum seconds to wait for the reply.

Raises:
  • IEC104ProtocolError – If the read is negatively confirmed (e.g. unknown IOA).

  • TimeoutError – If the reply does not arrive in time.

Returns:

The reply ASDU (its type depends on the point being read; decode with decode_objects()).

Return type:

ASDU

single_command(common_address: int, ioa: int, value: bool, *, select: bool = False, qu: QOC = QOC.NO_ADDITIONAL_DEFINITION, timeout: float | None = None) ASDU[source]#

Send a single command (on/off).

Only performs one step of the select-before-operate sequence; call twice (select=True then select=False) to select then execute.

Parameters:
  • common_address (int) – Target station address.

  • ioa (int) – Information Object Address to command.

  • value (bool) – Commanded state.

  • select (bool) – True to select rather than directly execute.

  • qu (QOC) – Qualifier of command (pulse duration behavior).

  • timeout (float | None) – Maximum seconds to wait for the confirmation.

Raises:
  • IEC104ProtocolError – If the activation is negatively confirmed.

  • TimeoutError – If the confirmation does not arrive in time.

Returns:

The ACTIVATION_CON ASDU.

Return type:

ASDU

double_command(common_address: int, ioa: int, value: DoublePointValue, *, select: bool = False, qu: QOC = QOC.NO_ADDITIONAL_DEFINITION, timeout: float | None = None) ASDU[source]#

Send a double command (on/off/intermediate).

Only performs one step of the select-before-operate sequence; call twice (select=True then select=False) to select then execute.

Parameters:
  • common_address (int) – Target station address.

  • ioa (int) – Information Object Address to command.

  • value (DoublePointValue) – Commanded state.

  • select (bool) – True to select rather than directly execute.

  • qu (QOC) – Qualifier of command (pulse duration behavior).

  • timeout (float | None) – Maximum seconds to wait for the confirmation.

Raises:
  • IEC104ProtocolError – If the activation is negatively confirmed.

  • TimeoutError – If the confirmation does not arrive in time.

Returns:

The ACTIVATION_CON ASDU.

Return type:

ASDU

step_command(common_address: int, ioa: int, value: StepCommandValue, *, select: bool = False, qu: QOC = QOC.NO_ADDITIONAL_DEFINITION, timeout: float | None = None) ASDU[source]#

Send a regulating step command (step up/down).

Only performs one step of the select-before-operate sequence; call twice (select=True then select=False) to select then execute.

Parameters:
  • common_address (int) – Target station address.

  • ioa (int) – Information Object Address to command.

  • value (StepCommandValue) – Commanded step direction.

  • select (bool) – True to select rather than directly execute.

  • qu (QOC) – Qualifier of command (pulse duration behavior).

  • timeout (float | None) – Maximum seconds to wait for the confirmation.

Raises:
  • IEC104ProtocolError – If the activation is negatively confirmed.

  • TimeoutError – If the confirmation does not arrive in time.

Returns:

The ACTIVATION_CON ASDU.

Return type:

ASDU

setpoint_command_normalized(common_address: int, ioa: int, value: int, *, select: bool = False, ql: int = 0, timeout: float | None = None) ASDU[source]#

Send a set-point command with a normalized (fixed-point) value.

Parameters:
  • common_address (int) – Target station address.

  • ioa (int) – Information Object Address to command.

  • value (int) – Normalized value, see NVA.

  • select (bool) – True to select rather than directly execute.

  • ql (int) – Qualifier value (0: default).

  • timeout (float | None) – Maximum seconds to wait for the confirmation.

Raises:
  • IEC104ProtocolError – If the activation is negatively confirmed.

  • TimeoutError – If the confirmation does not arrive in time.

Returns:

The ACTIVATION_CON ASDU.

Return type:

ASDU

setpoint_command_scaled(common_address: int, ioa: int, value: int, *, select: bool = False, ql: int = 0, timeout: float | None = None) ASDU[source]#

Send a set-point command with a scaled (16-bit signed integer) value.

Parameters:
  • common_address (int) – Target station address.

  • ioa (int) – Information Object Address to command.

  • value (int) – Scaled value, see SVA.

  • select (bool) – True to select rather than directly execute.

  • ql (int) – Qualifier value (0: default).

  • timeout (float | None) – Maximum seconds to wait for the confirmation.

Raises:
  • IEC104ProtocolError – If the activation is negatively confirmed.

  • TimeoutError – If the confirmation does not arrive in time.

Returns:

The ACTIVATION_CON ASDU.

Return type:

ASDU

setpoint_command_short(common_address: int, ioa: int, value: float, *, select: bool = False, ql: int = 0, timeout: float | None = None) ASDU[source]#

Send a set-point command with a short floating point value.

Parameters:
  • common_address (int) – Target station address.

  • ioa (int) – Information Object Address to command.

  • value (float) – IEEE 754 single-precision value, see R32.

  • select (bool) – True to select rather than directly execute.

  • ql (int) – Qualifier value (0: default).

  • timeout (float | None) – Maximum seconds to wait for the confirmation.

Raises:
  • IEC104ProtocolError – If the activation is negatively confirmed.

  • TimeoutError – If the confirmation does not arrive in time.

Returns:

The ACTIVATION_CON ASDU.

Return type:

ASDU

IEC104_Connection - the APCI state machine (IEC 60870-5-104 framing layer).

(See IEC 60870-5-104, clause 5 - APCI structure, and clause 6 - APCI use on the network layer, for the STARTDT/STOPDT/TESTFR handshake and the I/S-format sequence-number bookkeeping this class implements.)

exception icspacket.proto.iec104.connection.IEC104ProtocolError[source]#

Raised when the peer violates the APCI state machine - an unexpected U-format reply, an out-of-sequence I-format N(S), or a confirmation that fails to arrive before t1 elapses.

class icspacket.proto.iec104.connection.IEC104_Connection(sock: socket | None = None, t0: float = 30, t1: float = 15, t2: float = 10, t3: float = 20, k: int = 12, w: int = 8)[source]#

Manages a single IEC 60870-5-104 TCP connection’s APCI layer.

Drives the STARTDT/STOPDT handshake, the I-format V(S)/ V(R) send/receive sequence counters and their k/w flow control window, automatic S-format acknowledgments, and the t1/t2/t3 timers. send_data()/recv_data() exchange raw encoded ASDU bytes (this class’s “user data”); send_asdu()/ recv_asdu() are thin convenience wrappers around ASDU.

Redundant/backup connections are out of scope: this class models exactly one TCP socket, matching this module’s documented scope.

Example:

>>> conn = IEC104_Connection()
>>> conn.connect(("127.0.0.1", 2404))  # 2404: IEC104_DEFAULT_PORT
>>> conn.send_asdu(asdu)
>>> response = conn.recv_asdu(timeout=10)
>>> conn.close()
Parameters:
  • sock (socket.socket | None) – Existing TCP socket to use; a new one is created if omitted.

  • t0 (float) – Connect timeout in seconds (default T0_DEFAULT).

  • t1 (float) – Confirmation timeout in seconds (default T1_DEFAULT).

  • t2 (float) – Acknowledgment timeout in seconds, t2 < t1 (default T2_DEFAULT).

  • t3 (float) – Idle/keepalive timeout in seconds (default T3_DEFAULT).

  • k (int) – Maximum outstanding unacknowledged I-format APDUs (default K_DEFAULT).

  • w (int) – Received-APDU count triggering an S-format ack, w <= k (default W_DEFAULT).

Raises:

ValueError – If w > k.

connect(address: tuple[str, int]) None[source]#

Connect to address and perform the STARTDT handshake.

Blocks until either STARTDT is confirmed or t0/t1 elapses. Once confirmed, sequence counters are reset to zero and the background reader thread is started.

Parameters:

address (tuple[str, int]) – (host, port) of the IEC-104 outstation.

Raises:
  • ConnectionError – If the TCP connection itself fails.

  • IEC104ProtocolError – If STARTDT is not confirmed in time or the peer replies with something other than STARTDT_CON.

close() None[source]#

Gracefully close the connection.

Sends STOPDT act and waits (best-effort, bounded by t1) for STOPDT con before stopping the reader thread and closing the socket - matching COTP_Connection’s best-effort disconnect style.

read_one_apci() APCI[source]#

Blocking read of exactly one APCI frame.

The frame’s own length octet (see APCI) is used to know exactly how many further bytes belong to it, so this never over-reads into the next frame.

Raises:

ConnectionClosedError – If the peer closes the socket mid-frame.

send_data(octets: bytes, /) None[source]#

Send octets (a single encoded ASDU) as an I-format APCI frame.

Blocks (bounded by t1) while the k send window is full, i.e. while k I-format APDUs are already unacknowledged.

Parameters:

octets (bytes) – Raw encoded ASDU bytes (see build()).

Raises:
recv_data() bytes[source]#

Block until the next I-format ASDU payload is available.

Raises:

ConnectionClosedError – If the connection closes/fails while waiting.

Returns:

The raw encoded ASDU bytes.

Return type:

bytes

recv_data_timeout(timeout: float | None) bytes[source]#

As recv_data(), but with an explicit timeout.

Parameters:

timeout (float | None) – Maximum seconds to wait, or None to block forever.

Raises:
  • TimeoutError – If no ASDU arrives within timeout seconds.

  • ConnectionClosedError – If the connection closes/fails while waiting.

Returns:

The raw encoded ASDU bytes.

Return type:

bytes

send_asdu(asdu: ASDU) None[source]#

Encode and send a complete ASDU.

recv_asdu(timeout: float | None = None) ASDU[source]#

Receive and decode the next ASDU.

Parameters:

timeout (float | None) – Maximum seconds to wait, or None to block forever.

property send_sequence: int#

Current V(S) send sequence number.

property recv_sequence: int#

Current V(R) receive sequence number.

handle_apci(apci: APCI) None[source]#

Dispatch a received APCI frame to the appropriate handler.

Called by _Reader; not normally called directly.

Raises:

IEC104ProtocolError – If an I-format frame’s N(S) is out of sequence.

check_timers() None[source]#

Check the t1/t2/t3 deadlines, sending an S-format acknowledgment or TESTFR act as needed.

Called periodically by _Reader; not normally called directly.

Raises:

IEC104ProtocolError – If a confirmation (I-format ack or TESTFR) fails to arrive before t1 elapses.

IEC 60870-5-104 constants and enumerations.

icspacket.proto.iec104.const.IEC104_DEFAULT_PORT = 2404#

Well-known TCP port IEC 60870-5-104 outstations listen on (IANA-registered as iec-104).

icspacket.proto.iec104.const.T0_DEFAULT = 30#

Default timeout t0 (seconds): time allowed for the TCP connection to be established.

icspacket.proto.iec104.const.T1_DEFAULT = 15#

Default timeout t1 (seconds): time allowed for a send or test APDU to be confirmed.

icspacket.proto.iec104.const.T2_DEFAULT = 10#

Default timeout t2 (seconds, t2 < t1): time before an S-format acknowledgment must be sent if no I-format APDU is available to piggy-back the acknowledgment on.

icspacket.proto.iec104.const.T3_DEFAULT = 20#

Default timeout t3 (seconds): maximum idle time before a TESTFR APDU is sent to keep the connection alive.

icspacket.proto.iec104.const.K_DEFAULT = 12#

Default k: maximum number of outstanding (unacknowledged) I-format APDUs the sender may have in flight at once.

icspacket.proto.iec104.const.W_DEFAULT = 8#

Default w (w <= k): number of received I-format APDUs after which an S-format acknowledgment must be sent at the latest.

icspacket.proto.iec104.const.APCI_START = 104#

Fixed start byte every APCI frame begins with.

icspacket.proto.iec104.const.APCI_FORMAT_MASK = 3#

Mask isolating the two format-selector bits from the first control octet.

class icspacket.proto.iec104.const.APCIFormat(*values)[source]#

APCI control-field format selector, held in the low bit(s) of the control field’s first octet. (See IEC 60870-5-104, clause 5.1)

I_FORMAT = 0#

Information transfer format - carries an ASDU, sequenced by ControlField_I’s send_seq/recv_seq. Only bit 0 (= 0) is significant; bit 1 is always transmitted as 0.

S_FORMAT = 1#

Numbered supervisory function format - a bare acknowledgment, carrying only a recv_seq (ControlField_S).

U_FORMAT = 3#

Unnumbered control function format - carries one of the STARTDT/STOPDT/TESTFR handshake functions (ControlField_U, see UFormatFunction).

class icspacket.proto.iec104.const.UFormatFunction(*values)[source]#

U-format control function bits.

Each member is an independent single-bit flag inside the U-format control field’s first octet (bits 2-7; bits 0-1 are always 11, see APCIFormat.U_FORMAT). Exactly one _ACT/_CON bit is set per U-format APDU.

STARTDT_ACT = 4#

Start data transfer - activation (client to server).

STARTDT_CON = 8#

Start data transfer - confirmation (server to client).

STOPDT_ACT = 16#

Stop data transfer - activation (client to server).

STOPDT_CON = 32#

Stop data transfer - confirmation (server to client).

TESTFR_ACT = 64#

Test frame - activation (either direction).

TESTFR_CON = 128#

Test frame - confirmation (either direction, answers TESTFR_ACT).

class icspacket.proto.iec104.const.TypeID(*values)[source]#

ASDU Type Identification.

Identifies the structure and semantics of the information objects carried by an ASDU (Application Service Data Unit). Written into the first octet of every ASDU. (See IEC 60870-5-101, clause 7.2.2)

File-transfer types (120-126) and the security-extension S_* types (81-95, defined by IEC 60870-5-7) are not modeled yet.

M_SP_NA_1 = 1#

Single-point information.

M_SP_TA_1 = 2#

Single-point information with CP24Time2a time tag.

M_DP_NA_1 = 3#

Double-point information.

M_DP_TA_1 = 4#

Double-point information with CP24Time2a time tag.

M_ST_NA_1 = 5#

Step position information.

M_ST_TA_1 = 6#

Step position information with CP24Time2a time tag.

M_BO_NA_1 = 7#

Bitstring of 32 bit.

M_BO_TA_1 = 8#

Bitstring of 32 bit with CP24Time2a time tag.

M_ME_NA_1 = 9#

Measured value, normalized value.

M_ME_TA_1 = 10#

Measured value, normalized value with CP24Time2a time tag.

M_ME_NB_1 = 11#

Measured value, scaled value.

M_ME_TB_1 = 12#

Measured value, scaled value with CP24Time2a time tag.

M_ME_NC_1 = 13#

Measured value, short floating point number.

M_ME_TC_1 = 14#

Measured value, short floating point number with CP24Time2a time tag.

M_IT_NA_1 = 15#

Integrated totals.

M_IT_TA_1 = 16#

Integrated totals with CP24Time2a time tag.

M_EP_TA_1 = 17#

Event of protection equipment with CP24Time2a time tag.

M_EP_TB_1 = 18#

Packed start events of protection equipment with CP24Time2a time tag.

M_EP_TC_1 = 19#

Packed output circuit information of protection equipment with CP24Time2a time tag.

M_PS_NA_1 = 20#

Packed single-point information with status change detection.

M_ME_ND_1 = 21#

Measured value, normalized value without quality descriptor.

M_SP_TB_1 = 30#

Single-point information with CP56Time2a time tag.

M_DP_TB_1 = 31#

Double-point information with CP56Time2a time tag.

M_ST_TB_1 = 32#

Step position information with CP56Time2a time tag.

M_BO_TB_1 = 33#

Bitstring of 32 bit with CP56Time2a time tag.

M_ME_TD_1 = 34#

Measured value, normalized value with CP56Time2a time tag.

M_ME_TE_1 = 35#

Measured value, scaled value with CP56Time2a time tag.

M_ME_TF_1 = 36#

Measured value, short floating point number with CP56Time2a time tag.

M_IT_TB_1 = 37#

Integrated totals with CP56Time2a time tag.

M_EP_TD_1 = 38#

Event of protection equipment with CP56Time2a time tag.

M_EP_TE_1 = 39#

Packed start events of protection equipment with CP56Time2a time tag.

M_EP_TF_1 = 40#

Packed output circuit information of protection equipment with CP56Time2a time tag.

S_IT_TC_1 = 41#

Integrated totals containing time tagged security statistics (vendor-common extension carried in the base Type-ID space by several stacks).

C_SC_NA_1 = 45#

Single command.

C_DC_NA_1 = 46#

Double command.

C_RC_NA_1 = 47#

Regulating step command.

C_SE_NA_1 = 48#

Set-point command, normalized value.

C_SE_NB_1 = 49#

Set-point command, scaled value.

C_SE_NC_1 = 50#

Set-point command, short floating point number.

C_BO_NA_1 = 51#

Bitstring of 32 bit command.

C_SC_TA_1 = 58#

Single command with CP56Time2a time tag.

C_DC_TA_1 = 59#

Double command with CP56Time2a time tag.

C_RC_TA_1 = 60#

Regulating step command with CP56Time2a time tag.

C_SE_TA_1 = 61#

Set-point command, normalized value with CP56Time2a time tag.

C_SE_TB_1 = 62#

Set-point command, scaled value with CP56Time2a time tag.

C_SE_TC_1 = 63#

Set-point command, short floating point number with CP56Time2a time tag.

C_BO_TA_1 = 64#

Bitstring of 32 bit command with CP56Time2a time tag.

M_EI_NA_1 = 70#

End of initialization.

C_IC_NA_1 = 100#

General interrogation command.

C_CI_NA_1 = 101#

Counter interrogation command.

C_RD_NA_1 = 102#

Read command.

C_CS_NA_1 = 103#

Clock synchronization command.

C_TS_NA_1 = 104#

Test command.

C_RP_NA_1 = 105#

Reset process command.

C_CD_NA_1 = 106#

Delay acquisition command.

C_TS_TA_1 = 107#

Test command with CP56Time2a time tag.

P_ME_NA_1 = 110#

Parameter of measured value, normalized value.

P_ME_NB_1 = 111#

Parameter of measured value, scaled value.

P_ME_NC_1 = 112#

Parameter of measured value, short floating point number.

P_AC_NA_1 = 113#

Parameter activation.

class icspacket.proto.iec104.const.CauseOfTransmission(*values)[source]#

Cause Of Transmission (COT).

Explains why an ASDU was sent - e.g. spontaneously, in answer to an interrogation, or in response to a command - and occupies the lower 6 bits of the ASDU header’s second octet (see the cause field of CauseOfTransmissionField). (See IEC 60870-5-101, clause 7.2.3)

PERIODIC = 1#

Transmitted cyclically/periodically.

BACKGROUND_SCAN = 2#

Transmitted as part of a background scan.

SPONTANEOUS = 3#

Transmitted spontaneously (unsolicited, e.g. on a value change).

INITIALIZED = 4#

Transmitted after the outstation (re-)initialized.

REQUEST = 5#

Transmitted in response to a read request.

ACTIVATION = 6#

Command activation.

ACTIVATION_CON = 7#

Command activation confirmation.

DEACTIVATION = 8#

Command deactivation.

DEACTIVATION_CON = 9#

Command deactivation confirmation.

ACTIVATION_TERMINATION = 10#

Command activation termination.

RETURN_INFO_REMOTE = 11#

Feedback caused by a remote command.

RETURN_INFO_LOCAL = 12#

Feedback caused by a local command (e.g. local operator action).

FILE_TRANSFER = 13#

Transmitted as part of a file transfer.

AUTHENTICATION = 14#

Authentication (IEC 62351 security extension).

MAINTENANCE_OF_AUTH_SESSION_KEY = 15#

Maintenance of authentication session key (IEC 62351).

MAINTENANCE_OF_USER_ROLE_AND_UPDATE_KEY = 16#

Maintenance of user role and update key (IEC 62351).

INTERROGATED_BY_STATION = 20#

Transmitted in response to a station (global) interrogation.

INTERROGATED_BY_GROUP_1 = 21#

Transmitted in response to a group-1 interrogation.

INTERROGATED_BY_GROUP_2 = 22#

Transmitted in response to a group-2 interrogation.

INTERROGATED_BY_GROUP_3 = 23#

Transmitted in response to a group-3 interrogation.

INTERROGATED_BY_GROUP_4 = 24#

Transmitted in response to a group-4 interrogation.

INTERROGATED_BY_GROUP_5 = 25#

Transmitted in response to a group-5 interrogation.

INTERROGATED_BY_GROUP_6 = 26#

Transmitted in response to a group-6 interrogation.

INTERROGATED_BY_GROUP_7 = 27#

Transmitted in response to a group-7 interrogation.

INTERROGATED_BY_GROUP_8 = 28#

Transmitted in response to a group-8 interrogation.

INTERROGATED_BY_GROUP_9 = 29#

Transmitted in response to a group-9 interrogation.

INTERROGATED_BY_GROUP_10 = 30#

Transmitted in response to a group-10 interrogation.

INTERROGATED_BY_GROUP_11 = 31#

Transmitted in response to a group-11 interrogation.

INTERROGATED_BY_GROUP_12 = 32#

Transmitted in response to a group-12 interrogation.

INTERROGATED_BY_GROUP_13 = 33#

Transmitted in response to a group-13 interrogation.

INTERROGATED_BY_GROUP_14 = 34#

Transmitted in response to a group-14 interrogation.

INTERROGATED_BY_GROUP_15 = 35#

Transmitted in response to a group-15 interrogation.

INTERROGATED_BY_GROUP_16 = 36#

Transmitted in response to a group-16 interrogation.

REQUESTED_BY_GENERAL_COUNTER = 37#

Transmitted in response to a general counter interrogation.

REQUESTED_BY_GROUP_1_COUNTER = 38#

Transmitted in response to a group-1 counter interrogation.

REQUESTED_BY_GROUP_2_COUNTER = 39#

Transmitted in response to a group-2 counter interrogation.

REQUESTED_BY_GROUP_3_COUNTER = 40#

Transmitted in response to a group-3 counter interrogation.

REQUESTED_BY_GROUP_4_COUNTER = 41#

Transmitted in response to a group-4 counter interrogation.

UNKNOWN_TYPE_ID = 44#

Negative confirmation: the Type-ID is not supported by the outstation.

UNKNOWN_COT = 45#

Negative confirmation: the cause of transmission is not supported.

UNKNOWN_CA = 46#

Negative confirmation: the Common Address is not configured.

UNKNOWN_IOA = 47#

Negative confirmation: the Information Object Address is unknown.

class icspacket.proto.iec104.const.DoublePointValue(*values)[source]#

Double-point information value (DPI).

The 2-bit value carried by DIQ and, in command direction, the state bits of DCO. (See IEC 60870-5-101, clause 7.2.6.2)

INTERMEDIATE = 0#

Indeterminate/intermediate state (point is transitioning).

OFF = 1#

Determined OFF state.

ON = 2#

Determined ON state.

INDETERMINATE = 3#

Indeterminate state (fault).

class icspacket.proto.iec104.const.StepCommandValue(*values)[source]#

Regulating-step command value (RCS).

The 2-bit value carried by the state bits of RCO. Structurally the same width/position as DoublePointValue, but with distinct “lower/higher” semantics, so it is modeled as its own enum. (See IEC 60870-5-101, clause 7.2.6.17)

INVALID_0 = 0#

Not permitted.

LOWER = 1#

Regulating step: next step lower/DOWN.

HIGHER = 2#

Regulating step: next step higher/UP.

INVALID_3 = 3#

Not permitted.

class icspacket.proto.iec104.const.QOI(*values)[source]#

Qualifier Of Interrogation command.

Selects the scope of a general interrogation command (TypeID.C_IC_NA_1): the whole station, or one of 16 interrogation groups configured on the outstation. (See IEC 60870-5-101, clause 7.2.6.22)

STATION = 20#

Interrogate the entire station (global/general interrogation).

class icspacket.proto.iec104.const.QCC_Request(*values)[source]#

Request qualifier (RQT) part of the Qualifier Of Counter interrogation Command (QCC).

Occupies the lower 6 bits of the QCC octet; combine with a QCC_Freeze member (upper 2 bits) to build a full QCC value. (See IEC 60870-5-101, clause 7.2.6.23)

GENERAL = 5#

Request all counters (general/global counter interrogation).

class icspacket.proto.iec104.const.QCC_Freeze(*values)[source]#

Freeze qualifier (FRZ) part of the Qualifier Of Counter interrogation Command (QCC), occupying the upper 2 bits of the QCC octet. (See IEC 60870-5-101, clause 7.2.6.23)

READ = 0#

Read the counter value(s) without freezing or resetting them.

FREEZE_WITHOUT_RESET = 64#

Freeze the counter value(s) without resetting them.

FREEZE_WITH_RESET = 128#

Freeze the counter value(s) and reset them afterwards.

COUNTER_RESET = 192#

Reset the counter value(s) without freezing them first.

class icspacket.proto.iec104.const.QRP(*values)[source]#

Qualifier Of Reset Process command. (See IEC 60870-5-101, clause 7.2.6.27)

GENERAL_RESET = 1#

Reset the entire process (outstation application).

RESET_PENDING_INFO_WITH_TIME_TAG = 2#

Reset all pending information with time tag.

class icspacket.proto.iec104.const.QPA(*values)[source]#

Qualifier Of Parameter Activation command. (See IEC 60870-5-101, clause 7.2.6.25)

ACT_PREV_LOADED_PARAMETER = 1#

(De)activate the previously loaded parameter set.

ACT_OBJECT_PARAMETER = 2#

(De)activate the parameter of the addressed information object.

ACT_OBJECT_TRANSMISSION = 3#

(De)activate cyclic/periodic transmission of the addressed object.

class icspacket.proto.iec104.const.QPM_Kind(*values)[source]#

Kind-of-parameter part of the Qualifier of Parameter of Measured values (QPM), occupying the lower 6 bits of the QPM octet; bit 6 (LPC, “local parameter change”) and bit 7 (POP, “parameter operation”) are modeled as separate flags on QPM. (See IEC 60870-5-101, clause 7.2.6.24)

SMOOTHING_FACTOR = 2#

Smoothing factor (filter time constant).

class icspacket.proto.iec104.const.QOC(*values)[source]#

Qualifier Of Command, occupying bits 2-6 of the SCO/DCO/RCO octet (the qu field of SCO/ DCO/ RCO). (See IEC 60870-5-101, clause 7.2.6.26)

NO_ADDITIONAL_DEFINITION = 0#

No additional definition - execute/terminate the command directly.

SHORT_PULSE_DURATION = 1#

Output duration is determined by a system parameter.

LONG_PULSE_DURATION = 2#

Output duration is determined by a system parameter (long).

PERSISTENT_OUTPUT = 3#

Output persists until a different command changes it.

class icspacket.proto.iec104.const.COI_Cause(*values)[source]#

Cause-of-initialization value (the R sub-field, bits 0-6) carried by the fused COI octet of TypeID.M_EI_NA_1 (end of initialization). Bit 7 of that octet (I, “initialization after change of local parameters”) is modeled as a separate flag on the elements.COI struct. (See IEC 60870-5-101, clause 7.2.6.21)

LOCAL_POWER_SWITCH_ON = 0#

Local power switch on.

LOCAL_MANUAL_RESET = 1#

Local manual reset.

REMOTE_RESET = 2#

Remote reset.