Class Reference
Class Details
- class keapi.AuthMgr[source]
Holds the auth_token, client_id, PCL IP and robot name
- Raises:
HttpError – When the authorisation was unsuccessful
- auth_token() str[source]
Returns the Authtoken used to connect to the sockts.
- Raises:
HttpError – When the user is not logged in.
- Returns:
Authtoken
- Return type:
str
- client_id() int[source]
Returns the client id.
- Raises:
HttpError – When the client id is not set.
- Returns:
Client ID
- Return type:
str
- host_ip() str[source]
Returns the host ip address.
- Raises:
HttpError – When the user is not logged in.
- Returns:
IP Address
- Return type:
str
- login(ip: str, robot_name: str, user: str, passwd: str) None[source]
Authenticate to the PLC. This needs to be done once before connecting to one of the servers
- Raises:
HttpError – When login was not successful
- Parameters:
ip (str) – Ip Address of the PLC
robot_name (str) – Name of the robot
user (str) – Username to login
passwd (str) – Password to login
- 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.
- 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
- 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
- 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
- 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(auth_mgr: AuthMgr)[source]
Establishes a connection to the RcWebApi Commands Socket and returns CommandServer object which can be used to interact with the socket.
- Parameters:
auth_mgr (AuthMgr) – Instance of AuthMgr
- Returns:
CommandServer object
- Return type:
- keapi.connect_subscriber(auth_mgr: AuthMgr)[source]
Establishes a connection to the RcWebApi Subscribe Socket and returns SubscribeServer object which can be used to interact with the socket.
- Parameters:
auth_mgr (AuthMgr) – Instance of AuthMgr
- Returns:
SubscribeServer object
- Return type:
- 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