pyqt4 串口通信 自动化测试

Wolf_Electric_UI.py

  1 # -*- coding: utf-8 -*-
  2 
  3 # Form implementation generated from reading ui file 'wolf_electric.ui'
  4 #
  5 # Created: Mon Aug 28 14:30:16 2017
  6 #      by: PyQt4 UI code generator 4.11.3
  7 #
  8 # WARNING! All changes made in this file will be lost!
  9 
 10 from PyQt4 import QtCore, QtGui
 11 
 12 try:
 13     _fromUtf8 = QtCore.QString.fromUtf8
 14 except AttributeError:
 15     def _fromUtf8(s):
 16         return s
 17 
 18 try:
 19     _encoding = QtGui.QApplication.UnicodeUTF8
 20     def _translate(context, text, disambig):
 21         return QtGui.QApplication.translate(context, text, disambig, _encoding)
 22 except AttributeError:
 23     def _translate(context, text, disambig):
 24         return QtGui.QApplication.translate(context, text, disambig)
 25 
 26 class Ui_ElectricalCalibration(object):
 27     def setupUi(self, ElectricalCalibration):
 28         ElectricalCalibration.setObjectName(_fromUtf8("ElectricalCalibration"))
 29         ElectricalCalibration.resize(650, 557)
 30         self.centralwidget = QtGui.QWidget(ElectricalCalibration)
 31         self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
 32         self.label = QtGui.QLabel(self.centralwidget)
 33         self.label.setGeometry(QtCore.QRect(10, 50, 31, 16))
 34         self.label.setObjectName(_fromUtf8("label"))
 35         self.label_3 = QtGui.QLabel(self.centralwidget)
 36         self.label_3.setGeometry(QtCore.QRect(170, 20, 101, 21))
 37         self.label_3.setObjectName(_fromUtf8("label_3"))
 38         self.CalibrationFunction = QtGui.QComboBox(self.centralwidget)
 39         self.CalibrationFunction.setGeometry(QtCore.QRect(280, 20, 87, 22))
 40         self.CalibrationFunction.setMaxCount(2147483647)
 41         self.CalibrationFunction.setObjectName(_fromUtf8("CalibrationFunction"))
 42         self.Begin_Calibration = QtGui.QPushButton(self.centralwidget)
 43         self.Begin_Calibration.setGeometry(QtCore.QRect(30, 250, 101, 31))
 44         self.Begin_Calibration.setObjectName(_fromUtf8("Begin_Calibration"))
 45         self.Log_write = QtGui.QTextEdit(self.centralwidget)
 46         self.Log_write.setGeometry(QtCore.QRect(30, 290, 581, 211))
 47         self.Log_write.setObjectName(_fromUtf8("Log_write"))
 48         self.widget = QtGui.QWidget(self.centralwidget)
 49         self.widget.setGeometry(QtCore.QRect(10, 20, 135, 23))
 50         self.widget.setObjectName(_fromUtf8("widget"))
 51         self.horizontalLayout = QtGui.QHBoxLayout(self.widget)
 52         self.horizontalLayout.setMargin(0)
 53         self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
 54         self.label_2 = QtGui.QLabel(self.widget)
 55         self.label_2.setObjectName(_fromUtf8("label_2"))
 56         self.horizontalLayout.addWidget(self.label_2)
 57         self.UUT_NUMBER = QtGui.QSpinBox(self.widget)
 58         self.UUT_NUMBER.setMinimum(1)
 59         self.UUT_NUMBER.setMaximum(3)
 60         self.UUT_NUMBER.setProperty("value", 1)
 61         self.UUT_NUMBER.setObjectName(_fromUtf8("UUT_NUMBER"))
 62         self.horizontalLayout.addWidget(self.UUT_NUMBER)
 63         self.widget1 = QtGui.QWidget(self.centralwidget)
 64         self.widget1.setGeometry(QtCore.QRect(10, 70, 120, 25))
 65         self.widget1.setObjectName(_fromUtf8("widget1"))
 66         self.horizontalLayout_2 = QtGui.QHBoxLayout(self.widget1)
 67         self.horizontalLayout_2.setMargin(0)
 68         self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
 69         self.Equip_5520 = QtGui.QCheckBox(self.widget1)
 70         self.Equip_5520.setText(_fromUtf8(""))
 71         self.Equip_5520.setObjectName(_fromUtf8("Equip_5520"))
 72         self.horizontalLayout_2.addWidget(self.Equip_5520)
 73         self.horizontalLayout_6 = QtGui.QHBoxLayout()
 74         self.horizontalLayout_6.setObjectName(_fromUtf8("horizontalLayout_6"))
 75         self.COM_5524 = QtGui.QLabel(self.widget1)
 76         self.COM_5524.setObjectName(_fromUtf8("COM_5524"))
 77         self.horizontalLayout_6.addWidget(self.COM_5524)
 78         self.COM_5520 = QtGui.QSpinBox(self.widget1)
 79         self.COM_5520.setMaximum(500)
 80         self.COM_5520.setProperty("value", 1)
 81         self.COM_5520.setObjectName(_fromUtf8("COM_5520"))
 82         self.horizontalLayout_6.addWidget(self.COM_5520)
 83         self.horizontalLayout_2.addLayout(self.horizontalLayout_6)
 84         self.widget2 = QtGui.QWidget(self.centralwidget)
 85         self.widget2.setGeometry(QtCore.QRect(10, 90, 120, 25))
 86         self.widget2.setObjectName(_fromUtf8("widget2"))
 87         self.horizontalLayout_7 = QtGui.QHBoxLayout(self.widget2)
 88         self.horizontalLayout_7.setMargin(0)
 89         self.horizontalLayout_7.setObjectName(_fromUtf8("horizontalLayout_7"))
 90         self.Equip_uut1 = QtGui.QCheckBox(self.widget2)
 91         self.Equip_uut1.setText(_fromUtf8(""))
 92         self.Equip_uut1.setObjectName(_fromUtf8("Equip_uut1"))
 93         self.horizontalLayout_7.addWidget(self.Equip_uut1)
 94         self.horizontalLayout_3 = QtGui.QHBoxLayout()
 95         self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
 96         self.COM_5521 = QtGui.QLabel(self.widget2)
 97         self.COM_5521.setObjectName(_fromUtf8("COM_5521"))
 98         self.horizontalLayout_3.addWidget(self.COM_5521)
 99         self.UUT1_COM = QtGui.QSpinBox(self.widget2)
