lib60870.NET 2.3.0
IEC 60870-5-101/104 Protocol Source Code Library for C#/.NET
Loading...
Searching...
No Matches
lib60870.CS104.Connection Class Reference

A single connection to a CS 104 (IEC 60870-5-104) server. Implements the Master interface. More...

Inheritance diagram for lib60870.CS104.Connection:
Collaboration diagram for lib60870.CS104.Connection:

Public Member Functions

 Connection (string hostname, int tcpPort=2404)
 Initializes a new instance of the lib60870.CS104.Connection class.
 
 Connection (string hostname, APCIParameters apciParameters, ApplicationLayerParameters alParameters)
 Initializes a new instance of the lib60870.CS104.Connection class.
 
 Connection (string hostname, int tcpPort, APCIParameters apciParameters, ApplicationLayerParameters alParameters)
 Initializes a new instance of the lib60870.CS104.Connection class.
 
 Connection (string hostname, TlsSecurityInformation tlsInfo, int tcpPort=19998)
 Initializes a new instance of the lib60870.CS104.Connection class using TLS.
 
 Connection (string hostname, int tcpPort, APCIParameters apciParameters, ApplicationLayerParameters alParameters, TlsSecurityInformation tlsInfo)
 Initializes a new instance of the lib60870.CS104.Connection class using TLS.
 
void SetTlsSecurity (TlsSecurityInformation securityInfo)
 Set the security parameters for TLS.
 
ConnectionStatistics GetStatistics ()
 Gets the conenction statistics.
 
void SetConnectTimeout (int millies)
 Sets the connect timeout.
 
override void SendInterrogationCommand (CauseOfTransmission cot, int ca, byte qoi)
 Sends the interrogation command.
 
override void SendCounterInterrogationCommand (CauseOfTransmission cot, int ca, byte qcc)
 Sends the counter interrogation command (C_CI_NA_1 typeID: 101)
 
override void SendReadCommand (int ca, int ioa)
 Sends a read command (C_RD_NA_1 typeID: 102).
 
override void SendClockSyncCommand (int ca, CP56Time2a time)
 Sends a clock synchronization command (C_CS_NA_1 typeID: 103).
 
override void SendTestCommand (int ca)
 Sends a test command (C_TS_NA_1 typeID: 104).
 
override void SendTestCommandWithCP56Time2a (int ca, ushort tsc, CP56Time2a time)
 Sends a test command with CP56Time2a time (C_TS_TA_1 typeID: 107).
 
override void SendResetProcessCommand (CauseOfTransmission cot, int ca, byte qrp)
 Sends a reset process command (C_RP_NA_1 typeID: 105).
 
override void SendDelayAcquisitionCommand (CauseOfTransmission cot, int ca, CP16Time2a delay)
 Sends a delay acquisition command (C_CD_NA_1 typeID: 106).
 
override void SendControlCommand (CauseOfTransmission cot, int ca, InformationObject sc)
 Sends the control command.
 
override void SendASDU (ASDU asdu)
 Sends an arbitrary ASDU to the connected slave.
 
override ApplicationLayerParameters GetApplicationLayerParameters ()
 
void SendStartDT ()
 Start data transmission on this connection.
 
void SendStopDT ()
 Stop data transmission on this connection.
 
void Connect ()
 Connect this instance.
 
void ConnectAsync ()
 Connects to the server (outstation). This is a non-blocking call. Before using the connection you have to check if the connection is already connected and running.
 
X509Certificate LocalCertificateSelectionCallback (object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssuers)
 Callback function for selecting a local certificate during an SSL/TLS handshake.
 
void Cancel ()
 
void Close ()
 
void SetASDUReceivedHandler (ASDUReceivedHandler handler, object parameter)
 Set the ASDUReceivedHandler. This handler is invoked whenever a new ASDU is received.
 
void SetConnectionHandler (ConnectionHandler handler, object parameter)
 Sets the connection handler. The connection handler is called when the connection is established or closed.
 
override void SetReceivedRawMessageHandler (RawMessageHandler handler, object parameter)
 Sets the raw message handler. This is a callback to intercept raw messages received.
 
override void SetSentRawMessageHandler (RawMessageHandler handler, object parameter)
 Sets the sent message handler. This is a callback to intercept the sent raw messages.
 
