Skip to content

Conversation

@minnnseokk
Copy link
Contributor

📌 PR 제목

feature | sprint2 | FRB-171 | 센서 포트 장치에서 읽어들이게 수정 | 정민석


✨ 변경 사항

  • Serial 정보를 COM3로 하드코딩했었는데 USB에서 불러오는 것으로 수정

@minnnseokk minnnseokk requested a review from Copilot May 23, 2025 05:57
@gwangbu-desu gwangbu-desu requested review from gwangbu-desu and removed request for Copilot May 23, 2025 05:57
Copy link
Member

@gwangbu-desu gwangbu-desu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GOOD

@gwangbu-desu gwangbu-desu merged commit b3052bf into develop May 23, 2025
1 check passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the sensor connection flow to automatically detect the USB serial port instead of hardcoding COM3, updates the UI warning message accordingly, and adjusts the simulation configuration ID.

  • Dynamically detect and select the serial port in RealSensor
  • Remove explicit “COM3” mention from Streamlit warning
  • Update equip_id in the simulation config

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
streamlit_app/app.py Removed specific COM3 reference from the real_sensor warning
simulation_cconfig.json Changed equip_id value
service/sensor/RealSensor.py Added _find_serial_port() helper and dynamic serial port setup
Comments suppressed due to low confidence (2)

service/sensor/RealSensor.py:55

  • Add unit tests for _find_serial_port, mocking serial.tools.list_ports.comports() to verify both the successful detection and fallback paths.
def _find_serial_port(self):

simulation_cconfig.json:6

  • The equip_id was updated to match zone_id, which likely duplicates the value by mistake. Please verify that the correct equip_id is being used.
"equip_id": "20250507165750-827",

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 포트
Copy link

Copilot AI May 23, 2025

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.

Copilot uses AI. Check for mistakes.
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.")
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace print statements with the project's logging framework to ensure consistent log levels and outputs.

Suggested change
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 uses AI. Check for mistakes.
Comment on lines +66 to +74
# "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'
Copy link

Copilot AI May 23, 2025

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.

Suggested change
# "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'

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants