scorpionsocket module

filename:scorpionsocket.py
author:thor@tordivel.no / roar@tordivel.no
requirements:Scorpion 11.0
copyright:2000-2015 Tordivel AS
license:Tordivel AS’ Scorpion Python Module License

General socket object handling standard Scorpion TdvCmd messages.

The ScorpionSocket is used for Socket Communication in Scorpion Vision Software. It provides a connection less send method and server object

Derived classes should override the execute method for profile specific protocols.

23nov2015, RL: 1.0.0.14
  std autodoc header
29apr2015, RL: 1.0.0.13
  added version property
  changed verbose level for some close methods
23apr2015, RL: 1.0.0.12
  kill timer in close
  SOCK_BUFFER_SIZE=1024
21apr2015, RL: 1.0.0.11
  new object inheritance model
15apr2015, RL: 1.0.0.10
  TdvCmd.cmd in origin case
15apr2015, RL: 1.0.0.9
  added execute method
  changed verbose level on some messages
13apr2015, RL: 1.0.0.8
  handles any TdvCmd in trigger
  verbose as int, 0=None,1=info,3=detailed
12apr2015, RL: 1.0.0.7
  added internal poll timer
  fixed missing import socket
10apr2015, RL: 1.0.0.6
  fixed printDebug in trigger_response
22mar2015, TV: 1.0.0.5
  add client method pair
    open_send_request
    recv_response_close
  add server method
    trigger_response
11feb2015, TV: 1.0.0.4
  fully working beta sample
class scorpionsocket.TdvCmd(msg)

TdvCmd - splits a text message into TdvCmd command and parameters

TdvCmd format: “cmd;key=value;key=value;...;key=value”

>>>cmd=TdvCmd(data)
version

return class version

cmd

origin TdvCmd command

CMD

TdvCmd command in UPPERCASE

params

origin TdvCmd params as string - key=value;key=value;...;key=value

values

params as dictionary where keys are in UPPERCASE

iscmd(cmd)

case insensitive check for command

has_value(key)

return bool whether TdvCmd contains a given key - case insensitive

ex: if cmd.has_value(‘Ready’): ...do some stuff

has_values(keys)

return bool whether TdvCmd contains all given keys in list/tuple - case insensitive

ex: if cmd.has_values([‘Ready’,’Status’]): ...do some stuff

class scorpionsocket.ScorpionSocket(ip, port, pollrate=0.25, timeout=0.2, verbose=1)

Bases: object

The SocketObject is used for Socket Communication in Scorpion Vision Software It provides a connection less send method and server object

Central Start Sample:

>>>socket = ScorpionSocket("localhost",port=8705,pollrate=0.25,timeout=0.01,verbose=1)
__del__()

kill Scorpion timer and close

version

return class version

close()

close server socket

printDebug(level, msg)

prints a debug message when verbose is less equal level

onTimer(sender, args)

internal timer callback - handles any TdvCmd

send(str0, host, port=8700, timeout=0.3)

provides sending an ascii string to a tcp/ip socket server

open_send_request(str0, host, port=8700, timeout=0.3)

open send a request to a server - read response using recv_response_close

recv_response_close()

recv response and close - send keep - return empty string if no response is read

trigger_response(response)

send response

resetCounter()

resets the disconnect counter

execute(msg)

execute msg as TdvCmd and call Scorpion ExecuteCmd