Skip to content

Commit 2fc463f

Browse files
committed
reorganize instruments
1 parent 75f4d2c commit 2fc463f

5 files changed

Lines changed: 530 additions & 4 deletions

File tree

instruments/delaystage/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
2121
"""
22+
import logging
23+
from .generic import DelayStage
24+
from instruments.delaystage.standa import Standa_8SMC5
25+
26+
27+
logging.getLogger(__name__).addHandler(logging.NullHandler())
2228

2329

2430
def main():

instruments/delaystage/generic.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,58 @@
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
2121
"""
22+
from instruments import generic
2223

24+
class DelayStage(generic.Instrument):
25+
def __init__(self):
26+
super(DelayStage, self).__init__()
27+
self.position_zero = 0
28+
self.position_current = 0
29+
self.path = 1
30+
self.position_max = 150
31+
self.position_min = -150
32+
self.position_in_ps = 2 * 3.33333 * self.path * self.position_current
33+
self.configuration = {'zero position': 0}
34+
self.velocity = 10 # units per second
35+
36+
def connect(self):
37+
print('connetcted to fake stage. current position=' + str(self.position_current) + '; zero possition' + str(
38+
self.position_zero))
39+
40+
def disconnect(self):
41+
print('Fake stage has been disconnected')
42+
43+
def move_absolute(self, new_position):
44+
# pos=new_position-self.position_zero
45+
time_to_sleep = (abs(self.position_current - new_position)) / self.velocity
46+
if (new_position <= self.position_max) and (new_position >= self.position_min):
47+
'here should be command for real stage; use pos for the real stage'
48+
self.position_current = new_position
49+
time.sleep(time_to_sleep)
50+
print('Fake stage was moved to ' + str(new_position))
51+
else:
52+
print('position is out of range')
53+
54+
def move_relative(self, shift):
55+
if (self.position_current + shift <= self.position_max) and (
56+
self.position_current + shift >= self.position_min):
57+
self.move_absolute(self.position_current + shift)
58+
print('Fake stage was moved by ' + str(shift))
59+
else:
60+
print('position is out of range')
61+
62+
def set_zero_position(self):
63+
print('Zero position set to ' + str(self.position_current))
64+
self.position_zero = self.position_current
65+
self.position_max = self.position_max - self.position_current
66+
self.position_min = self.position_min - self.position_current
67+
self.position_current = 0
68+
69+
def position_get(self):
70+
return self.position_current
71+
72+
class StageError(Exception):
73+
pass
2374

2475
def main():
2576
pass

instruments/delaystage/newport.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,94 @@
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
2121
"""
22+
import time
23+
import sys, os
24+
from .generic import DelayStage
25+
try:
26+
import clr
27+
import System
28+
except ImportError:
29+
print('missing packages for Newport stage.')
30+
31+
class NewportXPS(DelayStage):
32+
33+
def __init__(self):
34+
super(NewportXPS, self).__init__()
35+
if 'CommandInterfaceXPS' not in sys.modules: # TODO: fix imports for XPS stage
36+
# TODO: implement test and ask for correct path in case of faliure
37+
self.NETAssemblyPath = r'C:\Windows\Microsoft.NET\assembly\GAC_64\Newport.XPS.CommandInterface\v4.0_1.0.0.0__9a267756cf640dcf'
38+
sys.path.append(self.NETAssemblyPath)
39+
clr.AddReference("Newport.XPS.CommandInterface")
40+
import CommandInterfaceXPS
41+
42+
self.myXPS = CommandInterfaceXPS.XPS()
43+
self.Address = '192.168.254.254'
44+
self.Port = 5001
45+
self.StageName = "CykBlyat"
46+
self.velocity = 500
47+
self.position_zero = -100
48+
self.position_current = 0
49+
self.position_max = 150
50+
self.position_min = -150
51+
52+
def XPS_Open(self):
53+
# Create XPS interface
54+
# Open a socket
55+
timeout = 1000
56+
result = self.myXPS.OpenInstrument(self.Address, self.Port, timeout)
57+
if result == 0:
58+
print('Open ', self.Address, ":", self.Port, " => Successful")
59+
else:
60+
print('Open ', self.Address, ":", self.Port, " => failure ", result)
61+
62+
def connect(self):
63+
self.XPS_Open()
64+
self.myXPS.GroupKill(System.String(self.StageName), System.String(""))
65+
self.myXPS.GroupInitialize(System.String(self.StageName), System.String(""))
66+
time.sleep(1)
67+
self.myXPS.GroupHomeSearch(System.String(self.StageName), System.String(""))
68+
self.myXPS.GroupMotionEnable(System.String(self.StageName), System.String(""))
69+
self.move_absolute(self.position_zero)
70+
71+
def move_absolute(self, new_position):
72+
'''Moves stage to the given position in range of +/- 150 mm '''
73+
74+
time_to_sleep = (abs(self.position_current - new_position)) / self.velocity
75+
if (new_position < self.position_max) and (new_position > self.position_min):
76+
self.myXPS.GroupMoveAbsolute(System.String(self.StageName), [System.Double(new_position)], System.Int32(1),
77+
System.String(""))
78+
self.position_current = new_position
79+
time.sleep(time_to_sleep)
80+
print('DelayStage was moved to ' + str(new_position))
81+
else:
82+
print('position is out of range')
83+
84+
def position_get(self):
85+
pos = self.myXPS.GetCurrentPosition(System.Double(0), System.Double(0), System.Int32(1), System.Int32(1),
86+
System.Int32(1), System.Int32(1), System.String(self.StageName))
87+
return pos
88+
89+
def disconnect(self):
90+
self.myXPS.GroupKill(System.String(self.StageName), System.String(""))
91+
print('DelayStage has been disconnected')
92+
93+
def XPS_GetControllerVersion(self, myXPS, flag):
94+
result, version, errString = self.myXPS.FirmwareVersionGet(System.String(""), System.String(""))
95+
if flag == 1:
96+
if result == 0:
97+
print('XPS firmware version => ', version)
98+
else:
99+
print('FirmwareVersionGet Error => ', errString)
100+
return result, version
101+
102+
def XPS_GetControllerState(self, myXPS, flag):
103+
result, state, errString = self.myXPS.ControllerStatusGet(System.Int32(0), System.String(""))
104+
if flag == 1:
105+
if result == 0:
106+
print('XPS controller state => ', state)
107+
else:
108+
print('ControllerStatusGet Error => ', errString)
109+
return result, state
22110

23111

24112
def main():

0 commit comments

Comments
 (0)