bool IsTransmitBufferFull ()
 Determines whether the transmit (send) buffer is full. If true the next send command will throw a ConnectionException.
 
override void GetFile (int ca, int ioa, NameOfFile nof, IFileReceiver receiver)
 Initiates a request to retrieve a file from the remote system.
 
void GetFile (int ca, int ioa, NameOfFile nof, IFileReceiver receiver, int timeout)
 Initiates a request to retrieve a file from the remote system with a specified timeout.
 
override void SendFile (int ca, int ioa, NameOfFile nof, IFileProvider fileProvider)
 Initiates a request to send a file to the remote system.
 
void GetDirectory (int ca)
 Requests the directory listing from the remote system.
 
- Public Member Functions inherited from lib60870.CS101.Master
void SendInterrogationCommand (CauseOfTransmission cot, int ca, byte qoi)
 Sends the interrogation command.
 
void SendCounterInterrogationCommand (CauseOfTransmission cot, int ca, byte qcc)
 Sends the counter interrogation command (C_CI_NA_1 typeID: 101)
 
void SendReadCommand (int ca, int ioa)
 Sends a read command (C_RD_NA_1 typeID: 102).
 
void SendClockSyncCommand (int ca, CP56Time2a time)
 Sends a clock synchronization command (C_CS_NA_1 typeID: 103).
 
void SendTestCommand (int ca)
 Sends a test command (C_TS_NA_1 typeID: 104).
 
void SendTestCommandWithCP56Time2a (int ca, ushort tsc, CP56Time2a time)
 Sends a test command with CP56Time2a time (C_TS_TA_1 typeID: 107).
 
void SendResetProcessCommand (CauseOfTransmission cot, int ca, byte qrp)
 Sends a reset process command (C_RP_NA_1 typeID: 105).
 
void SendDelayAcquisitionCommand (CauseOfTransmission cot, int ca, CP16Time2a delay)
 Sends a delay acquisition command (C_CD_NA_1 typeID: 106).
 
void SendControlCommand (CauseOfTransmission cot, int ca, InformationObject sc)
 Sends the control command.
 
void SendASDU (ASDU asdu)
 Sends an arbitrary ASDU to the connected slave.
 
void GetFile (int ca, int ioa, NameOfFile nof, IFileReceiver receiver)
 Read the file from slave (upload file)
 
void SendFile (int ca, int ioa, NameOfFile nof, IFileProvider fileProvider)
 Sends the file to slave (download file)
 
ApplicationLayerParameters GetApplicationLayerParameters ()
 Get the application layer parameters used by this master instance.
 
void SetReceivedRawMessageHandler (RawMessageHandler handler, object parameter)
 Sets the raw message handler for received messages.
 
void SetSentRawMessageHandler (RawMessageHandler handler, object parameter)
 Sets the sent message handler for sent messages.
 

Protected Member Functions

void SendStartDT_CON ()
 Start application layer data transmission on this connection.
 
void SendStopDT_CON ()
 Sends a STOPDT_CON message to the remote server if the connection is active.
 
void SendTestFR_ACT ()
 Sends a TESTFR_ACT message to the remote server if the connection is active.
 
void SendTestFR_CON ()
 Sends a TESTFR_CON message to the remote server if the connection is active.
 

Protected Attributes

int tcpPort
 
- Protected Attributes inherited from lib60870.CS101.Master
bool debugOutput
 

Properties

string LocalIpAddress [get, set]
 Set the local IP address for the local connection endpoint.
 
int LocalTcpPort [get, set]
 Set the TCP (source) port for the local connection endpoint (0 to automatically select a source port)
 
bool UseSendMessageQueue [get, set]
 Gets or sets a value indicating whether this lib60870.Connection use send message queue.
 
int SendSequenceNumber [get, set]
 Gets or sets the send sequence number N(S). WARNING: For test purposes only! Do net set in real application!
 
bool CheckSequenceNumbers [get, set]
 
int ReceiveSequenceNumber [get, set]
 Gets or sets the receive sequence number N(R). WARNING: For test purposes only! Do net set in real application!
 
bool Autostart [get, set]
 Gets or sets a value indicating whether this lib60870.Connection is automatically sends a STARTDT_ACT message on startup.
 
ApplicationLayerParameters Parameters [get]
 
