Class Reference

Class Details

class keapi.CommandServer[source]

Holds the connection to the RcWebApi’s command socket. Provides a low level API to execute or start commands on the KEBA PLC

Raises

HttpError – When the connection to the socket was unsuccessful.

disconnect()[source]

Disconnects from the socket.

exec(cmd: str, **kwargs) Any[source]

Sends the given command and it’s parameters to the PLC and waits till it’s finished. This method is blocking. Returns the result of the executed command.

Parameters

cmd (str) – PLC command

Returns

Command result

Return type

Any

is_connected() bool[source]

Returns whether the socket is connected or not.

Returns

Is connection open

Return type

bool

start(cmd: str, **kwargs) Ticket[source]

Sends the given command and it’s parameters to the PLC returns a ticket

Parameters

cmd (str) – PLC command

Returns

Ticket of given command

Return type

Ticket

class keapi.SubscribeServer[source]

Holds the connection to the RcWebApi’s subscribe socket. Provides a low level API to subscribe and unsubscribe to topics predefined by KEBA.

Raises

SocketError – When there is a problem while receiving the answer from the socket

disconnect()[source]

Unsubscribes from all active subscriptions and closes the connection to the socket.

is_connected() bool[source]

Returns whether the socket ist connected or not.

Returns

Is connection open

Return type

bool

subscribe(topic: str, func=None, cycle_time=0.0)[source]

Subscribes to a topic. The topic can be a cyclic or event based type. The passed function is called when the topic sends an answer. Leave the cycle_time to 0.0 if subscribing to an event based topic. A topic can be subscribed to multiple times with different functions. If it is a cyclic topic the cycle_time from the first call will be used.

Parameters
  • topic (str) – RcWebApi Topic Name

  • func (function) – Function that will be called when topic returns an answer.

  • cycle_time (float, optional) – Time in seconds how often a topic should return an answer, defaults to 0.0. If left to 0.0 it is assumed that an event based topic is subscribed

unsubscribe(topic: str, func=None)[source]

Unsubscribe from a previously subscribed topic. Can be used to unsubscribe all functions from a topic by leaving func=None. If only a specific function should be unsubscribed pass the function in parameter func.

Parameters
  • topic (str) – RcWebApi Topic Name

  • func (function, optional) – Function that should be unsubscribed, defaults to None

class keapi.Ticket(server, id)[source]

A Ticket represents one command sent to the socket. While the ticket is in state BUSY it has not yet been completed. If a ticket completes with an error the corresponding exception is raised. If a ticket completes normaly the result is returned.

Raises
  • TimeoutError – When wait timeout is reached

  • HttpError – When the request has an error on the users side (e.g. wrong usage of command)

  • KebaError – When the error is on the PLC

class State(value)[source]

An enumeration.

requestid() int[source]

Unique request id for this ticket. This is used to associate a ticket to a command.

Returns

request id

Return type

int

property state: State

Current state of the Ticket

Returns

State

Return type

State

wait(timeout=None) Any[source]

Waits and blocks until the ticket is completed or the timeout is reached.

Parameters

timeout (float, optional) – Timeout in seconds. If left to None it waits forever. Defaults to None

Returns

Result of the sent command. can be none if there is no result for the command

Return type

Any

keapi.connect_commands(url: str)[source]

Establishes a connection to the RcWebApi Commands Socket and returns CommandServer object which can be used to interact with the socket.

Parameters