100         self.UUT1_COM.setMinimum(1)
101         self.UUT1_COM.setMaximum(500)
102         self.UUT1_COM.setObjectName(_fromUtf8("UUT1_COM"))
103         self.horizontalLayout_3.addWidget(self.UUT1_COM)
104         self.horizontalLayout_7.addLayout(self.horizontalLayout_3)
105         self.widget3 = QtGui.QWidget(self.centralwidget)
106         self.widget3.setGeometry(QtCore.QRect(10, 110, 120, 25))
107         self.widget3.setObjectName(_fromUtf8("widget3"))
108         self.horizontalLayout_8 = QtGui.QHBoxLayout(self.widget3)
109         self.horizontalLayout_8.setMargin(0)
110         self.horizontalLayout_8.setObjectName(_fromUtf8("horizontalLayout_8"))
111         self.Equip_uut2 = QtGui.QCheckBox(self.widget3)
112         self.Equip_uut2.setText(_fromUtf8(""))
113         self.Equip_uut2.setObjectName(_fromUtf8("Equip_uut2"))
114         self.horizontalLayout_8.addWidget(self.Equip_uut2)
115         self.horizontalLayout_4 = QtGui.QHBoxLayout()
116         self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
117         self.COM_5522 = QtGui.QLabel(self.widget3)
118         self.COM_5522.setObjectName(_fromUtf8("COM_5522"))
119         self.horizontalLayout_4.addWidget(self.COM_5522)
120         self.UUT2_COM = QtGui.QSpinBox(self.widget3)
121         self.UUT2_COM.setMinimum(1)
122         self.UUT2_COM.setMaximum(500)
123         self.UUT2_COM.setObjectName(_fromUtf8("UUT2_COM"))
124         self.horizontalLayout_4.addWidget(self.UUT2_COM)
125         self.horizontalLayout_8.addLayout(self.horizontalLayout_4)
126         self.widget4 = QtGui.QWidget(self.centralwidget)
127         self.widget4.setGeometry(QtCore.QRect(10, 130, 120, 25))
128         self.widget4.setObjectName(_fromUtf8("widget4"))
129         self.horizontalLayout_9 = QtGui.QHBoxLayout(self.widget4)
130         self.horizontalLayout_9.setMargin(0)
131         self.horizontalLayout_9.setObjectName(_fromUtf8("horizontalLayout_9"))
132         self.Equip_uut3 = QtGui.QCheckBox(self.widget4)
133         self.Equip_uut3.setText(_fromUtf8(""))
134         self.Equip_uut3.setObjectName(_fromUtf8("Equip_uut3"))
135         self.horizontalLayout_9.addWidget(self.Equip_uut3)
136         self.horizontalLayout_5 = QtGui.QHBoxLayout()
137         self.horizontalLayout_5.setObjectName(_fromUtf8("horizontalLayout_5"))
138         self.COM_5523 = QtGui.QLabel(self.widget4)
139         self.COM_5523.setObjectName(_fromUtf8("COM_5523"))
140         self.horizontalLayout_5.addWidget(self.COM_5523)
141         self.UUT3_COM = QtGui.QSpinBox(self.widget4)
142         self.UUT3_COM.setMinimum(1)
143         self.UUT3_COM.setMaximum(500)
144         self.UUT3_COM.setObjectName(_fromUtf8("UUT3_COM"))
145         self.horizontalLayout_5.addWidget(self.UUT3_COM)
146         self.horizontalLayout_9.addLayout(self.horizontalLayout_5)
147         ElectricalCalibration.setCentralWidget(self.centralwidget)
148         self.Clear_msg = QtGui.QPushButton(self.centralwidget)
149         self.Clear_msg.setGeometry(QtCore.QRect(500, 250, 93, 28))
150         self.Clear_msg.setObjectName(_fromUtf8("Clear_msg"))
151         self.menubar = QtGui.QMenuBar(ElectricalCalibration)
152         self.menubar.setGeometry(QtCore.QRect(0, 0, 650, 26))
153         self.menubar.setObjectName(_fromUtf8("menubar"))
154         ElectricalCalibration.setMenuBar(self.menubar)
155         self.statusbar = QtGui.QStatusBar(ElectricalCalibration)
156         self.statusbar.setObjectName(_fromUtf8("statusbar"))
157         ElectricalCalibration.setStatusBar(self.statusbar)
158 
159         self.retranslateUi(ElectricalCalibration)
160         self.CalibrationFunction.setCurrentIndex(-1)
161         QtCore.QMetaObject.connectSlotsByName(ElectricalCalibration)
162 
163     def retranslateUi(self, ElectricalCalibration):
164         ElectricalCalibration.setWindowTitle(_translate("ElectricalCalibration", "MainWindow", None))
165         self.label.setText(_translate("ElectricalCalibration", "COM", None))
166         self.label_3.setText(_translate("ElectricalCalibration", "Select_Func", None))
167         #self.Begin_Calibration.setText(_translate("ElectricalCalibration", "Calibration", None))
168         self.Begin_Calibration.setText(_translate("ElectricalCalibration", "Cal Test", None))
169         self.label_2.setText(_translate("ElectricalCalibration", "UUT_Number", None))
170         self.COM_5524.setText(_translate("ElectricalCalibration", "5520", None))
171         self.COM_5521.setText(_translate("ElectricalCalibration", "UUT1", None))
172         self.COM_5522.setText(_translate("ElectricalCalibration", "UUT2", None))
173         self.COM_5523.setText(_translate("ElectricalCalibration", "UUT3", None))
174         self.Clear_msg.setText(_translate("ElectricalCalibration", "Clear", None))
View Code