int ConnectTimeout [get, set]
 Timeout for connection establishment in milliseconds (ms)
 
int ReceiveTimeout [get, set]
 Maximum allowed time for receiving a single message.
 
bool IsRunning [get]
 Gets a value indicating whether this T:lib60870.CS104.Connection is running(connected).
 
- Properties inherited from lib60870.CS101.Master
bool DebugOutput [get, set]
 

Detailed Description

A single connection to a CS 104 (IEC 60870-5-104) server. Implements the Master interface.

Constructor & Destructor Documentation

◆ Connection() [1/5]

lib60870.CS104.Connection.Connection ( string hostname,
int tcpPort = 2404 )

Initializes a new instance of the lib60870.CS104.Connection class.

Parameters
hostnamehostname of IP address of the CS 104 server
tcpPortTCP port of the CS 104 server

◆ Connection() [2/5]

lib60870.CS104.Connection.Connection ( string hostname,
APCIParameters apciParameters,
ApplicationLayerParameters alParameters )

Initializes a new instance of the lib60870.CS104.Connection class.

Parameters
hostnamehostname of IP address of the CS 104 server
apciParametersAPCI parameters.
alParametersapplication layer parameters.

◆ Connection() [3/5]

lib60870.CS104.Connection.Connection ( string hostname,
int tcpPort,
APCIParameters apciParameters,
ApplicationLayerParameters alParameters )

Initializes a new instance of the lib60870.CS104.Connection class.

Parameters
hostnamehostname of IP address of the CS 104 server
tcpPortTCP port of the CS 104 server
apciParametersAPCI parameters.
alParametersapplication layer parameters.

◆ Connection() [4/5]

lib60870.CS104.Connection.Connection ( string hostname,
TlsSecurityInformation tlsInfo,
int tcpPort = 19998 )

Initializes a new instance of the lib60870.CS104.Connection class using TLS.

Parameters
hostnamehostname of IP address of the CS 104 server
tlsInfoTLS setup
tcpPortTCP port of the CS 104 server

◆ Connection() [5/5]

lib60870.CS104.Connection.Connection ( string hostname,
int tcpPort,
APCIParameters apciParameters,
ApplicationLayerParameters alParameters,
TlsSecurityInformation tlsInfo )

Initializes a new instance of the lib60870.CS104.Connection class using TLS.

Parameters
hostnamehostname of IP address of the CS 104 server
tcpPortTCP port of the CS 104 server
apciParametersAPCI parameters.
alParametersapplication layer parameters.
tlsInfoTLS setup

Member Function Documentation

◆ Connect()

void lib60870.CS104.Connection.Connect ( )

Connect this instance.

The function will throw a SocketException if the connection attempt is rejected or timed out.

Exceptions
ConnectionExceptiondescription

◆ ConnectAsync()

void lib60870.CS104.Connection.ConnectAsync ( )

Connects to the server (outstation). This is a non-blocking call. Before using the connection you have to check if the connection is already connected and running.

Exceptions
ConnectionExceptiondescription

◆ GetDirectory()

void lib60870.CS104.Connection.GetDirectory ( int ca)

Requests the directory listing from the remote system.

Parameters
caThe communication address of the remote system.

◆ GetFile() [1/2]

override void lib60870.CS104.Connection.GetFile ( int ca,
int ioa,
NameOfFile nof,
IFileReceiver receiver )

Initiates a request to retrieve a file from the remote system.

Parameters
caThe communication address of the remote system.
ioaThe information object address for the file.
nofThe name of the file to be retrieved.
receiverThe receiver implementation to handle the file data.

◆ GetFile() [2/2]

void lib60870.CS104.Connection.GetFile ( int ca,
int ioa,
NameOfFile nof,
IFileReceiver receiver,
int timeout )

Initiates a request to retrieve a file from the remote system with a specified timeout.

Parameters
caThe communication address of the remote system.
ioaThe information object address for the file.
nofThe name of the file to be retrieved.
receiverThe receiver implementation to handle the file data.
timeoutThe timeout duration in milliseconds for the file request.

◆ GetStatistics()

ConnectionStatistics lib60870.CS104.Connection.GetStatistics ( )

Gets the conenction statistics.

Returns
The connection statistics.

◆ IsTransmitBufferFull()

bool lib60870.CS104.Connection.IsTransmitBufferFull ( )

