def test_stopspindle2(self): P[4100] = 1 th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "F11开始") th.msleep(6000) # 判断主轴已启动且同步 for i in range(basic.spindleCount()): assert F[71 + i] and F[81 + i] th.msleep(1000) th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "F12 停止") th.msleep(5000) assert F[3] # 判断主轴未启动且同步 for i in range(basic.spindleCount()): assert not F[71 + i] and F[81 + i] # 判断主轴转速为0 for i in range(basic.spindleCount()): assert R[191 + i] == 0 P[4100] = 0 th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "F11开始") th.msleep(6000) # 判断主轴已启动且同步 for i in range(basic.spindleCount()): assert F[71 + i] and F[81 + i] th.msleep(1000) th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "F12 停止") th.msleep(5000) assert F[3] # 判断主轴已启动且同步 for i in range(basic.spindleCount()): assert F[71 + i] and F[81 + i]
def test_AfterProcess(self): # 加工结束后回固定点 P[4001] = 0 th.msleep(500) th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "F11开始") th.msleep(35000) # 判断机床坐标等于固定点参数值 for i in range(basic.axisCount()): assert (round(R[101 + i] * BLU) == P[1601 + i] * mm) th.msleep(500) # 加工结束后回工件原点 P[4001] = 1 th.msleep(500) th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "F11开始") th.msleep(35000) # 判断X,Y工件坐标等于0,Z轴机床坐标等于固定点参数值 assert (R[121] == R[122] == 0) for a in range(basic.spindleCount()): assert round(R[103 + a] * BLU) == P[1603 + a] * mm # 加工结束后无附件动作 P[4001] = 2 th.msleep(500) th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "F11开始") th.msleep(35000) # 判断X,Y,Z工件坐标等于NC程序最后的X,Y,Z走的值 assert round(R[121] * BLU) == 0 * mm and round(R[122] * BLU, 3) == -62.375 * mm for b in range(basic.spindleCount()): assert round(R[123 + b] * BLU) == 5 * mm
def test_CheckToolSet(self): th.msleep(1000) th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "参数") th.msleep(1000) dlg = th.assertActiveWindow(ParamsDialog) th.msleep(500) P[4006] = 1 th.msleep(500) dlg.close() th.msleep(500) for i in range(basic.spindleCount()): R[31, i] = 0 th.msleep(1000) basic.start() th.msleep(2000) self.assertTrue(F[3]) th.msleep(500) P[4006] = 0 th.msleep(1000) basic.start() th.msleep(2000) self.assertFalse(F[3]) th.msleep(500) basic.stop() th.msleep(2000) self.assertTrue(F[3])
def test_SingleExec(self): # 加载测试NC程序 basic.loadProgram("E:/NC/自动测试程序/single_test.NC") th.msleep(500) th.clickButton(basic.mainWindow, "单段执行") th.msleep(500) th.clickButton(basic.mainWindow, "F11 开始") th.msleep(1000) # 判断是否处于单段保持状态 assert F[2] == 1 # 判断走完一行之后的坐标 assert R[101] == 100000000 and R[102] == -100000000 for i in range(basic.spindleCount()): assert R[103 + i] == -20000000 th.clickButton(basic.mainWindow, "F11 开始") th.msleep(1000) # 判断是否处于单段保持状态 assert F[2] == 1 # 判断走完一行之后的坐标 assert R[101] == 130000000 and R[102] == -100000000 for i in range(basic.spindleCount()): assert R[103 + i] == -20000000 th.clickButton(basic.mainWindow, "F11 开始") th.msleep(1000) # 判断是否处于单段保持状态 assert F[2] == 1 # 判断走完一行之后的坐标 assert R[101] == 130000000 and R[102] == -130000000 for i in range(basic.spindleCount()): assert R[103 + i] == -20000000 th.clickButton(basic.mainWindow, "F11 开始") th.msleep(1000) # 判断是否处于单段保持状态 assert F[2] == 1 # 判断走完一行之后的坐标 assert R[101] == 100000000 and R[102] == -130000000 for i in range(basic.spindleCount()): assert R[103 + i] == -20000000 th.clickButton(basic.mainWindow, "F11 开始") th.msleep(1000) # 判断是否处于单段保持状态 assert F[2] == 1 # 判断走完一行之后的坐标 assert R[101] == 100000000 and R[102] == -100000000 for i in range(basic.spindleCount()): assert R[103 + i] == -20000000 th.clickButton(basic.mainWindow, "F11 开始") th.msleep(1000) # 判断加工结束后,是否回到准备好状态 assert F[3] == 1 # 判断加工结束后,回到固定点 assert R[101] == R[102] == 0 for i in range(basic.spindleCount()): assert R[103 + i] == 0
def test_Auto_Home(self): # 检查是否开机后软件自动Home for i in range(basic.spindleCount()): R[43 + i] == 1 # 获取键盘 F[400] = True # 模拟Home信号按键 self.push_key() # 检查是否是Z先Home完成,XY再Home assert R[41] == 0 and R[42] == 0 for i in range(basic.spindleCount()): R[43 + i] == 1 self.push_key() # 检查是否都Home完成 assert R[41] == 1 and R[42] == 1 for i in range(basic.spindleCount()): R[43 + i] == 1 # 勾消重启软件后自动Home th.msleep(500) P[4138] = 0
def test_BackWPHome(self): # 设置xyz运动的距离为行程的一半 move_x = round((P[1501] + P[1521]) / 2) move_y = round((P[1502] + P[1522]) / 2) move_z = round((P[1503] + P[1523]) / 2) # XY轴先运动,Z轴再运动 basic.mdi("G90 G00 X{:.3f} Y{:.3f}".format(move_x / mm, move_y / mm)) th.msleep(8000) basic.mdi("G90 G53 G00 Z{:.3f}".format(move_z / mm)) th.msleep(3000) # 点击BackWPHome th.clickButton(basic.mainWindow, "BackWPHome") th.msleep(500) # Z工件坐标 wcs_z = round(move_z / BLU - R[143]) # 判断BackWPHome时“Z轴先抬高,XY轴不动 assert (R[121] == round(move_x / BLU)) and (R[122] == round( move_y / BLU)) for i in range(basic.spindleCount()): assert R[123 + i] != wcs_z th.msleep(3000) # Z工件坐标原点 wcs_origin_z = round(R[103] - R[143]) # 判断BackWPHome时“Z轴回到工件原点后,XY回再工件原点” assert (R[121] != round(move_x / BLU)) and (R[122] != round( move_y / BLU)) for i in range(basic.spindleCount()): assert R[123 + i] == wcs_origin_z th.msleep(6000) # 判断XYZ轴是否都回到工件原点 assert (R[121] == 0) and (R[121] == 0) for i in range(basic.spindleCount()): assert R[123 + i] == wcs_origin_z
def test_up_tool(self): P[4008] = 1 th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "F11开始") th.msleep(3000) # 判断Z轴机床坐标不为0 for i in range(basic.spindleCount()): assert round(R[103 + i] * BLU) != 0 * mm th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "暂停") th.msleep(200) assert F[1] # 判断Z轴进给速度不为0 for i in range(basic.spindleCount()): R[173 + i] != 0 th.msleep(6000) # 判断Z轴机床坐标为0 for i in range(basic.spindleCount()): assert round(R[103 + i] * BLU) == 0 * mm th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "F12 停止") th.msleep(1000) P[4008] = 0 th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "F11开始") th.msleep(5000) # 判断Z轴机床坐标不为0 for i in range(basic.spindleCount()): assert round(R[103 + i] * BLU) != 0 * mm th.msleep(1000) th.assertActiveWindow(basic.mainWindow) th.clickButton(basic.mainWindow, "暂停") th.msleep(500) assert F[1] # 判断Z轴进给速度为0且机床坐标不为0 for i in range(basic.spindleCount()): assert R[173 + i] == 0 and round(R[103 + i] * BLU) != 0 * mm
def test_BackFixesPt(self): # 设置xyz运动的距离为行程的一半 move_x = round((P[1501] + P[1521]) / 2) move_y = round((P[1502] + P[1522]) / 2) move_z = round((P[1503] + P[1523]) / 2) # XY轴先运动,Z轴再运动 basic.mdi("G90 G53 G01 X{:.3f} Y{:.3f}".format(move_x / mm, move_y / mm)) th.msleep(2000) basic.mdi("G90 G53 G01 Z{:.3f}".format(move_z / mm)) th.msleep(3000) # 点击BackFixesPt th.clickButton(basic.mainWindow, "BackFixesPt") th.msleep(500) # 判断BackFixesPt时“Z轴先抬高,XY轴不动 assert (R[101] == round(move_x / BLU)) and (R[102] == round( move_y / BLU)) for i in range(basic.spindleCount()): assert R[103 + i] != round(move_z / BLU) th.msleep(3000) # 判断BackFixesPt时“Z轴回到固定点后,XY回再固定点” assert (R[101] != round(move_x / BLU)) and (R[102] != round( move_y / BLU)) for i in range(basic.spindleCount()): assert R[103 + i] == round(-0.001 * mm / BLU) th.msleep(5000) # 判断XYZ轴是否都回到固定点 assert (R[101] == round(-0.001 * mm / BLU)) and (R[102] == round( -0.001 * mm / BLU)) for i in range(basic.spindleCount()): assert R[103 + i] == round(-0.001 * mm / BLU)
def test_AutoToolSet(self): # 获取键盘 F[400] = True # 单头机 if basic.spindleCount() == 1: th.clickButton(basic.mainWindow, "AutoToolSet") th.msleep(1000) msg = th.assertActiveWindow(QtWidgets.QMessageBox) th.msleep(500) th.clickButton(msg, "确定") th.msleep(500) # 点击完AutoToolSet,判断输出端口对刀吹气是否为ture assert Y[7] th.msleep(1500) # 判断XY是否到达对刀起始高度 assert R[101] == round(P[1621] / BLU, 1) and R[102] == round( P[1622] / BLU, 1) # 判断XYZ是否到达对刀起始高度后,关闭吹气 self.assertFalse(Y[7]) th.msleep(1000) F[590] = True # 判断对刀时,第一次触碰对刀信号后,Z轴抬高 th.msleep(200) v1 = R[103] th.msleep(200) v2 = R[103] assert v1 < v2 th.msleep(1000) F[590] = False th.msleep(500) F[590] = True th.msleep(500) F[590] = False th.msleep(2000) # 判断 取消AutoToolSet后 XYZ轴不动 v1_x = R[101] v1_y = R[102] v1_z = R[103] th.clickButton(basic.mainWindow, "AutoToolSet") th.msleep(1000) msg = th.assertActiveWindow(QtWidgets.QMessageBox) th.msleep(1000) th.clickButton(msg, "取消") v2_x = R[101] v2_y = R[102] v2_z = R[103] assert v1_x == v2_x and v1_y == v2_y and v1_z == v2_z else: # 多头机对刀 th.clickButton(basic.mainWindow, "AutoToolSet") th.msleep(1000) msg = th.assertActiveWindow(basic.AutomaticToolDialog) th.msleep(1000) th.clickButton(msg, "对刀开始") th.msleep(2000) # 判断XYZ是否到达对刀起始高度 assert R[101] == round(P[1621] / BLU, 1) and R[102] == round( P[1622] / BLU, 1) th.msleep(1000) F[590] = True # 判断对刀时,第一次触碰对刀信号后,Z轴抬高 th.msleep(200) v1 = R[103] th.msleep(200) v2 = R[103] assert v1 < v2 th.msleep(1000) F[590] = False th.msleep(500) F[590] = True th.msleep(1000) F[590] = False th.msleep(3000) # 不勾选所有Z轴 th.clickButton(basic.mainWindow, "AutoToolSet") th.msleep(1000) R[1007, random.randint(0, basic.spindleCount() - 1)] = 0 th.msleep(1000) msg = th.assertActiveWindow(basic.AutomaticToolDialog) th.clickButton(msg, "对刀开始") th.msleep(2000) F[590] = True th.msleep(1000) F[590] = False th.msleep(500) F[590] = True th.msleep(1000) F[590] = False th.msleep(3000)
def test_Manul_Home(self): # 获取键盘 F[400] = True # 将X寻原点方向设为1,YZ寻原点方向设为0 P[1701] = 1 for i in range(basic.axisCount() - 1): P[1702 + i] = 0 if P[4138] == 0: # 点击所有轴Home按钮 th.clickButton(self.homewindow, "所有轴Home") th.msleep(1000) # 判断是否是Z轴先Home assert R[41] == 1 and R[42] == 1 for i in range(basic.spindleCount()): R[43 + i] == 0 self.push_key() # 判断是否ZHome完成后,xy开始Home assert R[41] == 0 and R[42] == 0 for i in range(basic.spindleCount()): R[43 + i] == 1 self.push_key() # 判断xyZ是否都Home成功 assert R[41] == 1 and R[42] == 1 for i in range(basic.spindleCount()): R[43 + i] == 1 # 单轴Home # X轴Home th.clickButton(self.homewindow, "X 轴Home") th.msleep(1000) # 判断X轴Home方向 th.msleep(200) v1 = R[101] th.msleep(500) v2 = R[101] assert v1 > v2 th.msleep(500) F[588] = True th.msleep(500) F[588] = False # 判断粗定位完成后,X轴Home方向 th.msleep(200) v3 = R[101] th.msleep(200) v4 = R[101] assert v3 < v4 th.msleep(500) F[590] = True th.msleep(500) F[590] = False th.msleep(500) F[590] = True th.msleep(500) F[590] = False th.msleep(500) # Y轴Home th.clickButton(self.homewindow, "Y 轴Home") th.msleep(1000) # 判断Y轴Home方向 th.msleep(200) v1 = R[102] th.msleep(500) v2 = R[102] assert v1 < v2 th.msleep(500) F[588] = True th.msleep(500) F[588] = False # 判断粗定位完成后,Y轴Home方向 th.msleep(200) v3 = R[102] th.msleep(200) v4 = R[102] assert v3 > v4 th.msleep(500) F[590] = True th.msleep(500) F[590] = False th.msleep(500) F[590] = True th.msleep(500) F[590] = False th.msleep(500) # Z轴Home i = random.randint(1, basic.spindleCount()) th.clickButton(self.homewindow, "Z{} 轴Home".format(i)) th.msleep(1000) # 判断Z轴Home方向 th.msleep(200) v1 = R[102 + i] th.msleep(500) v2 = R[102 + i] assert v1 < v2 th.msleep(500) F[588] = True th.msleep(500) F[588] = False # 判断粗定位完成后,Z轴Home方向 th.msleep(200) v3 = R[102 + i] th.msleep(200) v4 = R[102 + i] assert v3 > v4 th.msleep(500) F[590] = True th.msleep(500) F[590] = False th.msleep(500) F[590] = True th.msleep(500) F[590] = False th.msleep(500) # 选择任意一个Z轴Home th.msleep(1000) th.clickButton( self.homewindow, "Z{} 轴Home".format(random.randint(1, basic.spindleCount()))) th.msleep(500) # 停止Home th.clickButton(basic.mainWindow, "F12 停止") # Z轴未Home的情况下,XHome th.msleep(500) th.clickButton(self.homewindow, "X 轴Home") th.msleep(500) msg = th.assertActiveWindow(QtWidgets.QMessageBox) th.clickButton(msg, "是(&Y)") self.push_key() # Z轴未Home的情况下,点击YHome并取消YHome th.msleep(500) th.clickButton(self.homewindow, "Y 轴Home") th.msleep(500) msg = th.assertActiveWindow(QtWidgets.QMessageBox) th.clickButton(msg, "否(&N)") # 勾选重启软件自动Home P[4138] = 1