Wolf_Electric.py

 1 # -*- coding: utf-8 -*-
 2 
 3 import sys
 4 from PyQt4.QtGui import *
 5 from PyQt4.QtCore import *
 6 import Wolf_Electric_UI
 7 #import Wolf_electrical_cal
 8 import Wolf_threads
 9 import time
10 import datetime
11 
12  
13 class MyApp(QMainWindow,Wolf_Electric_UI.Ui_ElectricalCalibration):
14     def __init__(self,parent=None):
15         super(MyApp, self).__init__(parent)
16         self.setupUi(self)
17         self.setWindowTitle( "Wolf" )
18         # set Log_write readonly
19         self.Log_write.setReadOnly(True)
20         self.CalibrationFunction.addItem("C_cal")
21         self.CalibrationFunction.addItem("V_cal")
22         self.CalibrationFunction.addItem("C_Test")
23         self.CalibrationFunction.addItem("V_Test")
24         self.Equip_5520.setChecked(True)
25 
26         QTextCodec.setCodecForTr(QTextCodec.codecForName("system"))
27         QTextCodec.setCodecForCStrings(QTextCodec.codecForName("system"))
28         QTextCodec.setCodecForLocale(QTextCodec.codecForName("system"))
29         #self.Begin_Calibration.clicked.connect(self.bigwork)
30         self.Begin_Calibration.clicked.connect(self.begin)
31         self.Clear_msg.clicked.connect(self.clear)
32     def  clear(self):
33         self.Log_write.setText("")
34     def bigwork(self):
35         from Wolf_threads import MyThread
36         self.testthread = MyThread(int(9))
37         self.testthread.start()
38         #self.Begin_Calibration.setDisabled(True)
39     def begin(self):
40         # disable button
41         self.Begin_Calibration.setDisabled(True)
42         #get UUT NUMBER
43         UUT_Num = int(self.UUT_NUMBER.value())
44 
45         #get com
46         COM_5520 = self.COM_5520.value()
47         UUT1_COM = self.UUT1_COM.value()
48         UUT2_COM = self.UUT2_COM.value()
49         UUT3_COM = self.UUT3_COM.value()
50 
51         #get Cal Function
52         Switch_Func = self.CalibrationFunction.currentText()
53         
54         Equip5520_state = self.Equip_5520.isChecked()
55         UUT1_state = self.Equip_uut1.isChecked()
56         UUT2_state = self.Equip_uut2.isChecked()
57         UUT3_state = self.Equip_uut3.isChecked()
58 
59         from Wolf_threads import MyThread
60         self.testthread = MyThread(Switch_Func,
61                                    UUT_Num,
62                                    COM_5520,UUT1_COM,UUT2_COM,UUT3_COM,
63                                    Equip5520_state,UUT1_state,UUT2_state,UUT3_state)
64         # connect sub thread single
65         self.testthread.FinishSignal.connect(self.end)
66         self.testthread.start()
67         
68     def end(self,show_message):
69         C_time = datetime.datetime.now()
70         show_message = C_time.strftime('%y-%m-%d %I:%M:%S ') +":" + show_message
71         self.Log_write.append(show_message)
72         #self.Log_write.append('\n')
73 
74         # recover button
75         #Rex_Rsp = r'[-]?\d+over!'
76         if(('complete' in show_message) or ('Electrical' in show_message) ):
77             self.Begin_Calibration.setDisabled(False)
78         #if(str == "Current cal complete!" or str == "Current test complete!" or str == "Volt cal complete!" or str == "Voltage test complete!"):
79         #    self.Begin_Calibration.setDisabled(False)
80         
81  
82 if __name__ == "__main__":
83     app = QApplication(sys.argv)
84     window  = MyApp()
85     window .show()
86     sys.exit(app.exec_())
View Code