Determines whether the transmit (send) buffer is full. If true the next send command will throw a ConnectionException.

Returns
true if this instance is send buffer full; otherwise, false.

◆ LocalCertificateSelectionCallback()

X509Certificate lib60870.CS104.Connection.LocalCertificateSelectionCallback ( object sender,
string targetHost,
X509CertificateCollection localCertificates,
X509Certificate remoteCertificate,
string[] acceptableIssuers )

Callback function for selecting a local certificate during an SSL/TLS handshake.

Parameters
senderThe source of the certificate selection request (typically the client in an SSL/TLS connection).
targetHostThe name of the server being connected to (host name or IP address).
localCertificatesThe collection of local certificates available for selection.
remoteCertificateThe remote server's certificate being validated (not used in this implementation).
acceptableIssuersA list of acceptable issuers for the certificate (not used in this implementation).
Returns
The local certificate to be used for the SSL/TLS connection. In this case, the first certificate in the collection.

◆ SendASDU()

override void lib60870.CS104.Connection.SendASDU ( ASDU asdu)

Sends an arbitrary ASDU to the connected slave.

Parameters
asduThe ASDU to send

◆ SendClockSyncCommand()

override void lib60870.CS104.Connection.SendClockSyncCommand ( int ca,
CP56Time2a time )

Sends a clock synchronization command (C_CS_NA_1 typeID: 103).

Parameters
caCommon address
timethe new time to set
Exceptions
ConnectionExceptiondescription

◆ SendControlCommand()

override void lib60870.CS104.Connection.SendControlCommand ( CauseOfTransmission cot,
int ca,
InformationObject sc )

Sends the control command.

The type ID has to match the type of the InformationObject!

C_SC_NA_1 -> SingleCommand C_DC_NA_1 -> DoubleCommand C_RC_NA_1 -> StepCommand C_SC_TA_1 -> SingleCommandWithCP56Time2a C_SE_NA_1 -> SetpointCommandNormalized C_SE_NB_1 -> SetpointCommandScaled C_SE_NC_1 -> SetpointCommandShort C_BO_NA_1 -> Bitstring32Command

Parameters
cotCause of transmission (use ACTIVATION to start a control sequence)
caCommon address
scInformation object of the command
Exceptions
ConnectionExceptiondescription

◆ SendCounterInterrogationCommand()

override void lib60870.CS104.Connection.SendCounterInterrogationCommand ( CauseOfTransmission cot,
int ca,
byte qcc )

Sends the counter interrogation command (C_CI_NA_1 typeID: 101)

Parameters
cotCause of transmission
caCommon address
qccQualifier of counter interrogation command
Exceptions
ConnectionExceptiondescription

◆ SendDelayAcquisitionCommand()

override void lib60870.CS104.Connection.SendDelayAcquisitionCommand ( CauseOfTransmission cot,
int ca,
CP16Time2a delay )

Sends a delay acquisition command (C_CD_NA_1 typeID: 106).

Parameters
cotCause of transmission
caCommon address
delaydelay for acquisition
Exceptions
ConnectionExceptiondescription

◆ SendFile()

override void lib60870.CS104.Connection.SendFile ( int ca,
int ioa,
NameOfFile nof,
IFileProvider fileProvider )

Initiates a request to send a file to the remote system.

Parameters
caThe communication address of the remote system.
ioaThe information object address for the file.
nofThe name of the file to be sent.
fileProviderThe file provider interface that supplies the file data to be sent.

◆ SendInterrogationCommand()

override void lib60870.CS104.Connection.SendInterrogationCommand ( CauseOfTransmission cot,
int ca,
byte qoi )

Sends the interrogation command.

Parameters
cotCause of transmission
caCommon address
qoiQualifier of interrogation (20 = station interrogation)
Exceptions
ConnectionExceptiondescription

◆ SendReadCommand()

override void lib60870.CS104.Connection.SendReadCommand ( int ca,
int ioa )

Sends a read command (C_RD_NA_1 typeID: 102).

This will send a read command C_RC_NA_1 (102) to the slave/outstation. The COT is always REQUEST (5). It is used to implement the cyclical polling of data application function.

Parameters
caCommon address
ioaInformation object address
Exceptions
ConnectionExceptiondescription

◆ SendResetProcessCommand()