url (str) – Full URL to socket (e.g. ws://IP:PORT/Robot/websocket-command)

Returns

CommandServer object

Return type

CommandServer

keapi.connect_subscriber(url: str)[source]

Establishes a connection to the RcWebApi Subscribe Socket and returns SubscribeServer object which can be used to interact with the socket.

Parameters

url (str) – Full URL to socket (e.g. ws://IP:PORT/Robot/websocket-subscribe)

Returns

SubscribeServer object

Return type

SubscribeServer

keapi.create_variable_getter(cmd_server: CommandServer, prefix: str)[source]

Creates a function to get variable values with a fixed prefix and server.

Example:

io = create_variable_getter(cmdserver, 'APPL.Application._IoMapping')
val = io('do_0')
Parameters
  • cmd_server (CommandServer) – CommandServer connection

  • prefix (str) – Variable Prefix (e.g. APPL.Application.GVL)

Returns

Function to get variable values

keapi.create_variable_setter(cmd_server: CommandServer, prefix: str)[source]

Creates a function to set variable values with a fixed prefix and server.

Example:

io = create_variable_setter(cmdserver, 'APPL.Application._IoMapping')
io('do_0', True)
Parameters
  • cmd_server (CommandServer) – CommandServer connection

  • prefix (str) – Variable Prefix (e.g. APPL.Application.GVL)

Returns

Function to set variable values

keapi.get_variable(cmd_server: CommandServer, prefix: str, name: str) Any[source]

Returns the value of a given variable on the PLC

Parameters
  • cmd_server (CommandServer) – CommandServer connection

  • prefix (str) – Variable Prefix (e.g. APPL.Application.GVL)

  • name (str) – Variable name

Returns

Variable value

Return type

Any

keapi.set_variable(cmd_server: CommandServer, prefix: str, name: str, val: Any)[source]

Sets a variable on the PLC

Parameters
  • cmd_server (CommandServer) – CommandServer connection

  • prefix (str) – Variable Prefix (e.g. APPL.Application.GVL)

  • name (str) – Variable name

  • val (Any) – Variable value

class keapi.compat.TcProg(robot: str)[source]

Holds the Auth Cookie and the logic to communicate with the TcApi

exec(project_name: str, prog_name: str)[source]

Starts a Teach Control programm and waits until it’s execution is finished. This function is blocking

Parameters
  • project_name (str) – Name of the Teach Control project

  • prog_name (str) – Name of the Teach Control program

Raises
  • TcError – When another program is already active

  • HttpError – When http status code != 200

is_prog_running() bool[source]

Returns whether a program is running or not

Raises
  • TcError – When there is no program started

  • HttpError – When http status code != 200

Returns

Program running

Return type

bool

load_project(project_name: str) None[source]

Loads a Teach Control Project

Parameters

project_name (str) – Name of the project

Raises

HttpError – When http status code != 200

start(project_name: str, prog_name: str)[source]

Loads and starts a Teach Control program.

Parameters
  • project_name (str) – Name of the Teach Control project

  • prog_name (str) – Name of the Teach Control program

Raises
  • TcError – When another program is already active

  • HttpError – When http status code != 200

stop()[source]

Stops the currently executing program and unloads the Teach Control project.

Raises
  • TcError – When there is no program to stop

  • HttpError – When http status code != 200

unload_project() None[source]

Unloads the currently loaded Teach Control project

Raises
  • TcError – When there is not project loaded

  • HttpError – When http status code != 200

class keapi.compat.TcVar[source]

Holds the Auth Cookie and the logic to communicate with the TcApi

get_var(path: str) Any[source]

Gets a Variable from the PLC via the TcApi

Parameters

path (str) – Full path to the Variable ‘.’ seperated

Raises

HttpError – When get was unsuccessful

Returns

Variable value

Return type

Any

set_var(path: str, val: Any)[source]

Sets a Variable on the PLC via the TcApi

Parameters
  • path (str) – Full path to the Variable ‘.’ seperated

  • val (Any) – Value to be set

Raises

HttpError – When set was unsuccessful

keapi.compat.connect_tc_prog(host: str, user: str, passwd: str, robot: str)[source]

Establishes a connection to the TcApi and returns a instance of TcProg which can be used to start and stop programs that are already definen in Teach Control

Parameters
  • host (str) – IP Address or Hostname of TcApi Server

  • user (str) – Username to login to TcApi

  • passwd (str) – Password to login to TcApi

  • robot (str) – Name of the robot

Returns

TcProg instance

Return type

TcProg

keapi.compat.connect_tc_var(host: str, user: str, passwd: str)[source]

Establishes a connection to the TcApi and returns a instance of TcVar which can be used to set and get variables via Teach Control

Parameters
  • host (str) – IP Address or Hostname of TcApi Server

  • user (str) – Username to login to TcApi

  • passwd (str) – Password to login to TcApi

Returns

TcVar instance

Return type

TcVar