Wolf_threads.py

 1 # -*- coding: utf-8 -*-
 2 
 3 from PyQt4 import QtCore, QtGui
 4 import time
 5 import Wolf_Electrical_cal_test
 6 
 7 class MyThread(QtCore.QThread):
 8     # statement a signal and return a str
 9     FinishSignal = QtCore.pyqtSignal(str) 
10     def __init__(self,Switch_Func,
11                  UUT_Num,
12                  COM_5520,UUT1_COM,UUT2_COM,UUT3_COM,
13                  Equip5520_state,UUT1_state,UUT2_state,UUT3_state,
14                  parent=None):
15         super(MyThread,self).__init__(parent)
16         self.Switch_Func = Switch_Func
17         self.UUT_Num = UUT_Num
18         self.COM_5520 = COM_5520
19         self.UUT1_COM = UUT1_COM
20         self.UUT2_COM = UUT2_COM
21         self.UUT3_COM = UUT3_COM
22         self.Equip5520_state = Equip5520_state
23         self.UUT1_state = UUT1_state
24         self.UUT2_state = UUT2_state
25         self.UUT3_state = UUT3_state
26         #pass
27         
28     def run(self):
29         #print ("=============")
30         
31         if(self.Switch_Func == 'C_cal'):
32             self.FinishSignal.emit("Current cal begin!")
33             s = Wolf_Electrical_cal_test.Current_Calibration(self.UUT_Num,self.COM_5520,self.UUT1_COM,self.UUT2_COM,self.UUT3_COM,self.Equip5520_state,
34                                                     self.UUT1_state,self.UUT2_state,self.UUT3_state)
35             self.FinishSignal.emit(s)
36             #self.FinishSignal.emit("Current cal over!")
37 
38         if(self.Switch_Func == 'V_cal'):
39             self.FinishSignal.emit("Voltage cal begin!")
40             s = Wolf_Electrical_cal_test.Voltage_Calibration(self.UUT_Num,self.COM_5520,self.UUT1_COM,self.UUT2_COM,self.UUT3_COM,self.Equip5520_state,
41                                                     self.UUT1_state,self.UUT2_state,self.UUT3_state)
42             self.FinishSignal.emit(s)
43             #self.FinishSignal.emit("Voltage cal over!")
44 
45         if(self.Switch_Func == 'C_Test'):
46             self.FinishSignal.emit("Current test begin!")
47             s = Wolf_Electrical_cal_test.Current_Test(self.UUT_Num,self.COM_5520,self.UUT1_COM,self.UUT2_COM,self.UUT3_COM,self.Equip5520_state,
48                                              self.UUT1_state,self.UUT2_state,self.UUT3_state)
49             self.FinishSignal.emit(s)
50             #self.FinishSignal.emit("Current test over!")
51 
52         if(self.Switch_Func == 'V_Test'):
53             self.FinishSignal.emit("Voltage test begin!")
54             s = Wolf_Electrical_cal_test.Voltage_Test(self.UUT_Num,self.COM_5520,self.UUT1_COM,self.UUT2_COM,self.UUT3_COM,self.Equip5520_state,
55                                              self.UUT1_state,self.UUT2_state,self.UUT3_state)
56             self.FinishSignal.emit(s)
57             #self.FinishSignal.emit("Voltage test over!")
58 
59         #self.FinishSignal.emit("")
View Code

