smartinspectpython.sitcpprotocol

Module: sitcpprotocol.py

Revision History

Date Version Description
2023/05/30 3.0.0.0 Initial Version.
2023/06/09 3.0.8.0 Added call to RaiseInfoEvent for the SI Console Server banner.

@export
class SITcpProtocol(smartinspectpython.siprotocol.SIProtocol):

Used for sending packets to the SmartInspect Console over a TCP socket connection.

This class is used for sending packets over a TCP connection to the Console. It is used when the 'tcp' protocol is specified in the SmartInspect.Connections property. Please see the IsValidOption method for a list of available protocol options.

For a list of available protocol options, please refer to the IsValidOption method.

Threadsafety:

The public members of this class are thread-safe.

SITcpProtocol()

Initializes a new instance of the class.

Name: str

Overridden. Returns "tcp".

def BuildOptions( self, builder: smartinspectpython.siconnectionsbuilder.SIConnectionsBuilder) -> None:

Overridden. Fills a SIConnectionsBuilder instance with the options currently used by this protocol.

Arguments:
  • builder (SIConnectionsBuilder): The SIConnectionsBuilder object to fill with the current options of this protocol.
def IsValidOption(self, name: str) -> bool:

Overridden. Validates if a protocol option is supported.

Arguments:
  • name (str): The option name to validate.
Returns:

True if the option is supported and false otherwise.

The following table lists all valid options, their default values and descriptions for the TCP protocol.

Valid Options (default value) Description
host ("127.0.0.1") Specifies the TCP host name or ip address that the SI Console is listening on.
port (4228) Specifies the TCP port number that the SI Console is listening on.
timeout (30000) Specifies the connect, receive and send timeout in milliseconds.

View Sample Code

from smartinspectpython.siauto import *

# the following are sample SI Connections options for this protocol.

# log messages using all default options (localhost, port 4228, 30s timeout).
SIAuto.Si.Connections = "tcp()"

# log messages using localhost, port 4228, 30s timeout, asynchronous processing.
SIAuto.Si.Connections = "tcp(host=localhost,port=4228,timeout=30000,reconnect=true,reconnect.interval=10s,async.enabled=true)
def InternalConnect(self) -> None:

Overridden. Creates and connects a TCP socket.

This method tries to connect a TCP socket to a SmartInspect Console. The hostname and port can be specified by passing the "hostname" and "port" options to the Initialize method. Furthermore, it is possible to specify the connect timeout by using the "timeout" option.

Raises:
  • Exception: Creating or connecting the socket failed.
def InternalDisconnect(self):

Overridden. Closes the TCP socket connection.

This method closes the underlying socket handle if previously created and disposes any supplemental objects.

Raises:
  • Exception: Closing the TCP socket failed.
def InternalWritePacket(self, packet: smartinspectpython.sipacket.SIPacket):

Sends a packet to the Console.

Arguments:
  • packet (SIPacket): The packet to write.
Raises:
  • Exception: Sending the packet to the Console failed.

This method sends the supplied packet to the SmartInspect Console and waits for a valid response.

def LoadOptions(self) -> None:

Overridden. Loads and inspects specific options for this protocol.

This method loads all relevant options and ensures their correctness. See IsValidOption for a list of options which are recognized by the protocol.