diff --git a/src/main/java/io/github/dsheirer/source/tuner/TunerFactory.java b/src/main/java/io/github/dsheirer/source/tuner/TunerFactory.java index ba525198..434c9d7f 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/TunerFactory.java +++ b/src/main/java/io/github/dsheirer/source/tuner/TunerFactory.java @@ -185,9 +185,19 @@ public class TunerFactory { //API instance is retained across the lifecycle of the constructed device, so we only close it if we don't get //a device from it. - SDRplay api = new SDRplay(); + SDRplay api = null; - if(api.isAvailable()) + try + { + api = new SDRplay(); + } + catch(SDRPlayException se) + { + mLog.info("Caught the exception here ...", se); + api = null; + } + + if(api != null && api.isAvailable()) { Device device = api.getDevice(deviceInfo); diff --git a/src/main/java/io/github/dsheirer/source/tuner/manager/TunerManager.java b/src/main/java/io/github/dsheirer/source/tuner/manager/TunerManager.java index a8963654..f1e4efa3 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/manager/TunerManager.java +++ b/src/main/java/io/github/dsheirer/source/tuner/manager/TunerManager.java @@ -299,9 +299,18 @@ public class TunerManager implements IDiscoveredTunerStatusListener //Note: we have to keep this first API instance open while we use any RSP tuners, otherwise the additional API //instance(s) used by the individual tuners become unresponsive. Note sure why. - mSDRplay = new SDRplay(); - if(mSDRplay.isAvailable()) + try + { + mSDRplay = new SDRplay(); + } + catch(SDRPlayException se) + { + mLog.error("Couldn't load SDRPlay API"); + mSDRplay = null; + } + + if(mSDRplay != null && mSDRplay.isAvailable()) { try { @@ -333,7 +342,11 @@ public class TunerManager implements IDiscoveredTunerStatusListener } else { - mSDRplay.close(); + if(mSDRplay != null) + { + mSDRplay.close(); + } + mSDRplay = null; } } diff --git a/src/main/java/io/github/dsheirer/source/tuner/sdrplay/api/SDRplay.java b/src/main/java/io/github/dsheirer/source/tuner/sdrplay/api/SDRplay.java index e605a551..71b44b3c 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/sdrplay/api/SDRplay.java +++ b/src/main/java/io/github/dsheirer/source/tuner/sdrplay/api/SDRplay.java @@ -104,7 +104,7 @@ public class SDRplay /** * Constructs an instance of the SDRPLay API */ - public SDRplay() + public SDRplay() throws SDRPlayException { mSdrplayLibraryLoaded = loadLibrary(); @@ -116,6 +116,11 @@ public class SDRplay mLog.info("API library - open status: " + openStatus); } mAvailable = openStatus.success() && getVersion().isSupported(); + + if(openStatus == Status.FAIL) + { + throw new SDRPlayException("Service not available"); + } } else { @@ -693,23 +698,23 @@ public class SDRplay * Java will look there for the library, without having to specify it as a launcher * option. This would allow for users that have installed the API to an alternate location. */ - SDRplay sdrplay = new SDRplay(); - Status status = sdrplay.open(); - mLog.info("Open Status: " + status); try { + SDRplay sdrplay = new SDRplay(); + Status status = sdrplay.open(); + mLog.info("Open Status: " + status); + for(DeviceInfo deviceInfo: sdrplay.getDeviceInfos()) { mLog.info("Found: " + deviceInfo); } + Status closeStatus = sdrplay.close(); + mLog.info("Close Status: " + closeStatus); } catch(SDRPlayException se) { mLog.info("Error", se); } - - Status closeStatus = sdrplay.close(); - mLog.info("Close Status: " + closeStatus); } }