Wolf_Electrical_cal_test.py

  1 #!/usr/bin/env python
  2 # -*- coding: utf-8 -*-   
  3 import datetime
  4 import time
  5 import sys
  6 import Wolf_device
  7 
  8 
  9 Cal_Cur_List = ['0.4','24']
 10 Cal_Volt_List = ['0m','30']
 11 Test_Volt_List = ['0','3','6','9','12','15','18','21','24','27','30']
 12 Test_Cur_List = ['0','0.4','2.4','4.8','7.2','9.6','12','14.4','16.8','19.2','21.6','24']
 13 Wait_5520_Steady = 10
 14 #保存文件路径及名称
 15 File_Name = 'wolf_Electrical_performance.csv'
 16 
 17 def SEND_Command(uut_dev_in, CMD):
 18     uut_dev_in.write(CMD)
 19 def uut_get_val(uut_dev_in, cmd):      #[0-9]\d*\.\d+$     r'[- ][0-9]{1,5}\.[0-9]{2,3}'
 20     Rex_Rsp = r'[-]?\d+\.[0-9]{3}'
 21     m = uut_dev_in.trx(cmd,Rex_Rsp)
 22     print ("m = %s")% m.group(0)
 23     return float(m.group(0))
 24     
 25 def Current_Calibration(UUT_Num,COM_5520,UUT1_COM,UUT2_COM,UUT3_COM,Equip5520_state,UUT1_state,UUT2_state,UUT3_state):
 26     DUT_Num = UUT_Num
 27     ComList = ["COM"+str(COM_5520),"COM"+str(UUT1_COM),"COM"+str(UUT2_COM),"COM"+str(UUT3_COM)]
 28 
 29     try:
 30         if(Equip5520_state == True):
 31             Equip_5520COM_001 = Wolf_device.SerialDevice(False, True, port = ComList[0], baudrate = 9600)
 32         if(UUT1_state == True):
 33             UUT1_COM = Wolf_device.SerialDevice(False, True, port = ComList[1], baudrate = 9600)
 34             SEND_Command(UUT1_COM,'imeas\n')
 35             SEND_Command(UUT1_COM,'imeas\n')
 36             SEND_Command(UUT1_COM,"iref[0] 0.4\n")
 37             SEND_Command(UUT1_COM,"iref[1] 24\n")
 38         if(UUT2_state == True):
 39             UUT2_COM = Wolf_device.SerialDevice(False, True, port = ComList[2], baudrate = 9600)
 40             SEND_Command(UUT2_COM,'imeas\n')
 41             SEND_Command(UUT2_COM,'imeas\n')
 42             SEND_Command(UUT2_COM,"iref[0] 0.4\n")
 43             SEND_Command(UUT2_COM,"iref[1] 24\n") 
 44         if(UUT2_state == True):
 45             UUT3_COM = Wolf_device.SerialDevice(False, True, port = ComList[3], baudrate = 9600)
 46             SEND_Command(UUT3_COM,'imeas\n')
 47             SEND_Command(UUT3_COM,'imeas\n')
 48             SEND_Command(UUT3_COM,"iref[0] 0.4\n")
 49             SEND_Command(UUT3_COM,"iref[1] 24\n")
 50     except Exception as e:
 51         return str(e) + "Wolf_Electrical_cal_test.py:line50"
 52 
 53     
 54     # STBY 5520
 55     print ("5520 STBY!")
 56     SEND_Command(Equip_5520COM_001,'STBY\n')
 57     time.sleep(2)
 58    
 59     #5520控制电流输出
 60     for i in range(0,len(Cal_Cur_List)):
 61         SEND_Command(Equip_5520COM_001,'*CLS; OUT '+Cal_Cur_List[i]+'mA; OPER\n')
 62         print ("5520 output %s mA and Wait %d s steady!")% (Cal_Cur_List[i],Wait_5520_Steady)
 63         time.sleep(Wait_5520_Steady)
 64 
 65         ICAL_POINT = "ICAL_POINT[" + str(i) + "]\n"
 66         print ("ICAL_POINT = %s") % ICAL_POINT
 67         if(UUT1_state == True):
 68             SEND_Command(UUT1_COM,ICAL_POINT)
 69         if(UUT2_state == True):
 70             SEND_Command(UUT2_COM,ICAL_POINT)
 71         if(UUT3_state == True):
 72             SEND_Command(UUT3_COM,ICAL_POINT)
 73         time.sleep(2)
 74     
 75     print ("Store the calibration parameters!")
 76     if(UUT1_state == True):
 77         SEND_Command(UUT1_COM,"TEMP_CAL_STORE\n")
 78     if(UUT2_state == True):
 79             SEND_Command(UUT2_COM,"TEMP_CAL_STORE\n")
 80     if(UUT3_state == True):
 81         SEND_Command(UUT3_COM,"TEMP_CAL_STORE\n")
 82 
 83     #Equip_5520_STBY()
 84     print ("5520 STBY!")
 85     SEND_Command(Equip_5520COM_001,'STBY\n')
 86     print ("Current cal complete!")
 87     return "Current cal complete!"
 88 
 89 def Current_Test(UUT_Num,COM_5520,UUT1_COM,UUT2_COM,UUT3_COM,Equip5520_state,UUT1_state,UUT2_state,UUT3_state):
 90     DUT_Num = UUT_Num
 91     ComList = ["COM"+str(COM_5520),"COM"+str(UUT1_COM),"COM"+str(UUT2_COM),"COM"+str(UUT3_COM)]
 92     try:
 93         if(Equip5520_state == True):
 94             Equip_5520COM_001 = Wolf_device.SerialDevice(False, True, port = ComList[0], baudrate = 9600)
 95         if(UUT1_state == True):
 96             UUT1_COM = Wolf_device.SerialDevice(False, True, port = ComList[1], baudrate = 9600)
 97             SEND_Command(UUT1_COM,'imeas\n')
 98             SEND_Command(UUT1_COM,'imeas\n')
 99         if(UUT2_state == True):
