GeoCOM¶
Description¶
Module: geocompy.geo
The geo package provides wrapper methods for all GeoCOM RPC functions
available on supported instruments running various versions of the TPS
system software, or software based on the TPS system.
Types¶
GeoCom
Submodules¶
geocompy.geo.gcdatageocompy.geo.gctypesgeocompy.geo.ausgeocompy.geo.autgeocompy.geo.bapgeocompy.geo.bmmgeocompy.geo.camgeocompy.geo.comgeocompy.geo.csvgeocompy.geo.ctlgeocompy.geo.dnageocompy.geo.edmgeocompy.geo.ftrgeocompy.geo.imggeocompy.geo.kdmgeocompy.geo.motgeocompy.geo.supgeocompy.geo.tmcgeocompy.geo.wir
Definitions¶
-
class GeoCom(connection: Connection, *, logger: Logger | None =
None, attempts: int =2, checksum: bool =False)[source]¶ GeoCOM protocol handler.
The individual commands are available through their respective subsystems.
Examples
Opening a simple serial connection:
>>> from geocompy.communication import open_serial >>> from geocompy.geo import GeoCom >>> >>> with open_serial("COM1") as line: ... tps = GeoCom(line) ... tps.com.nullprocess() ... >>>Passing a logger:
>>> from sys import stdout >>> from logging import getLogger, DEBUG, StreamHandler >>> >>> from geocompy.communication import open_serial >>> from geocompy.geo import GeoCom >>> >>> logger = getLogger("TPS") >>> logger.addHandler(StreamHandler(stdout)) >>> logger.setLevel(DEBUG) >>> with open_serial("COM1") as com: ... tps = GeoCom(com, logger=logger) ... tps.com.nullprocess() ... >>> GeoComResponse(COM_NullProc) ... # Startup connection test GeoComResponse(COM_GetDoublePrecision) ... # Precision sync GeoComResponse(COM_NullProc) ... # First executed commandAfter the subsystems are initialized, the connection is tested by sending an
LFcharacter to clear the receiver buffer, then theCOM_NullProcis executed. If the test fails, it is retried with one second delay (if multiple attempts are allowed).- Parameters:
- connection: Connection¶
Connection to use for communication (usually a serial connection).
- logger: Logger | None =
None¶ Logger to log all requests and responses, by default None
- attempts: int =
2¶ Number of tries at connection validation before raising exception, by default 2
- checksum: bool =
False¶ Use and verify checksums in requests, by default False
- Raises:
ConnectionRefusedError – If the connection could not be verified in the specified number of attempts.
- abort() GeoComResponse[None][source]¶
Aborts the current motorized function.
- Returns:
- Error codes:
UNDEFINED: The command was accepted, but the response indicated failed execution. Possibly nothing to abort.COM_FAILED: The abort command could not be sent due to a communication issue.
- Return type:
Note
The abort command does not actually use the GeoCOM syntax, but the function returns a GeoComResponse anyway, in order to maintain the uniformity with the rest of the commands.
-
parse_response(cmd: str, response: str, parsers: Callable[[str], _T] | None =
None) GeoComResponse[_T][source]¶ -
parse_response(cmd: str, response: str, parsers: Iterable[Callable[[str], Any]] | None =
None) GeoComResponse[tuple[Any, ...]] Parses RPC response and constructs GeoComResponse instance.
- Parameters:
- Returns:
Parsed return codes and parameters from the RPC response.
- Return type:
-
request(rpc: int, params: Iterable[int | float | bool | str | Angle | Byte | Enum] =
(), parsers: Callable[[str], _T] | None =None) GeoComResponse[_T][source]¶ -
request(rpc: int, params: Iterable[int | float | bool | str | Angle | Byte | Enum] =
(), parsers: Iterable[Callable[[str], Any]] | None =None) GeoComResponse[tuple[Any, ...]] Executes an RPC request and returns the parsed GeoCOM response.
Constructs a request(from the given RPC code and parameters), writes it to the serial line, then reads the response. The response is then parsed using the provided parser functions.
- Parameters:
- rpc: int¶
Number of the RPC to execute.
- params: Iterable[int | float | bool | str | Angle | Byte | Enum] =
()¶ Parameters for the request, by default()
- parsers: Callable[[str], _T] | None =
None¶ - parsers: Iterable[Callable[[str], Any]] | None =
None Parser functions for the values in the RPC response, by default None
- Returns:
Parsed return codes and parameters from the RPC response.
- Return type: