客戶端
Tango Control System的客戶端有很多形式,可以通過Taurus,Sardana等插件來實現,也可以通過web端實現。
1.插件形式實現客戶端可以參考如下文章:
Tango Control System 使用(五):簡易客戶端測試Device Server
2.網頁客戶端可以參考:
Tango demo
3.自定義客戶端
自定義客戶端
通過QT來自定義客戶端界面,然後通過API實現與Device Server連接。
1.通過QT自定義客戶端界面結構
2.完善客戶端代碼,以下是當前示例代碼。
QT文件必須和代碼文件在同一目錄下
from taurus.external.qt import Qt
import taurus
import tango
import sys
import os
from taurus.qt.qtgui.util.ui import UILoadable
from taurus.qt.qtgui.application import TaurusApplication
from taurus.qt.qtgui.panel import TaurusForm
data=0
a = 0
@UILoadable(with_ui="_ui")
class panel(Qt.QMainWindow):
def __init__(self, parent=None):
Qt.QWidget.__init__(self, parent)
path = os.path.join(os.path.dirname(__file__))
self.loadUi(filename="HV_motor.ui", path=path)
#taurusForm模塊放到Qt圈好的widget裏
layout3 = Qt.QHBoxLayout()
panel = TaurusForm()
layout3.addWidget(panel)
props = [ 'state', 'Position', 'Rotation', 'LimitMin', 'LimitMax', 'speed', 'target' ]
model = [ 'tango://127.0.0.1:10000/test/HV_motor/1/%s' % p for p in props ]
panel.setModel(model)
#panel.removeModels(model) # removeModels to releas rom
self._ui.widget_3.setLayout(layout3)
#綁定button的信號和槽
motor = 'tango://127.0.0.1:10000/test/HV_motor/1'
hvmotor = tango.DeviceProxy(motor)
self._ui.move_button.clicked.connect(lambda:self.update_target(hvmotor,int(self._ui.target_data.text())))
self._ui.speed_button.clicked.connect(lambda:self.write_speed(hvmotor,int(self._ui.speed_data.text())))
self._ui.limitmin_button.clicked.connect(lambda:self.write_limitmin(hvmotor,int(self._ui.limitmin_data.text())))
self._ui.limitmax_button.clicked.connect(lambda:self.write_limitmax(hvmotor,int(self._ui.limitmax_data.text())))
def update(self, label,data):
if label == 'tango://DESKTOP-DEPQL70.localdomain:10000/test/HV_motor/1/Position':
self._ui.position1.setText(data)
self._ui.rotation1.setText(data)
# self._ui.position2.setText(data)
elif label == 'tango://DESKTOP-DEPQL70.localdomain:10000/test/HV_motor/1/target':
self._ui.target1.setText(data)
elif label == 'tango://DESKTOP-DEPQL70.localdomain:10000/test/HV_motor/1/speed':
self._ui.speed1.setText(data)
elif label == 'tango://DESKTOP-DEPQL70.localdomain:10000/test/HV_motor/1/LimitMin':
self._ui.limitimin1.setText(data)
elif label == 'tango://DESKTOP-DEPQL70.localdomain:10000/test/HV_motor/1/LimitMax' :
self._ui.limitmax1.setText(data)
def update_target(self, device,data):
device.target = data
device.command_inout('move')
def write_speed(self, device , data) :
device.speed = data
def write_limitmin(self, device , data) :
device.LimitMin = data
def write_limitmax(self, device , data) :
device.LimitMax = data
#重寫 窗口關閉事件
def closeEvent(self, event): #窗口關閉 移除監聽器
props = [ 'Position', 'LimitMin', 'LimitMax', 'speed', 'target' ]
model = [ 'tango://127.0.0.1:10000/test/HV_motor/1/%s' % p for p in props ]
for m in model:
taurus.Attribute(m).removeListener(myListener) #移除輪詢
def myListener(evt_src, evt_type, evt_value):
#print 'myListener: entering…'
print 'evt_src = ', evt_src
#print 'evt_type = ', evt_type
#print 'evt_value = ', evt_value
print 'evt_value = ', evt_value.rvalue
#print '\n'
a = evt_value.rvalue
pe.update(str(evt_src),str(a))
#return a
if __name__ == "__main__":
app = TaurusApplication(sys.argv)
pe = panel()
props = [ 'Position', 'LimitMin', 'LimitMax', 'speed', 'target' ]
model = [ 'tango://192.168.119.131:10000/test/HV_motor/1/%s' % p for p in props ]
for m in model:
taurus.Attribute(m).addListener(myListener) #輪詢
pe.show()
sys.exit(app.exec_())
3.運行結果
通過與ATKPanel進行比較,發現所有數據正常,命令執行正常。