100             UUT2_COM = Wolf_device.SerialDevice(False, True, port = ComList[2], baudrate = 9600)
101             SEND_Command(UUT2_COM,'imeas\n')
102             SEND_Command(UUT2_COM,'imeas\n')
103         if(UUT3_state == True):
104             UUT3_COM = Wolf_device.SerialDevice(False, True, port = ComList[3], baudrate = 9600)
105             SEND_Command(UUT3_COM,'imeas\n')
106             SEND_Command(UUT3_COM,'imeas\n')
107     except Exception as e:
108         return str(e) + "Wolf_Electrical_cal_test.py:line103"
109 
110     # STBY 5520
111     print ("5520 STBY!")
112     SEND_Command(Equip_5520COM_001,'STBY\n')
113     time.sleep(3)
114 
115     try:
116         fp = open(File_Name,'a')
117     except IOError as e:
118         return str(e) + "\n please close wolf_Electrical_performance.csv"
119     #5520控制电流输出
120     for i in range(0,len(Test_Cur_List)):
121         SEND_Command(Equip_5520COM_001,'*CLS; OUT '+Test_Cur_List[i]+'mA; OPER\n')
122         print ("5520 output %s mA and Wait %d s steady!")% (Test_Cur_List[i],Wait_5520_Steady)
123         time.sleep(Wait_5520_Steady)
124 
125         t = datetime.datetime.now()
126         uut_001 = ''
127         uut_002 = ''
128         uut_003 = ''        
129 
130         if(UUT1_state == True):
131             uut_001 = uut_get_val(UUT1_COM,"EVAL?\n")
132         if(UUT2_state == True):
133             uut_002 = uut_get_val(UUT2_COM,"EVAL?\n")
134         if(UUT2_state == True):
135             uut_003 = uut_get_val(UUT3_COM,"EVAL?\n")
136         time.sleep(2)
137         uut_reading = '%s,%s,%s,%s \n'%(t,uut_001,uut_002,uut_003)
138         fp.write(uut_reading)
139     
140     fp.close()
141     print ("5520 STBY!")
142     SEND_Command(Equip_5520COM_001,'STBY\n')
143     print ("Current test complete!")
144     return "Current test complete!"
145 
146 
147 def Voltage_Calibration(UUT_Num,COM_5520,UUT1_COM,UUT2_COM,UUT3_COM,Equip5520_state,UUT1_state,UUT2_state,UUT3_state):
148     DUT_Num = UUT_Num
149     ComList = ["COM"+str(COM_5520),"COM"+str(UUT1_COM),"COM"+str(UUT2_COM),"COM"+str(UUT3_COM)]
150 
151     try:
152         if(Equip5520_state == True):
153             Equip_5520COM_001 = Wolf_device.SerialDevice(False, True, port = ComList[0], baudrate = 9600)
154         if(UUT1_state == True):
155             UUT1_COM = Wolf_device.SerialDevice(False, True, port = ComList[1], baudrate = 9600)
156             SEND_Command(UUT1_COM,'vmeas\n')
157             SEND_Command(UUT1_COM,'vmeas\n')
158             SEND_Command(UUT1_COM,"vref[0] 0\n")
159             SEND_Command(UUT1_COM,"vref[1] 30\n")
160         if(UUT2_state == True):
161             UUT2_COM = Wolf_device.SerialDevice(False, True, port = ComList[2], baudrate = 9600)
162             SEND_Command(UUT2_COM,'vmeas\n')
163             SEND_Command(UUT2_COM,'vmeas\n')
164             SEND_Command(UUT2_COM,"vref[0] 0\n")
165             SEND_Command(UUT2_COM,"vref[1] 30\n") 
166         if(UUT3_state == True):
167             UUT3_COM = Wolf_device.SerialDevice(False, True, port = ComList[3], baudrate = 9600)
168             SEND_Command(UUT3_COM,'vmeas\n')
169             SEND_Command(UUT3_COM,'vmeas\n')
170             SEND_Command(UUT3_COM,"vref[0] 0\n")
171             SEND_Command(UUT3_COM,"vref[1] 30\n")
172     except Exception as e:
173         return str(e) + "Wolf_Electrical_cal_test.py:line161"
174     # STBY 5520
175     print ("5520 STBY!")
176     SEND_Command(Equip_5520COM_001,'STBY\n')
177     time.sleep(2)
178    
179     #5520控制电压输出
180     for i in range(0,len(Cal_Volt_List)):
181         SEND_Command(Equip_5520COM_001,'*CLS; OUT '+ Cal_Volt_List[i]+'V; OPER\n')
182         print ("5520 output %s V and Wait %d s steady!")% (Cal_Volt_List[i],Wait_5520_Steady)
183         time.sleep(Wait_5520_Steady)
184 
185         VCAL_POINT = "VCAL_POINT[" + str(i) + "]\n"
186         print ("VCAL_POINT = %s") % VCAL_POINT
187         if(UUT1_state == True):
188             SEND_Command(UUT1_COM,VCAL_POINT)
189         if(UUT2_state == True):
190             SEND_Command(UUT2_COM,VCAL_POINT)
191         if(UUT3_state == True):
192             SEND_Command(UUT3_COM,VCAL_POINT)
193         time.sleep(3)
194     
195     print ("Store the calibration parameters!")
196     if(UUT1_state == True):
197         SEND_Command(UUT1_COM,"TEMP_CAL_STORE\n")
198     if(UUT2_state == True):
199             SEND_Command(UUT2_COM,"TEMP_CAL_STORE\n")
200     if(UUT3_state == True):
201         SEND_Command(UUT3_COM,"TEMP_CAL_STORE\n")
202 
203     #Equip_5520_STBY()
204     print ("5520 STBY!")
205     SEND_Command(Equip_5520COM_001,'STBY\n')
206     print ("Volt cal complete!")
207     return "Volt cal complete!"
208 
209 def Voltage_Test(UUT_Num,COM_5520,UUT1_COM,UUT2_COM,UUT3_COM,Equip5520_state,UUT1_state,UUT2_state,UUT3_state):
210     DUT_Num = UUT_Num
211     ComList = ["COM"+str(COM_5520),"COM"+str(UUT1_COM),"COM"+str(UUT2_COM),"COM"+str(UUT3_COM)]
212 
213     try:
214         if(Equip5520_state == True):
215             Equip_5520COM_001 = Wolf_device.SerialDevice(False, True, port = ComList[0], baudrate = 9600)
216         if(UUT1_state == True):
217             UUT1_COM = Wolf_device.SerialDevice(False, True, port = ComList[1], baudrate = 9600)
218             SEND_Command(UUT1_COM,'vmeas\n')
219             SEND_Command(UUT1_COM,'vmeas\n')
220         if(UUT2_state == True):
221             UUT2_COM = Wolf_device.SerialDevice(False, True, port = ComList[2], baudrate = 9600)
222             SEND_Command(UUT2_COM,'vmeas\n')
223             SEND_Command(UUT2_COM,'vmeas\n')
224         if(UUT3_state == True):
225             UUT3_COM = Wolf_device.SerialDevice(False, True, port = ComList[3], baudrate = 9600)
226             SEND_Command(UUT3_COM,'vmeas\n')
227             SEND_Command(UUT3_COM,'vmeas\n')
228     except Exception as e:
229         return str(e) + "Wolf_Electrical_cal_test.py:line213"
230 
231     # STBY 5520
232     print ("5520 STBY!")
233     SEND_Command(Equip_5520COM_001,'STBY\n')
234     time.sleep(2)
235 
236     try:
237         fp = open(File_Name,'a')
238     except IOError as e:
239         return str(e) + "\n please close wolf_Electrical_performance.csv"
240     #5520控制电流输出
241     for i in range(0,len(Test_Volt_List)):
242         SEND_Command(Equip_5520COM_001,'*CLS; OUT '+Test_Volt_List[i]+'V; OPER\n')
243         print ("5520 output %s V and Wait %d s steady!")% (Test_Volt_List[i],Wait_5520_Steady)
244         time.sleep(Wait_5520_Steady)
245 
246         t = datetime.datetime.now()
247         uut_001 = ''
248         uut_002 = ''
249         uut_003 = ''        
250 
251         if(UUT1_state == True):
252             uut_001 = uut_get_val(UUT1_COM,"EVAL?\n")
253         if(UUT2_state == True):
254             uut_002 = uut_get_val(UUT2_COM,"EVAL?\n")
255         if(UUT3_state == True):
256            uut_003 = uut_get_val(UUT3_COM,"EVAL?\n")
257         time.sleep(2)
258         uut_reading = '%s,%s,%s,%s \n'%(t,uut_001,uut_002,uut_003)
259         fp.write(uut_reading)
260     
261     fp.close()
262     print ("5520 STBY!")
263     SEND_Command(Equip_5520COM_001,'STBY\n')
264     print ("Voltage test complete!")
265     return "Voltage test complete!"
View Code

