Up | Configuration | Examples | Release Notes

RemoteIterfaces class list
 

  

 
Examples

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

      RtAPI = CreateRtControllerClient()

    • def CreateRtControllerClient():
          try:
              client = RTControllerClient()
              rtAPI = IRTControllerAPI(client.RTControllerAPI)
              return rtAPI
          except Exception, msg:
              print "CreateRtControllerClient", msg

    • 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

      RtAPI = CreateRtControllerClient()

    • def CreateRtControllerClient():
          try:
              client = RTControllerClient()
              rtAPI = IRTControllerAPI(client.RTControllerAPI)
              return rtAPI
          except Exception, msg:
              print "CreateRtControllerClient", msg

    • def AddRules():
          # Create a rule that triggers same output at different positions
          schedulers = RtAPI.GetSchedulerList()
          for sr in schedulers:
              scheduler = ISchedulerRemote(sr)
              scheduler.ClearRules();

              inputLst = RtAPI.GetInputList()
              input1 = inputLst[len(inputLst) - 1]

              # get last output
              lst = RtAPI.GetOutputList()
              output1 = lst[lst.Length - 1]

              # create 2 delayed output task on same output
              startTask = RtAPI.CreateDelayedTask(0, True, [output1])
              startTask2 = RtAPI.CreateDelayedTask(1000000, False, [output1])

              endTask = RtAPI.CreateDelayedTask(2000000, True, [output1])
              endTask2 = RtAPI.CreateDelayedTask(3000000, False, [output1])

              scheduler.CreateDelayedOutputRule("Scorpion notification 1", [ input1], [ startTask, endTask, startTask2, endTask2 ], False)

    • 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]])

                  taskList.append(startTask)
                  taskList.append(endTask)

              # 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

          plonglong = POINTER(c_longlong)

          count = c_longlong()
          QueryPerformanceCounter.argtypes = [plonglong]
          QueryPerformanceCounter(byref(count))

          freq = c_longlong()
          QueryPerformanceFrequency.argtypes = [plonglong]
          QueryPerformanceFrequency(byref(freq))

          print (count.value - timer) * 1000 / freq.value

 


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