Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| modularpi:pyhmiprogramming:uimain_code:index [2026/02/15 02:36] – created admin | modularpi:pyhmiprogramming:uimain_code:index [2026/02/15 03:35] (current) – removed admin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | =====main.py==== | ||
| - | <code python> | ||
| - | import sys | ||
| - | import os | ||
| - | from PyQt5.QtWidgets import * | ||
| - | from PyQt5.QtGui import QPixmap | ||
| - | from PyQt5.QtCore import * | ||
| - | from PyQt5 import uic | ||
| - | from CFRASP import CFNET | ||
| - | |||
| - | # 파일 절대경로 (현재 디렉토리 기준) | ||
| - | current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
| - | |||
| - | # UI 파일 절대경로 (현재 디렉토리 기준) | ||
| - | ui_path = os.path.join(current_dir, | ||
| - | form_class = uic.loadUiType(ui_path)[0] | ||
| - | |||
| - | # 이미지 파일 절대경로 (현재 디렉토리 기준) | ||
| - | ON_IMG = os.path.join(current_dir, | ||
| - | OFF_IMG = os.path.join(current_dir, | ||
| - | |||
| - | # CFNET 객체 생성(CFIO 모듈 제어로직 객체) | ||
| - | cfnet = CFNET() | ||
| - | |||
| - | # 메인 윈도우 클래스 정의 | ||
| - | class MyWindow(QMainWindow, | ||
| - | def __init__(self): | ||
| - | super().__init__() | ||
| - | self.setupUi(self) | ||
| - | #타이머 설정 | ||
| - | self.timer = QTimer(self) | ||
| - | self.timer.setInterval(300) | ||
| - | self.timer.timeout.connect(self.update_value) | ||
| - | self.timer.start() | ||
| - | #초기 cfdio 상태 | ||
| - | self.outport_state = False | ||
| - | self.inport_state = False | ||
| - | self.port_OUT_0.clicked.connect(self.CFDO_0_click) | ||
| - | | ||
| - | # 입력 업데이트 (INPUT LAMP) | ||
| - | def update_value(self): | ||
| - | ###### !! CFNET CFDI 모듈 입력상태 읽기 !!###### | ||
| - | self.inport_state = cfnet.digitalRead(0, | ||
| - | ############################################### | ||
| - | if self.inport_state == False: | ||
| - | self.lamp_IN_0.setPixmap(QPixmap(OFF_IMG)) | ||
| - | else : | ||
| - | self.lamp_IN_0.setPixmap(QPixmap(ON_IMG)) | ||
| - | |||
| - | # 출력 버튼 클릭 이벤트 | ||
| - | def CFDO_0_click(self): | ||
| - | self.outport_state = not self.outport_state | ||
| - | ###### !! CFNET CFDO port 0 쓰기 | ||
| - | cfnet.digitalWrite(0, | ||
| - | ############################################### | ||
| - | if self.outport_state == True: | ||
| - | self.lamp_OUT_0.setPixmap(QPixmap(ON_IMG)) | ||
| - | else: | ||
| - | self.lamp_OUT_0.setPixmap(QPixmap(OFF_IMG)) | ||
| - | | ||
| - | if __name__ == " | ||
| - | print(" | ||
| - | app = QApplication(sys.argv) | ||
| - | mywindow = MyWindow() | ||
| - | mywindow.show() | ||
| - | app.exec_() | ||
| - | | ||
| - | |||
| - | </ | ||