override void lib60870.CS104.Connection.SendResetProcessCommand ( CauseOfTransmission cot,
int ca,
byte qrp )

Sends a reset process command (C_RP_NA_1 typeID: 105).

Parameters
cotCause of transmission
caCommon address
qrpQualifier of reset process command
Exceptions
ConnectionExceptiondescription

◆ SendTestCommand()

override void lib60870.CS104.Connection.SendTestCommand ( int ca)

Sends a test command (C_TS_NA_1 typeID: 104).

Not required and supported by IEC 60870-5-104.

Parameters
caCommon address
Exceptions
ConnectionExceptiondescription

◆ SendTestCommandWithCP56Time2a()

override void lib60870.CS104.Connection.SendTestCommandWithCP56Time2a ( int ca,
ushort tsc,
CP56Time2a time )

Sends a test command with CP56Time2a time (C_TS_TA_1 typeID: 107).

Parameters
caCommon address
tsctest sequence number
timetest timestamp
Exceptions
ConnectionExceptiondescription

◆ SetASDUReceivedHandler()

void lib60870.CS104.Connection.SetASDUReceivedHandler ( ASDUReceivedHandler handler,
object parameter )

Set the ASDUReceivedHandler. This handler is invoked whenever a new ASDU is received.

Parameters
handlerthe handler to be called
parameteruser provided parameter that is passed to the handler

◆ SetConnectionHandler()

void lib60870.CS104.Connection.SetConnectionHandler ( ConnectionHandler handler,
object parameter )

Sets the connection handler. The connection handler is called when the connection is established or closed.

Parameters
handlerthe handler to be called
parameteruser provided parameter that is passed to the handler

◆ SetConnectTimeout()

void lib60870.CS104.Connection.SetConnectTimeout ( int millies)

Sets the connect timeout.

Parameters
milliestimeout value in milliseconds (ms)

◆ SetReceivedRawMessageHandler()

override void lib60870.CS104.Connection.SetReceivedRawMessageHandler ( RawMessageHandler handler,
object parameter )

Sets the raw message handler. This is a callback to intercept raw messages received.

Parameters
handlerHandler/delegate that will be invoked when a message is received
parameterwill be passed to the delegate

◆ SetSentRawMessageHandler()

override void lib60870.CS104.Connection.SetSentRawMessageHandler ( RawMessageHandler handler,
object parameter )

Sets the sent message handler. This is a callback to intercept the sent raw messages.

Parameters
handlerHandler/delegate that will be invoked when a message is sent<
parameterwill be passed to the delegate

◆ SetTlsSecurity()

void lib60870.CS104.Connection.SetTlsSecurity ( TlsSecurityInformation securityInfo)

Set the security parameters for TLS.

Parameters
securityInfoSecurity info.

Property Documentation

◆ Autostart

bool lib60870.CS104.Connection.Autostart
getset

Gets or sets a value indicating whether this lib60870.Connection is automatically sends a STARTDT_ACT message on startup.

true to send STARTDT_ACT message on startup; otherwise, false.

◆ IsRunning

bool lib60870.CS104.Connection.IsRunning
get

Gets a value indicating whether this T:lib60870.CS104.Connection is running(connected).

true if is running/connected; otherwise, false.

◆ ReceiveSequenceNumber

int lib60870.CS104.Connection.ReceiveSequenceNumber
getset

Gets or sets the receive sequence number N(R). WARNING: For test purposes only! Do net set in real application!

The receive sequence number N(R)

◆ SendSequenceNumber

int lib60870.CS104.Connection.SendSequenceNumber
getset

Gets or sets the send sequence number N(S). WARNING: For test purposes only! Do net set in real application!

The send sequence number N(S)

◆ UseSendMessageQueue

bool lib60870.CS104.Connection.UseSendMessageQueue
getset

Gets or sets a value indicating whether this lib60870.Connection use send message queue.

If true the Connection stores the ASDUs to be sent in a Queue when the connection cannot send ASDUs. This is the case when the counterpart (slave/server) is (temporarily) not able to handle new message, or the slave did not confirm the reception of the ASDUs for other reasons. If false the ASDU will be ignored and a lib60870.ConnectionException will be thrown in this case.

true if use send message queue; otherwise, false.


The documentation for this class was generated from the following file: