Up | Editing scripts | Script Details | RS232 | TCP/IP | System | Scheduler | HistoryList | ImageView

 

  

 
TCP/IP
The Python classes IMTDVCmdProtocol gives access to the integrated TCP/IP component

These events are available:

  • PacketStart()
  • PacketEnd()
  • Command(Command)
  • Value(Name,Value)

PacketStart and PacketEnd are used for packet separation. Each packet may contain multiple Command and Value events but normally a packet contains a leading Command followed by optional Value events. Internal in Scorpion, the PacketStart event is used to Reset of previous events, the Command and Value events is validated and collected and in PacketEnd the complete command-event sequence is executed.

If the Python event handlers for Command and Value returns 0 Scorpion will execute default handling for these events, if the Python event handler returns 1 the event will be ignored by Scorpion.

Note ! Any changes to the component configuration will be persistent. If these settings is temporarely the script must retrieve the origin settings before setting new values and finally restore origin settings when done.

The following methods are available for the IMTDVCmdProtocol:

Method Parameters Comment
Send(value) string  sends a TDVCMD formatted string
GetTimeout() none returns timeout in seconds
SetTimeout(value) int no of seconds
GetPortNo() none returns the listening port
SetPortNo(value) int sets listening port
GetPortOpen() none returns 0/1 - closed/open
SetPortOpen(value) int 1=open, 0=closed
GetPortParametres() none returns current settings as semocolonseparater string
TCP/IP : 'address:portno'
SetPortParametres(value) string format must be in following order:
TCP/IP: 'address:portno'

Example 1:  Sending data with tdvcmdprotocol from Python

resX=str(GetValue('CenterLine.Line_x'))                #get x position
resY=str(GetValue('CenterLine.Line_y'))                #get y position
org=IMTDVCmdProtocol.GetPortParametres()               #get origin port parametres
IMTDVCmdProtocol.SetPortParametres('10.0.0.9:8700')    #set receiver parameters 
IMTDVCmdProtocol.Send('INSP;X=' + resX + ';Y=' + resY) #send the result 
IMTDVCmdProtocol.SetPortParametres(org)                #restore origin parametres 
Example 2:  Stateless TDVCmdprotocol Server
# Uses builtin TDVIMCmdProtocol as receiver - sends response with InternetMessanger ActiveX plugin
# 
def Handle_IMTDVCmdProtocol_PacketStart(Source):
  #
  # Source = VT_BSTR

  # Set requester to receive response
  ExecuteCmd('Script','IM.SetRemoteComputerAndPortName;Value='+Source)
def Handle_IMTDVCmdProtocol_Command(Command):
  #
  # Command = VT_BSTR
  #
  # return 1 if handled by script
  # return 0 if default handling
  #
  if Command == 'GetData' :
    angle = GetStringValue('Angle.Value')
    ExecuteCmd('Script','IM.Send;Command='+angle)
  return 1
 

Scorpion Vision Version XII : Build 646 - Date: 20170225
Scorpion Vision Software® is a registered trademark of Tordivel AS.
Copyright © 2000 - 2017 Tordivel AS.