Skip to content

Commit 2c57b1f

Browse files
committed
Errors out gracefully if it can't connect to a serial port
1 parent f224038 commit 2c57b1f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tools/hardware/elm327_relay.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ def send_cmd(cmd)
132132
#
133133
# @return [SerialPort] SerialPort object for communications. Also available as @ser
134134
def connect_to_device()
135-
@ser = SerialPort.new(self.serial_port, self.serial_baud, self.serial_bits, self.serial_stop_bits, SerialPort::NONE)
135+
begin
136+
@ser = SerialPort.new(self.serial_port, self.serial_baud, self.serial_bits, self.serial_stop_bits, SerialPort::NONE)
137+
rescue
138+
$stdout.puts "Unable to connect to serial port. See -h for help"
139+
exit -2
140+
end
136141
resp = send_cmd("ATZ") # Turn off ECHO
137142
#if resp =~ /ELM327/
138143
if resp =~ /ELM327/

0 commit comments

Comments
 (0)