Form Scorpion software RT Controller could be accessed via Python. Below there are two examples for
communicating with RT Controller.
Access RT Controller from Scorpion software for input (input type must be ScorpionInput):
# Central start
import os, time, CLR
from CLR.System.Reflection import Assembly
Assembly.LoadFrom(os.path.join(GetStringValue("System.Profile"), "RTController", "RTController.client.dll"))
from CLR.RTController.client import RTControllerClient
from CLR.RTController.RemoteIterfaces import IRTControllerAPI
from CLR.RTController.RemoteIterfaces import ISchedulerRemote
from CLR.RTController.RemoteIterfaces import IOutputRemote
from CLR.RTController.RemoteIterfaces import IInputRemote
def TriggerScorpionInput():
# Function to flip scorpion input value
global lastState
try:
lastState = not lastState
except:
lastState = True
inputList = RtAPI.GetInputList()
input0 = IInputRemote(inputList[len(inputList)-1])
input0.SetSoftwareTrigger(lastState)
Access RT Controller from Scorpion software as output (output type must be ScorpionOutput):
# Central start
import os, time, CLR
from CLR.System.Reflection import Assembly
Assembly.LoadFrom(os.path.join(GetStringValue("System.Profile"), "RTController", "RTController.client.dll"))
from CLR.RTController.client import RTControllerClient
from CLR.RTController.RemoteIterfaces import IRTControllerAPI
from CLR.RTController.RemoteIterfaces import ISchedulerRemote
from CLR.RTController.RemoteIterfaces import IOutputRemote
from CLR.RTController.RemoteIterfaces import IInputRemote
def AddRules():
# Create a rule that triggers same output at different positions
schedulers = RtAPI.GetSchedulerList()
for sr in schedulers:
scheduler = ISchedulerRemote(sr)
scheduler.ClearRules();
def ClearRules():
# Clears all rules defined in all schedulers
schedulers = RtAPI.GetSchedulerList()
for sr in schedulers:
scheduler = ISchedulerRemote(sr)
scheduler.ClearRules();
def CreatePatternRule():
# Creates a rule that sets outputs in a pattern
# after last input from a list is triggered
# Values for delay and pulse length are for performance
# counter and must be tweeked for each machine as it is speed
# dependant
# Get last input
inputList = RtAPI.GetInputList()
lastInput = inputList[len(inputList)-1]
# add rule for all schedulers (effectively to all available counters)
schedulers = RtAPI.GetSchedulerList()
count = 0
for sr in schedulers:
# Cast scheduler to ISchedulerRemote
scheduler = ISchedulerRemote(sr)
scheduler.ClearRules();
# create task list. Tasks will be to enable then disable output
taskList = []
outputList = RtAPI.GetOutputList()
for i in range(len(outputList)):
# for each output we move start (make stairs)
# start task is to raise DigitalOutput (True parameter)
startTask = RtAPI.CreateDelayedTask((1000000*i), True, [outputList[i]])
# end task is to lower DigitalOutput (False parameter)
endTask = RtAPI.CreateDelayedTask((1000000*i) + 1000000, False, [outputList[i]])
# create the rule with given tasks (execute it always when input condition is met)
scheduler.CreateDelayedOutputRule("Scorpion notification %s" % count, [lastInput], taskList, False)
count += 1
def Mymethod(id = None, value = None, timer = None):
# Callback method for scorpion output
# It must have this signature (id, value, timer)
# Function prints out the QueryPerformanceCounter
# difference with the sent one
print "Mymethod", id, value, timer
from ctypes import *
kernel32=windll.kernel32
QueryPerformanceCounter=kernel32.QueryPerformanceCounter
QueryPerformanceFrequency=kernel32.QueryPerformanceFrequency