From 5b5a6041c18bfc4ee071b253c6131d2c84efebee Mon Sep 17 00:00:00 2001 From: scream3r Date: Mon, 22 Apr 2013 10:46:45 +0400 Subject: [PATCH] Added using of "ERR_INCORRECT_SERIAL_PORT" into SerialPort class. Also made a little refactoring - if/else changed to switch/case in "openPort()" method for handling error --- src/java/jssc/SerialPort.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/java/jssc/SerialPort.java b/src/java/jssc/SerialPort.java index b719532..06cd585 100644 --- a/src/java/jssc/SerialPort.java +++ b/src/java/jssc/SerialPort.java @@ -151,15 +151,18 @@ public class SerialPort { else { throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_NULL_NOT_PERMITTED);//since 2.1.0 -> NULL port name fix } - if(portHandle == SerialNativeInterface.ERR_PORT_BUSY){//since 0.9.0 -> - throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PORT_BUSY); + switch(portHandle) { + case SerialNativeInterface.ERR_PORT_BUSY: + throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PORT_BUSY); + case SerialNativeInterface.ERR_PORT_NOT_FOUND: + throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PORT_NOT_FOUND); + case SerialNativeInterface.ERR_PERMISSION_DENIED: + throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PERMISSION_DENIED); + case SerialNativeInterface.ERR_INCORRECT_SERIAL_PORT: + throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_INCORRECT_SERIAL_PORT); + default: + break; } - else if(portHandle == SerialNativeInterface.ERR_PORT_NOT_FOUND){ - throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PORT_NOT_FOUND); - }//<- since 0.9.0 - else if(portHandle == SerialNativeInterface.ERR_PERMISSION_DENIED){//since 2.2.0 -> - throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PERMISSION_DENIED); - }//<- since 2.2.0 portOpened = true; return true; }