-
Notifications
You must be signed in to change notification settings - Fork 0
feature | sprint2 | FRB-171 | 센서 포트 장치에서 읽어들이게 수정 | 정민석 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| from awscrt import mqtt | ||||||||||||||||||||||||||||||||||||||||||||||||||
| from service.simulation.SimulatorInterface2 import SimulatorInterface2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| from mqtt_util.publish import AwsMQTT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import serial.tools.list_ports | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| class RealSensor(SimulatorInterface2): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| def __init__(self, idx, zone_id, equip_id, interval, msg_count, conn=None, stop_event=None): | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -21,7 +22,7 @@ def __init__(self, idx, zone_id, equip_id, interval, msg_count, conn=None, stop_ | |||||||||||||||||||||||||||||||||||||||||||||||||
| self.topic_name_temp = self._build_topic(self.zone_id, self.equip_id, self.sensor_id, "temp") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.topic_name_humid = self._build_topic(self.zone_id, self.equip_id, self.sensor_id, "humid") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # 시리얼 포트 설정 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.serial_port = 'COM3' # Windows COM 포트 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.serial_port = self._find_serial_port() # Windows COM 포트 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.baudrate = 9600 # 바우드 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ######## 오버라이딩은 하되 내용은 필요없는 메서드 ######## | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -51,6 +52,27 @@ def start_publishing(self): | |||||||||||||||||||||||||||||||||||||||||||||||||
| thread.start() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return thread | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def _find_serial_port(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """USB Serial Device 포트를 자동으로 찾습니다""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # 사용 가능한 모든 포트 가져오기 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ports = list(serial.tools.list_ports.comports()) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # 포트 정보 출력 (디버깅용) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"Available ports: {len(ports)}") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for port in ports: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"- {port.device}: {port.description} (manufacturer: {port.manufacturer})") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # "USB Serial Device"라는 설명이 있는 포트 찾기 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for port in ports: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if "USB Serial Device" in port.description: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"Found USB Serial Device at {port.device}") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return port.device | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # 찾지 못한 경우 기본값 'COM3' 반환 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| print("USB Serial Device not found. Falling back to COM3.") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+62
to
+73
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"Available ports: {len(ports)}") | |
| for port in ports: | |
| print(f"- {port.device}: {port.description} (manufacturer: {port.manufacturer})") | |
| # "USB Serial Device"라는 설명이 있는 포트 찾기 | |
| for port in ports: | |
| if "USB Serial Device" in port.description: | |
| print(f"Found USB Serial Device at {port.device}") | |
| return port.device | |
| # 찾지 못한 경우 기본값 'COM3' 반환 | |
| print("USB Serial Device not found. Falling back to COM3.") | |
| logging.info(f"Available ports: {len(ports)}") | |
| for port in ports: | |
| logging.debug(f"- {port.device}: {port.description} (manufacturer: {port.manufacturer})") | |
| # "USB Serial Device"라는 설명이 있는 포트 찾기 | |
| for port in ports: | |
| if "USB Serial Device" in port.description: | |
| logging.info(f"Found USB Serial Device at {port.device}") | |
| return port.device | |
| # 찾지 못한 경우 기본값 'COM3' 반환 | |
| logging.warning("USB Serial Device not found. Falling back to COM3.") |
Copilot
AI
May 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Filtering by the literal string 'USB Serial Device' may not catch all adapter types; consider making this match rule configurable or more robust.
| # "USB Serial Device"라는 설명이 있는 포트 찾기 | |
| for port in ports: | |
| if "USB Serial Device" in port.description: | |
| print(f"Found USB Serial Device at {port.device}") | |
| return port.device | |
| # 찾지 못한 경우 기본값 'COM3' 반환 | |
| print("USB Serial Device not found. Falling back to COM3.") | |
| return 'COM3' | |
| # Configurable keywords for matching port descriptions | |
| match_keywords = getattr(self, "serial_port_keywords", ["USB Serial Device"]) | |
| # Search for a port matching any of the keywords | |
| for port in ports: | |
| if any(keyword.lower() in port.description.lower() for keyword in match_keywords): | |
| print(f"Found matching device at {port.device} (description: {port.description})") | |
| return port.device | |
| # If no matching port is found, fall back to default | |
| print(f"No matching device found. Falling back to default port: 'COM3'.") | |
| return 'COM3' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider extracting the hardcoded fallback port (
'COM3') into a configuration setting or environment variable for easier customization.