From 746f4bfda509bd2bddb5583123db8a6003db9751 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 15 Nov 2024 10:06:55 +0100 Subject: [PATCH] update: relay control --- __pycache__/sainsmartrelay.cpython-311.pyc | Bin 0 -> 3439 bytes bjoerntest10.py | 54 +++++++++++++++++++++ sainsmartrelay.py | 53 ++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 __pycache__/sainsmartrelay.cpython-311.pyc create mode 100644 sainsmartrelay.py diff --git a/__pycache__/sainsmartrelay.cpython-311.pyc b/__pycache__/sainsmartrelay.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ee29d68f90b3ade013e1b744e1efaec033b4b629 GIT binary patch literal 3439 zcmd^BO-vg{6rTM9vp6h)I0OS>2?@mswvk97%1@=FA!%|zQK3>|saYBCn%LNDI=fDY z<+Lcu0Y#M>Rgpk#qjG3z5UJE-k4>c>EA66fgH}SSRP~UXBXWpx>YKH_u!dHx)LWmu zZ)fJsd-L9#Z{F-Td-m`MsOTS=nyf?Uchad6S7~gXpb%O>GLoqbiXj?ZL^6F3$;>j1 z&?-D-ictzJv(ru=-=&d4ErVdSDn>B|##n_}s@ioWq#<+5u*xbtW%BkYSk=)5A9s>m z=bi2Cxw`c`H4*aq_!pYKf3GQ1y;kPUe8u$&GS7Na|%D^n7vy*!9~@*LWIxvUbM zOy?A=MyFDG^rDi|GAVUR!B=oDtt9lQ*Ne!^ZQCbFDK(`_QlZW3a-=F?$r^ir&7t++ z;d%CBVIF>)Fn~N^5MP`y1|3K?Al(HFLTR@xLwIR7{3*If6+lrZ<|>pXRvg-WRHkM6 z39}4PU3KAlhc41-;;BQs!`KU_an$Qw)rIe2gpc20bfIbu4ggzZ(k{^ciS^IXBf1u_ z*Wj4mVLoKYmX=$$s9R{3xrT00A#Mz|G%x2SLabe<>2fZwJ8uPJo7I(B-R2TEl*DwQ zeiY*zJ}HJ8Y+lPx&fr`^(KMUEdDVe~&0e{5WfV7o_co{LI5lIpyd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oerntest10.py b/bjoerntest10.py index ffb7cff..3b3e170 100644 --- a/bjoerntest10.py +++ b/bjoerntest10.py @@ -28,6 +28,8 @@ import cv2 import os +import sainsmartrelay + # db_config = { # 'user': 'dbUser', # 'password': 'dbPassword', @@ -459,6 +461,14 @@ class Ui_MainWindow(object): self.graphicsView.setGeometry(QtCore.QRect(10, int(1080/2), 661, int(480*1.05))) # position and size of camera frame # int(640*1.05) self.graphicsView.setObjectName("graphicsView") + # relay control + self.startSpotlightBtn = QtWidgets.QPushButton(self.centralwidget) + self.startSpotlightBtn.setGeometry(QtCore.QRect(700+200, int(1080/2)+100, 161, 25)) #int(1080/2)+100 + self.startSpotlightBtn.setObjectName("startSpotlightBtn") + self.stopSpotlightBtn = QtWidgets.QPushButton(self.centralwidget) + self.stopSpotlightBtn.setGeometry(QtCore.QRect(700+200, int(1080/2)+150, 161, 25)) + self.stopSpotlightBtn.setObjectName("stopSpotlightBtn") + #self.myTestLambda = lambda: self.worker.checkWaageStartSignal.emit(einzelteilID, self.teileZuViel, self.auftragsnummer) ''' @@ -561,6 +571,10 @@ class Ui_MainWindow(object): self.camWorkFlowcheckBox.setText(_translate("MainWindow", "Camera Workflow")) # self.camWorkFlowcheckBox.clicked.connect(self.onCheckboxCheck) self.modelComboBox + + # relay control + self.startSpotlightBtn.setText(_translate("MainWindow", "Turn on light")) + self.stopSpotlightBtn.setText(_translate("MainWindow", "Turn off light")) @@ -1045,6 +1059,46 @@ class CameraStreamApp(QtWidgets.QMainWindow): self.yolo_stream.cap.release() event.accept() +# new class for relay control +class RelayControl(QtWidgets.QMainWindow): + def __init__(self, ui): + super().__init__() + self.ui = ui + # self.timer = QtCore.QTimer(self) + # self.timer.timeout.connect(self.update_frame) + + # # Populate the model dropdown menu + # self.populate_model_dropdown() + + self.ui.startSpotlightBtn.clicked.connect(self.spot_on) + self.ui.stopSpotlightBtn.clicked.connect(self.spot_off) + # self.scene = QtWidgets.QGraphicsScene(self) + # self.ui.graphicsView.setScene(self.scene) + + # def populate_model_dropdown(self): + # """Populate the dropdown menu with model files from the models directory.""" + # models_dir = "models" + # model_files = [f for f in os.listdir(models_dir) if f.endswith(".pt")] + # self.ui.modelComboBox.clear() + # self.ui.modelComboBox.addItems(model_files) + + def spot_on(self): + # Start the YOLOv8 camera stream (only if not already started) + # if self.yolo_stream is None: + # self.yolo_stream = YOLOv8CameraStream(model_path="models/yolov8m_seg_e300.pt", logging_level="high") + # # self.yolo_stream.start() # Start the YOLOv8 stream + # self.timer.start(30) # Start the timer to update the frame every 30ms (about 33 FPS) + sainsmartrelay.turn_on(1) + + def spot_off(self): + # # Stop the camera stream and processing + # if self.yolo_stream is not None: + # self.timer.stop() # Stop the timer + # self.yolo_stream.cap.release() # Release the camera resource + # self.yolo_stream = None # Reset the YOLOv8 stream object + # self.scene.clear() # Clear the displayed frame from the graphicsView + # print("Camera stream stopped and resources released.") + sainsmartrelay.turn_off(1) if __name__ == "__main__": import sys diff --git a/sainsmartrelay.py b/sainsmartrelay.py new file mode 100644 index 0000000..c021110 --- /dev/null +++ b/sainsmartrelay.py @@ -0,0 +1,53 @@ +import subprocess + +class SainsmartRelay: + def __init__(self, executable="sainsmartrelay"): + self.executable = executable + + def _run_command(self, args): + try: + result = subprocess.run( + ["sudo", self.executable] + args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + check=True + ) + return result.stdout.strip() + except subprocess.CalledProcessError as e: + print(f"Error: {e.stderr.strip()}") + return None + + def turn_on(self, relays): + """Turn on specified relays.""" + relays_str = ','.join(map(str, relays)) if isinstance(relays, (list, tuple)) else str(relays) + return self._run_command(["--on", relays_str]) + + def turn_off(self, relays): + """Turn off specified relays.""" + relays_str = ','.join(map(str, relays)) if isinstance(relays, (list, tuple)) else str(relays) + return self._run_command(["--off", relays_str]) + + def get_status(self, relays="all"): + """Get the status of specified relays.""" + return self._run_command(["--status", str(relays)]) + + def find_all_devices(self): + """Find all connected FTDI devices.""" + return self._run_command(["--findall"]) + +# Example usage: +if __name__ == "__main__": + relay = SainsmartRelay() + + # Turn on relay 1 + print(relay.turn_on(1)) + + # Turn off all relays + print(relay.turn_off("all")) + + # Get the status of all relays + print(relay.get_status()) + + # Find all FTDI devices + print(relay.find_all_devices())