Add ability to get library version programmatically with getVersion()

This commit is contained in:
hedgecrw85 2019-03-22 10:43:48 -05:00
parent 206d1721a9
commit 15a24d4cf6
2 changed files with 14 additions and 7 deletions

View File

@ -2,7 +2,7 @@
* SerialPort.java * SerialPort.java
* *
* Created on: Feb 25, 2012 * Created on: Feb 25, 2012
* Last Updated on: Mar 19, 2019 * Last Updated on: Mar 22, 2019
* Author: Will Hedgecock * Author: Will Hedgecock
* *
* Copyright (C) 2012-2019 Fazecast, Inc. * Copyright (C) 2012-2019 Fazecast, Inc.
@ -39,19 +39,19 @@ import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.regex.Pattern;
/** /**
* This class provides native access to serial ports and devices without requiring external libraries or tools. * This class provides native access to serial ports and devices without requiring external libraries or tools.
* *
* @author Will Hedgecock <will.hedgecock@fazecast.com> * @author Will Hedgecock <will.hedgecock@fazecast.com>
* @version 2.5.0 * @version 2.5.1
* @see java.io.InputStream * @see java.io.InputStream
* @see java.io.OutputStream * @see java.io.OutputStream
*/ */
public final class SerialPort public final class SerialPort
{ {
// Static initializer loads correct native library for this machine // Static initializer loads correct native library for this machine
private static final String versionString = "2.5.1";
private static volatile boolean isAndroid = false; private static volatile boolean isAndroid = false;
private static volatile boolean isUnixBased = false; private static volatile boolean isUnixBased = false;
private static volatile boolean isWindows = false; private static volatile boolean isWindows = false;
@ -265,7 +265,14 @@ public final class SerialPort
* @return The port description as reported by the device itself. * @return The port description as reported by the device itself.
*/ */
@Override @Override
public String toString() { return getPortDescription(); } public String toString() { return getPortDescription(); }
/**
* Returns the current version of the jSerialComm library.
*
* @return The current library version.
*/
static public String getVersion() { return versionString; }
/** /**
* Returns a list of all available serial ports on this machine. * Returns a list of all available serial ports on this machine.

View File

@ -2,7 +2,7 @@
* SerialPortTest.java * SerialPortTest.java
* *
* Created on: Feb 27, 2015 * Created on: Feb 27, 2015
* Last Updated on: Mar 19, 2019 * Last Updated on: Mar 22, 2019
* Author: Will Hedgecock * Author: Will Hedgecock
* *
* Copyright (C) 2012-2019 Fazecast, Inc. * Copyright (C) 2012-2019 Fazecast, Inc.
@ -26,14 +26,13 @@
package com.fazecast.jSerialComm; package com.fazecast.jSerialComm;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Scanner; import java.util.Scanner;
/** /**
* This class provides a test case for the jSerialComm library. * This class provides a test case for the jSerialComm library.
* *
* @author Will Hedgecock <will.hedgecock@gmail.com> * @author Will Hedgecock <will.hedgecock@gmail.com>
* @version 2.5.0 * @version 2.5.1
* @see java.io.InputStream * @see java.io.InputStream
* @see java.io.OutputStream * @see java.io.OutputStream
*/ */
@ -84,6 +83,7 @@ public class SerialPortTest
static public void main(String[] args) static public void main(String[] args)
{ {
System.out.println("\nUsing Library Version v" + SerialPort.getVersion());
SerialPort[] ports = SerialPort.getCommPorts(); SerialPort[] ports = SerialPort.getCommPorts();
System.out.println("\nAvailable Ports:\n"); System.out.println("\nAvailable Ports:\n");
for (int i = 0; i < ports.length; ++i) for (int i = 0; i < ports.length; ++i)