添加运行hpi必须的文件
This commit is contained in:
83
record_system_v27/data/ArcusDevice.py
Normal file
83
record_system_v27/data/ArcusDevice.py
Normal file
@ -0,0 +1,83 @@
|
||||
"""
|
||||
Arcus controller python interface.
|
||||
Only works if one ARCUS device is connected.
|
||||
Including Arcus Configuration cables.
|
||||
Open ArcusDevice.py in Python IDE --> Run --> Enter Terminal Commands
|
||||
"""
|
||||
import threading
|
||||
import Arcus
|
||||
import copy
|
||||
import sys
|
||||
|
||||
class ArcusDevice(object):
|
||||
"""
|
||||
This is interface class to Arcus stepper controller
|
||||
@author Lukas Zubal
|
||||
@version 1.0
|
||||
"""
|
||||
def __init__(self):
|
||||
"""
|
||||
@brief Constructor
|
||||
@param self object instance
|
||||
"""
|
||||
self.device = Arcus.Arcus()
|
||||
if self.device.Connect() == 1:
|
||||
print ' '
|
||||
else:
|
||||
print "Cannot open stepper device on port "
|
||||
sys.exit()
|
||||
self.outputBuffer = " "
|
||||
self.lock = threading.Lock() # thread safety
|
||||
self.verbose = 0
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
@brief Closes Arcus device connection
|
||||
@param self object instance
|
||||
@return bool Returns a 1 if successful
|
||||
"""
|
||||
self.lock.acquire()
|
||||
self.device.Close()
|
||||
self.lock.release()
|
||||
del self.device
|
||||
return 1
|
||||
|
||||
def write(self, data):
|
||||
"""
|
||||
@brief Command-response call to Arcus device
|
||||
@see Arcus controller manual for complete list of interactive commands
|
||||
@param self object instance
|
||||
@param data string containing interactive commands to arcus
|
||||
@return str Returns string containing response of controller
|
||||
"""
|
||||
self.lock.acquire()
|
||||
self.device.SendAndRecive(data, self.outputBuffer)
|
||||
resp = copy.deepcopy(self.outputBuffer[:])
|
||||
self.lock.release()
|
||||
resp = resp.split('\x00')[0]
|
||||
if self.verbose == 1:
|
||||
print resp
|
||||
return resp
|
||||
|
||||
arc = ArcusDevice()
|
||||
|
||||
arc.write('DN') # Send Terminal Command to return device name.
|
||||
# print "Connected to device: " + response # Notify user
|
||||
|
||||
for i in range(len(sys.argv)-1): # The first param is the name of this file.
|
||||
response = arc.write(sys.argv[i+1]) # Process Command and save Controller Response
|
||||
print sys.argv[i+1], response
|
||||
if sys.argv[i+1] == 'DN': # Command 'DN' whose response is not 'OK'(actually is JSA00) is used to test if arcus is connected.
|
||||
pass
|
||||
elif sys.argv[i+1] == 'PX': # Command 'PX' is used to test if the position of arcus is return to 0(initial position);
|
||||
if int(response) == 0:
|
||||
print 'arcus is return to initial position'
|
||||
if int(response) != 0:
|
||||
print 'arcus is still returning'
|
||||
else:
|
||||
while response != 'OK':
|
||||
response = arc.write(sys.argv[i+1])
|
||||
|
||||
|
||||
arc.close() # Close Device.
|
||||
del arc
|
Reference in New Issue
Block a user