Skip to content

Commit

Permalink
Add port check to KMTronicLibrary
Browse files Browse the repository at this point in the history
If port is 'NONE' do not open connection.

Signed-off-by: Ville-Pekka Juntunen <[email protected]>
  • Loading branch information
vjuntunen committed Jan 24, 2025
1 parent 0c76cba commit a78e377
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
26 changes: 15 additions & 11 deletions Robot-Framework/lib/KMTronicLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ class KMTronicLibrary:

def __init__(self, port):
"""Initialize the serial connection"""
self.ser = serial.Serial(
port=port, # Port to which the device is connected
baudrate=9600, # Baud rate
bytesize=serial.EIGHTBITS, # Number of data bits
parity=serial.PARITY_NONE, # No parity
stopbits=serial.STOPBITS_ONE, # One stop bit
timeout=1 # Timeout for reading data
)
if self.ser.is_open:
print(f"Connection established successfully on port {port}.")
if port == 'NONE':
self.ser = None
print("No serial connection initialized (port set to 'NONE').")
else:
raise RuntimeError(f"Failed to open connection on port {port}")
self.ser = serial.Serial(
port=port, # Port to which the device is connected
baudrate=9600, # Baud rate
bytesize=serial.EIGHTBITS, # Number of data bits
parity=serial.PARITY_NONE, # No parity
stopbits=serial.STOPBITS_ONE, # One stop bit
timeout=1 # Timeout for reading data
)
if self.ser.is_open:
print(f"Connection established successfully on port {port}.")
else:
raise RuntimeError(f"Failed to open connection on port {port}")

def close_relay_board_connection(self):
"""
Expand Down
9 changes: 0 additions & 9 deletions Robot-Framework/resources/serial_keywords.resource
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ Open Serial Port
... stopbits=1
... timeout=${timeout}

Open Relay Serial Port
[Arguments] ${serialr_port} ${timeout}=1.0 ${baudrate}=9600
Add Port ${serialr_port}
... baudrate=${baudrate}
... bytesize=8
... parity=N
... stopbits=1
... timeout=${timeout}

Turn Relay Off
[Documentation] Turn given ${relay_number} relay off.
[Arguments] ${relay_number}
Expand Down

0 comments on commit a78e377

Please sign in to comment.