Wolf_device.py

 1 '''
 2     Document string:
 3 '''
 4 import re
 5 
 6 import sys
 7 import time
 8 import serial
 9 
10 class SerialDevice(serial.Serial):
11     def __init__(self, tx_log=False, rx_log=False, *args, **kwargs):
12         self.tx_log = tx_log
13         self.rx_log = rx_log
14         serial.Serial.__init__(self, *args, **kwargs)
15         self.setTimeout(0.1)
16         self.setWriteTimeout(1.0)
17 
18     def read(self, size=1):
19         '''
20             Document string:
21         '''
22         data = serial.Serial.read(self, size)
23         if self.rx_log:
24             #sys.stdout.write(data)
25             i =1
26         return data
27 
28     def write(self, data):
29         '''
30             Document string:
31         '''
32         #print 'data = %s' % data
33         serial.Serial.write(self, data)
34         if self.tx_log:
35             sys.stdout.write(data)
36         return
37 
38     def trx(self, omsg, imsgs, delay=0, trx_wait = 2):
39         '''
40             Document string:
41         '''
42         if omsg:
43             self.write(omsg)
44         start = time.clock()
45         if type(imsgs) == type('str'):
46             imsgs = (imsgs, )
47         for imsg in imsgs:
48             line = ''
49             m = None
50             while True:
51                 line = line + self.read()
52                 #print (line)
53                 m = re.search(imsg, line)
54                 if m: 
55                     #print m.group(0)
56                     break
57                 now = time.clock()
58                 if (now - start) > trx_wait:
59                     raise Exception("trx timeout")
60         time.sleep(delay)
61         return m
View Code

 

posted @ 2017-09-07 10:11  njuptlwh  阅读(726)  评论(0编辑  收藏  举报