SpecSocket

pycertifspec.SpecSocket #

[view_source]

SpecMessage #

[view_source]

NamedTuple representing a response from SPEC. Fields are named the same as in the server documentation: https://www.certif.com/spec_help/server.html#protocol

Properties:

  • magic - Spec magic number (4277009102)
  • vers - Protocol version number
  • size - Size of the header
  • sn - Serial number (same as request if response)
  • sec - Time when sent
  • usec - Time when sent
  • cmd - Command code (One of pycertifspec.EventTypes)
  • type - Type of body data (One of pycertifspec.DataTypes)
  • rows - Number of rows if body data is array
  • cols - Number of columns if body data is array
  • len - Length of body
  • err - Error code (0 if none)
  • flags - Flags (combination of pycertifspec.Flags)
  • name - Name of property
  • body - Body of the message (string when DataTypes.SV_STRING, else raw bytes)

SpecSocket Objects #

class SpecSocket(socket.socket)

[view_source]

Socket like a regular socket.socket, but with extra methods for sending and receiving data from a SPEC server.

connect_spec #

 | connect_spec(host: str, port: int = None, port_range: Tuple[int, int] = (6510, 6530), ports: List[int] = [], timeout: float = 0.5)

[view_source]

Scan ports for a SPEC server and connect when found. If port is already known .connect() can be used instead

Attributes:

  • host string - The address of the host computer
  • port int - If exact port is known, the port to connect to
  • port_range tuple - Range of ports to scan (end is inclusive)
  • ports list - List of ports to scan
  • timeout float - Time to wait for answer before trying the next port

Returns:

  • (int) - The port connected to

send_spec #

 | send_spec(serial_number: int, command: int, data_type: int, property_name: str = "", body: bytes = b'', error: bool = False, flags: List[int] = [], rows: int = 0, cols: int = 0)

[view_source]

Send a message to the SPEC server

Attributes:

  • serial_number int - Serial number of message. Will be the same in server reply
  • command int - The command/event from EventTypes to execute
  • data_type int - The data type of the body. One of DataTypes
  • property_name string - The name of the property to do work on
  • body bytes - The body of the message
  • error int - Error if != 0
  • flags int - Set a flag (isn’t used yet)
  • rows int - The number of rows of the body (if array)
  • cols int - The number of cols of the body (if array)

recv_spec #

 | recv_spec() -> SpecMessage

[view_source]

Receive a SPEC message

Returns:

  • (SpecMessage) - The message from the SPEC server