Scorpion Communication Modules¶
Scorpion Communication modules are modules for interfacing external processes and systems by TCP/IP, serial, etc. The modules may be used as base classes implementing profile specific protocols or instantiated as is. Default implementation should by default implement Scorpion standard TdvCmd protocol.
Note
Derived classes are typically implemented in Scorpion Central.
TdvCmd protocol¶
The TdvCmd protocol is a text protocol containing a command and optional parameters, separated by semicolon, ‘;’. Parameters consist of a key and following value separated by equal character, ‘=’.
<cmd>;<key=value>;...;<key=value>
Examples¶
Example 1, ScorpionSocket¶
This example creates a ScorpionSocket handling standard TdvCmd protocol. This turns Scorpion into a TdvCmd TCP/IP server.
Central Start:
# Python start script goes here
from scorpionsocket import ScorpionSocket
socket = ScorpionSocket("localhost",port=8706,pollrate=0.1,timeout=0.01,verbose=1)
Central Stop:
# Python stop script goes here
if socket:
socket.close()
socket=None
Example 2, ScorpionSerial¶
This example implements a derived ScorpionSerial class handling some special commands in addition to standard TdvCmd.
RobotSerial class implementation:
from scorpionserial import ScorpionSerial
class RobotSerial(ScorpionSerial):
"""
profile specific protocol implementation
"""
def execute(self,data):
"""
execute spesific profile commands
if not handled, call super class implementation
"""
try:
self.printDebug(data)
cmd,values=self.parse(data) #cmd as string, params as dictionary
if cmd=='ROBOT': #do some specific robot stuff
if 'X' in values and 'Y' in values:
SetFloatValue('InData.X',values['X'])
SetFloatValue('InData.Y',values['Y'])
ExecuteCmd('Inspect','')
return True
else:
return super(RobotSerial,self).execute(data)
except Exception,msg:
self.error(msg)
return False
Central Start:
# Python start script goes here
serial=RobotSerial(4) #COM4
Central Stop:
# Python stop script goes here
if serial:
serial.close()
serial=None