From 8370f2a253a3f71a197bc20d102e76750fd08083 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Fri, 12 Jan 2024 22:36:30 -0500 Subject: [PATCH] very questionable code --- .../peak/can/basic/HackLoadLibraryFlag.java | 6 ++++ src/main/java/peak/can/basic/PCANBasic.java | 32 ++++++++++--------- 2 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 src/main/java/peak/can/basic/HackLoadLibraryFlag.java diff --git a/src/main/java/peak/can/basic/HackLoadLibraryFlag.java b/src/main/java/peak/can/basic/HackLoadLibraryFlag.java new file mode 100644 index 0000000..538a522 --- /dev/null +++ b/src/main/java/peak/can/basic/HackLoadLibraryFlag.java @@ -0,0 +1,6 @@ +package peak.can.basic; + +public class HackLoadLibraryFlag { + // control if library should be auto-loaded or not + public static boolean LOAD_LIBRARY = true; +} diff --git a/src/main/java/peak/can/basic/PCANBasic.java b/src/main/java/peak/can/basic/PCANBasic.java index 1ca469a..48e69e4 100644 --- a/src/main/java/peak/can/basic/PCANBasic.java +++ b/src/main/java/peak/can/basic/PCANBasic.java @@ -2,7 +2,7 @@ /* * $Id: PCANBasic.java 12274 2021-08-30 12:20:04Z Fabrice $ * @LastChange $Date: 2021-08-30 14:20:04 +0200 (Mon, 30 Aug 2021) $ - * + * * PCANBasic JAVA Interface. * * Copyright (C) 2001-2021 PEAK System-Technik GmbH @@ -156,7 +156,7 @@ public class PCANBasic { */ public native TPCANStatus Reset( TPCANHandle Channel); - + /** * Gets the current status of a PCAN Channel * @@ -165,7 +165,7 @@ public class PCANBasic { */ public native TPCANStatus GetStatus( TPCANHandle Channel); - + /** * Transmits a CAN message * @@ -180,7 +180,7 @@ public class PCANBasic { TPCANHandle Channel, TPCANMsg MessageBuffer, TPCANTimestamp TimestampBuffer); - + /** * Reads a CAN message from the receive queue of a FD capable PCAN Channel * @@ -195,7 +195,7 @@ public class PCANBasic { TPCANHandle Channel, TPCANMsgFD MessageBuffer, TPCANTimestampFD TimestampBuffer); - + /** * Transmits a CAN message * @@ -206,7 +206,7 @@ public class PCANBasic { public native TPCANStatus Write( TPCANHandle Channel, TPCANMsg MessageBuffer); - + /** * Transmits a CAN message over a FD capable PCAN Channel * @@ -217,7 +217,7 @@ public class PCANBasic { public native TPCANStatus WriteFD( TPCANHandle Channel, TPCANMsgFD MessageBuffer); - + /** * Configures the reception filter. The message filter will be expanded with * every call to this function. If it is desired to reset the filter, please @@ -235,7 +235,7 @@ public class PCANBasic { int FromID, int ToID, TPCANMode Mode); - + /** * Retrieves a PCAN Channel value Parameters can be present or not according * with the kind of Hardware (PCAN Channel) being used. If a parameter is @@ -252,7 +252,7 @@ public class PCANBasic { TPCANParameter Parameter, Object Buffer, int BufferLength); - + /** * Configures or sets a PCAN Channel value Parameters can be present or not * according with the kind of Hardware (PCAN Channel) being used. If a @@ -296,7 +296,7 @@ public class PCANBasic { * @return A TPCANStatus error code */ public native TPCANStatus LookUpChannel( - StringBuffer Parameters, + StringBuffer Parameters, MutableTPCANHandle FoundChannel); /** @@ -325,11 +325,13 @@ public class PCANBasic { public native boolean initializeAPI(); static { - try { - System.loadLibrary("pcanbasic_jni"); - } catch (UnsatisfiedLinkError e) { - System.out.println(e.getMessage()); - System.loadLibrary("PCANBasic_JNI"); + if (HackLoadLibraryFlag.LOAD_LIBRARY) { + try { + System.loadLibrary("pcanbasic_jni"); + } catch (UnsatisfiedLinkError e) { + System.out.println(e.getMessage()); + System.loadLibrary("PCANBasic_JNI"); + } } } }