st-ten-1/src/ui/test_pipe_cutter/test_pipe_cutter.py

95 lines
3.4 KiB
Python
Raw Normal View History

2025-01-17 14:14:28 +00:00
from PyQt5.QtGui import QMovie
import logging
from ui.test_test import Test_Test
2025-01-22 11:27:15 +00:00
import time
2025-01-22 14:21:08 +00:00
from PyQt5.QtCore import QByteArray
2025-01-17 14:14:28 +00:00
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class Test_Pipe_Cutter(Test_Test):
"""
A class to manage and operate a pipe cutter machine in a test environment.
"""
2025-01-21 09:51:06 +00:00
def __init__(self, config, components, recipe=None, run_once=False,reset_on_start=False, enable_override=False, bench_name="generic", step=None,):
2025-01-22 11:27:15 +00:00
super().__init__(components=components, recipe=recipe, step=step, run_once=run_once,reset_on_start=reset_on_start, enable_override=enable_override,)
2025-01-21 14:44:47 +00:00
self.config = config
2025-01-17 14:14:28 +00:00
self.bench_name = bench_name
2025-01-22 11:27:15 +00:00
self.step=step
self.current_cut_length = 0
self.get_connection = None
2025-01-21 14:44:47 +00:00
2025-01-22 14:21:08 +00:00
gif_path = "config/instruction_images/st-ten-10/pipe.gif"
self.movie = QMovie(gif_path,QByteArray(), self)
2025-01-22 11:27:15 +00:00
self.pipe_gif.setMovie(self.movie)
self.movie.start()
self.pipe_gif.setMovie(self.movie)
2025-01-17 14:14:28 +00:00
def start(self, recipe=None, step=None, pieces=None):
2025-01-22 11:27:15 +00:00
self.get_connection = self.components["pipe_cutter"].out.connect(self.get)
2025-01-21 14:44:47 +00:00
self.components["pipe_cutter"].resume()
2025-01-22 11:27:15 +00:00
show = super().start(recipe=recipe, step=step, pieces=pieces)
if show is False:
return show
2025-01-17 14:14:28 +00:00
if step is not None :
self.start_cutting()
self.stop_cutting()
2025-01-22 11:27:15 +00:00
return show
2025-01-17 14:14:28 +00:00
def start_cutting(self,recipe=None,step=None):
"""
Start the pipe cutting process and activate the pipe cutter component.
"""
2025-01-21 14:44:47 +00:00
self.current_status = self.components["pipe_cutter"]._get()
2025-01-22 11:27:15 +00:00
#print(f"current status is :{str(self.current_status)}")
#print(self.step.spec["lenght"])
2025-01-23 09:58:14 +00:00
self.lenght=self.step.spec["lenght"]
self.diameter=self.step.spec["diameter"]
2025-01-17 14:14:28 +00:00
if self.current_status == 102 : # ready for operation
try:
2025-01-22 11:27:15 +00:00
#self.reset_machine()
2025-01-23 09:58:14 +00:00
self.components["pipe_cutter"].write_total_length(self.lenght)
self.components["pipe_cutter"].write_od_of_pipe(self.diameter)
2025-01-22 11:27:15 +00:00
time.sleep(1)
2025-01-21 14:44:47 +00:00
self.components["pipe_cutter"].write_bit_with_delay(600,0,100)
2025-01-17 14:14:28 +00:00
except Exception as e:
logger.error(f"Failed to start the pipe cutting process: {e}")
else:
try:
2025-01-21 14:44:47 +00:00
self.components["pipe_cutter"].write_bit_with_delay(600, 1, 100) # resetting
2025-01-17 14:14:28 +00:00
except Exception as e:
logger.error(f"Failed to reset the pipe cutting process: {e}")
def stop_cutting(self):
"""
Stop the pipe cutting process and deactivate the pipe cutter component.
"""
try:
2025-01-21 14:44:47 +00:00
self.components["pipe_cutter"].write_bit_with_delay(600, 2, 100)
2025-01-22 11:27:15 +00:00
#self.reset_machine()
2025-01-17 14:14:28 +00:00
except Exception as e:
logger.error(f"Failed to stop the pipe cutting process: {e}")
2025-01-22 11:27:15 +00:00
def stop(self):
self.components["pipe_cutter"].pause()
self.disconnect(self.get_connection)
super().stop()
2025-01-17 14:14:28 +00:00
def reset_machine(self):
"""
Reset the pipe cutter machine to its initial state.
"""
try:
2025-01-21 14:44:47 +00:00
self.components["pipe_cutter"].write_bit_with_delay(600, 1, 100)
2025-01-17 14:14:28 +00:00
except Exception as e:
logger.error(f"Failed to reset the pipe cutter machine: {e}")