From 9bfdbb1d569eea229fd9f10823891234c8676145 Mon Sep 17 00:00:00 2001 From: Jérémy Zurcher Date: Fri, 18 Feb 2011 17:39:44 +0100 Subject: initial commit, version 0.4.1 from http://sourceforge.net/projects/libk8055 --- java/build.xml | 213 ++++++ java/src/c/jk8055.c | 398 ++++++++++ java/src/java/net/sf/libk8055/jk8055/JK8055.java | 812 +++++++++++++++++++++ .../net/sf/libk8055/jk8055/JK8055Exception.java | 73 ++ .../java/net/sf/libk8055/jk8055/JK8055Test.java | 400 ++++++++++ java/src/java/net/sf/libk8055/jk8055/overview.html | 7 + java/src/java/net/sf/libk8055/jk8055/package.html | 8 + 7 files changed, 1911 insertions(+) create mode 100644 java/build.xml create mode 100644 java/src/c/jk8055.c create mode 100644 java/src/java/net/sf/libk8055/jk8055/JK8055.java create mode 100644 java/src/java/net/sf/libk8055/jk8055/JK8055Exception.java create mode 100644 java/src/java/net/sf/libk8055/jk8055/JK8055Test.java create mode 100644 java/src/java/net/sf/libk8055/jk8055/overview.html create mode 100644 java/src/java/net/sf/libk8055/jk8055/package.html (limited to 'java') diff --git a/java/build.xml b/java/build.xml new file mode 100644 index 0000000..66dc02c --- /dev/null +++ b/java/build.xml @@ -0,0 +1,213 @@ + + + + + java wrapper for libk8055 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/src/c/jk8055.c b/java/src/c/jk8055.c new file mode 100644 index 0000000..e33de70 --- /dev/null +++ b/java/src/c/jk8055.c @@ -0,0 +1,398 @@ +/* + * Copyright (C) 2008 Martin Pischky (mailto:martin@pischky.de) + * + * This file (jk8055.c) is part of libk8055/jk8055. + * jk8055 - a java wrapper for libk8055 + * + * libk8055/jk8055 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * $Id: jk8055.c,v 1.2 2008/07/12 11:32:01 pischky Exp $ + * + */ + +#include +#ifdef USE_VELLEMAN_DLL + // assumes that Velleman DLL Version 2 has been installed + #define bool int + #include +#else + // assumes that the c library as been installed with header file + #include +#endif +#include +#include "jk8055.h" + +#define K8055_ERROR -1 + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: COpenDevice + * Signature: (I)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_COpenDevice +(JNIEnv* env, jobject obj, jint cardAddress) +{ + return OpenDevice(cardAddress); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CCloseDevice + * Signature: ()I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CCloseDevice +(JNIEnv* env, jobject obj) +{ + return CloseDevice(); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CReadAnalogChannel + * Signature: (I)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CReadAnalogChannel +(JNIEnv* env, jobject obj, jint channel) +{ + return ReadAnalogChannel( channel ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CReadAllAnalog + * Signature: (Lnet/sf/libk8055/jk8055/JK8055$AllAnalog;)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CReadAllAnalog +(JNIEnv* env, jobject obj, jobject data) +{ + long a1, a2; + jfieldID fid1, fid2; + int retval; + jclass cls; + + retval = ReadAllAnalog( &a1, &a2 ); + if( retval == K8055_ERROR ) return retval; + cls = (*env)->GetObjectClass( env, data ); + fid1 = (*env)->GetFieldID( env, cls, "data1", "I" ); + if( fid1 == NULL ) return K8055_ERROR; + fid2 = (*env)->GetFieldID( env, cls, "data2", "I" ); + if( fid2 == NULL ) return K8055_ERROR; + (*env)->SetIntField( env, data, fid1, (jint) a1 ); + (*env)->SetIntField( env, data, fid2, (jint) a2 ); + return 0; +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: COutputAnalogChannel + * Signature: (II)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_COutputAnalogChannel +(JNIEnv* env, jobject obj, jint channel, jint data) +{ + return OutputAnalogChannel( channel, data ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: COutputAllAnalog + * Signature: (II)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_COutputAllAnalog +(JNIEnv* env, jobject obj, jint data1, jint data2) +{ + return OutputAllAnalog( data1, data2 ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CClearAllAnalog + * Signature: ()I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CClearAllAnalog +(JNIEnv* env, jobject obj) +{ + return ClearAllAnalog(); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CClearAnalogChannel + * Signature: (I)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CClearAnalogChannel +(JNIEnv* env, jobject obj, jint channel) +{ + return ClearAnalogChannel( channel ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CSetAnalogChannel + * Signature: (I)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CSetAnalogChannel +(JNIEnv* env, jobject obj, jint channel) +{ + return SetAnalogChannel( channel ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CSetAllAnalog + * Signature: ()I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CSetAllAnalog +(JNIEnv* env, jobject obj) +{ + return SetAllAnalog(); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CWriteAllDigital + * Signature: (I)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CWriteAllDigital +(JNIEnv* env, jobject obj, jint data) +{ + return WriteAllDigital( data ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CClearDigitalChannel + * Signature: (I)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CClearDigitalChannel +(JNIEnv* env, jobject obj, jint channel) +{ + return ClearDigitalChannel( channel ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CClearAllDigital + * Signature: ()I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CClearAllDigital +(JNIEnv* env, jobject obj) +{ + return ClearAllDigital(); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CSetDigitalChannel + * Signature: (I)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CSetDigitalChannel +(JNIEnv* env, jobject obj, jint channel) +{ + return SetDigitalChannel( channel ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CSetAllDigital + * Signature: ()I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CSetAllDigital +(JNIEnv* env, jobject obj) +{ + return SetAllDigital(); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CReadDigitalChannel + * Signature: (I)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CReadDigitalChannel +(JNIEnv* env, jobject obj, jint channel) +{ + return ReadDigitalChannel( channel ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CReadAllDigital + * Signature: ()I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CReadAllDigital +(JNIEnv* env, jobject obj) +{ + return ReadAllDigital(); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CResetCounter + * Signature: (I)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CResetCounter +(JNIEnv* env, jobject obj, jint counterno) +{ + return ResetCounter( counterno ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CReadCounter + * Signature: (I)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CReadCounter +(JNIEnv* env, jobject obj, jint counterno) +{ + return ReadCounter( counterno ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CSetCounterDebounceTime + * Signature: (II)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CSetCounterDebounceTime +(JNIEnv* env, jobject obj, jint counterno, jint debouncetime) +{ + return SetCounterDebounceTime( counterno, debouncetime ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CReadAllValues + * Signature: (Lnet/sf/libk8055/jk8055/JK8055$AllValues;)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CReadAllValues +(JNIEnv* env, jobject obj, jobject av) +{ + long input, analog1, analog2, counter1, counter2; + int retval; + jfieldID fid_input, fid_analog1, fid_analog2, fid_counter1, fid_counter2; + jclass cls; + + #ifdef USE_VELLEMAN_DLL + input = ReadAllDigital(); + if( input == K8055_ERROR ) return input; + retval = ReadAllAnalog( &analog1, &analog2 ); + if( retval == K8055_ERROR ) return retval; + counter1 = ReadCounter( 1 ); + if( counter1 == K8055_ERROR ) return counter1; + counter2 = ReadCounter( 2 ); + if( counter2 == K8055_ERROR ) return counter2; + #else + retval = ReadAllValues( &input, &analog1, &analog2, &counter1, &counter2 ); + if( retval == K8055_ERROR ) return retval; + #endif + cls = (*env)->GetObjectClass( env, av ); + fid_input = (*env)->GetFieldID( env, cls, "input", "I" ); + if( fid_input == NULL ) return K8055_ERROR; + fid_analog1 = (*env)->GetFieldID( env, cls, "analog1", "I" ); + if( fid_analog1 == NULL ) return K8055_ERROR; + fid_analog2 = (*env)->GetFieldID( env, cls, "analog2", "I" ); + if( fid_analog2 == NULL ) return K8055_ERROR; + fid_counter1 = (*env)->GetFieldID( env, cls, "counter1", "I" ); + if( fid_counter1 == NULL ) return K8055_ERROR; + fid_counter2 = (*env)->GetFieldID( env, cls, "counter2", "I" ); + if( fid_counter2 == NULL ) return K8055_ERROR; + (*env)->SetIntField( env, av, fid_input, (jint) input ); + (*env)->SetIntField( env, av, fid_analog1, (jint) analog1 ); + (*env)->SetIntField( env, av, fid_analog2, (jint) analog2 ); + (*env)->SetIntField( env, av, fid_counter1, (jint) counter1 ); + (*env)->SetIntField( env, av, fid_counter2, (jint) counter2 ); + return 0; +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CSetAllValues + * Signature: (III)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CSetAllValues +(JNIEnv* env, jobject obj, jint digitaldata, jint analogdata1, jint analogdata2) +{ + int retval; + #ifdef USE_VELLEMAN_DLL + retval = WriteAllDigital( digitaldata ); + if( retval == K8055_ERROR ) return retval; + retval = OutputAllAnalog( analogdata1, analogdata2 ); + if( retval == K8055_ERROR ) return retval; + #else + retval = SetAllValues( digitaldata, analogdata1, analogdata2 ); + #endif + return retval; +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CSetCurrentDevice + * Signature: (I)I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CSetCurrentDevice +(JNIEnv* env, jobject obj, jint deviceno) +{ + return SetCurrentDevice( deviceno ); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CSearchDevices + * Signature: ()I + */ +JNIEXPORT jint +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CSearchDevices +(JNIEnv* env, jobject obj) +{ + return SearchDevices(); +} + +/* + * Class: net_sf_libk8055_jk8055_JK8055 + * Method: CVersion + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring +JNICALL Java_net_sf_libk8055_jk8055_JK8055_CVersion +(JNIEnv* env, jobject obj) +{ + #ifdef USE_VELLEMAN_DLL + return (*env)->NewStringUTF( env, "unknown" ); + #else + return (*env)->NewStringUTF( env, Version() ); + #endif +} diff --git a/java/src/java/net/sf/libk8055/jk8055/JK8055.java b/java/src/java/net/sf/libk8055/jk8055/JK8055.java new file mode 100644 index 0000000..26cdbc1 --- /dev/null +++ b/java/src/java/net/sf/libk8055/jk8055/JK8055.java @@ -0,0 +1,812 @@ +/* + * Copyright (C) 2008 Martin Pischky (mailto:martin@pischky.de) + * + * This file (JK8055.java) is part of libk8055/jk8055. + * jk8055 - a java wrapper for libk8055 + * + * libk8055/jk8055 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * $Id: JK8055.java,v 1.4 2008/07/28 09:58:30 pischky Exp $ + * + */ + +package net.sf.libk8055.jk8055; + +/** + * JK8055 - A java wrapper for libk8055. + * + * @see http://libk8055.sourceforge.net/ + * @author Martin Pischky + * + */ +public class JK8055 { + + public static final String CVS_ID = "$Id: JK8055.java,v 1.4 2008/07/28 09:58:30 pischky Exp $"; + + /** + * This class is singleton. + */ + private JK8055() { + } + + private static JK8055 instance = null; + + /** + * Create an instance if needed and return it. + * @return the instance + */ + public static JK8055 getInstance() { + if( instance != null ) { + return instance; + } + synchronized (JK8055.class) { + if( instance == null ) { + instance = new JK8055(); + } + } + return instance; + } + + public static final int K8055_ERROR = -1; + + static { + System.loadLibrary("jk8055"); + } + + /* (non-Javadoc) + * @see java.lang.Object#finalize() + */ + protected void finalize() throws Throwable { + try { + CloseAllOpenDevices(); + } finally { + super.finalize(); + } + } + + /** + * Open device. + * Scan through usb busses looking + * for the right device, claim it and then open the device. + * @param cardAddress + * @return BoardAddress or K8055_ERROR + */ + private native int COpenDevice( int cardAddress ); + + /** + * Opens the communication link to the K8055 device. + * Opens the communication link to the K8055 card. Loads the drivers + * needed to communicate via the USB port. This procedure must be performed + * before any attempts to communicate with the K8055 card. + *
+ * This function can also be used to selects the active K8055 card to read + * and write the data. All the communication routines after this function + * call are addressed to this card until the other card is selected by this + * function call. + * + * @param cardAddress Value between 0 and 3 which corresponds to the + * jumper (SK5, SK6) setting on the K8055 board. + * @return If succeeded the return value will be the card address read + * from the K8055 hardware. + * @throws JK8055Exception indicates that K8055 card was not found. + */ + public synchronized int OpenDevice( int cardAddress ) + throws JK8055Exception + { + if( cardAddress<0 || 3 + * The counter number 1 counts the pulses fed to the input I1 and the + * counter number 2 counts the pulses fed to the input I2. + * + * @param counterno Value 1 or 2, which corresponds to the counter to be + * read. + * @return The content of the 16 bit pulse counter. + * @throws JK8055Exception indicates an error. + * @throws IllegalArgumentException indicates an invalid counter number. + */ + public synchronized int ReadCounter( int counterno ) + throws JK8055Exception + { + if( counterno<1 || 2 + * If the debounce time is set to 0, then the maximum counting rate is + * about 2000 counts per second. + * + * @param counterno Value 1 or 2, which corresponds to the counter + * to be set. + * @param debouncetime (0..7450?) Debounce time for the pulse counter. + *
+ * The DebounceTime value corresponds to the debounce + * time in milliseconds (ms) to be set for the + * pulse counter. Debounce time value may vary between + * 0 and 5000?. + * @throws JK8055Exception indicates an error. + * @throws IllegalArgumentException indicates an invalid parameter. + */ + public synchronized void SetCounterDebounceTime( int counterno, + int debouncetime ) + throws JK8055Exception + { + if( counterno<1 || 2Note + *
Once a specific device address is connected with a program + * another program can't get access to it. + * + * @return + *
 
+	 * Bin 0000, Dec 0 : No devices was found
+	 * Bin 0001, Dec 1 : Card address 0 was found.
+	 * Bin 0010, Dec 2 : Card address 1 was found.
+	 * Bin 0100, Dec 4 : Card address 2 was found.
+	 * Bin 1000, Dec 8 : Card address 3 was found.
+	 * Example : return value 9 = devices with address 0 and 3 are connected.
+	 * 
+ * @throws JK8055Exception + */ + public synchronized int SearchDevices() + throws JK8055Exception + { + int retval = CSearchDevices(); + if( retval == K8055_ERROR ) { + throw new JK8055Exception( "SearchDevices failed" ); + } + return retval; + } + + private native String CVersion(); + + /** + * Return the version number of the libk8055 library used. + * + * @return a string like "0.3" + */ + public synchronized String Version() { + return CVersion(); + } + +} diff --git a/java/src/java/net/sf/libk8055/jk8055/JK8055Exception.java b/java/src/java/net/sf/libk8055/jk8055/JK8055Exception.java new file mode 100644 index 0000000..d0e7104 --- /dev/null +++ b/java/src/java/net/sf/libk8055/jk8055/JK8055Exception.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2008 Martin Pischky (mailto:martin@pischky.de) + * + * This file (JK8055Exception.java) is part of libk8055/jk8055. + * jk8055 - a java wrapper for libk8055 + * + * libk8055/jk8055 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * $Id: JK8055Exception.java,v 1.3 2008/07/14 07:47:55 pischky Exp $ + * + */ + +package net.sf.libk8055.jk8055; + +/** + * Exceptions thrown by class JK8055. + * + * @author Martin Pischky + */ +public class JK8055Exception extends Exception { + + public static final String CVS_ID = "$Id: JK8055Exception.java,v 1.3 2008/07/14 07:47:55 pischky Exp $"; + + /** + * + */ + private static final long serialVersionUID = 3821577565947420161L; + + /** + * Constructor. + */ + public JK8055Exception() { + super(); + } + + /** + * Constructor. + * @param message + */ + public JK8055Exception(String message) { + super(message); + } + + /** + * Constructor. + * @param cause + */ + public JK8055Exception(Throwable cause) { + super(cause); + } + + /** + * Constructor. + * @param message + * @param cause + */ + public JK8055Exception(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/java/src/java/net/sf/libk8055/jk8055/JK8055Test.java b/java/src/java/net/sf/libk8055/jk8055/JK8055Test.java new file mode 100644 index 0000000..c2c559c --- /dev/null +++ b/java/src/java/net/sf/libk8055/jk8055/JK8055Test.java @@ -0,0 +1,400 @@ +/* + * Copyright (C) 2008 Martin Pischky (mailto:martin@pischky.de) + * + * This file (JK8055Test.java) is part of libk8055/jk8055. + * jk8055 - a java wrapper for libk8055 + * + * libk8055/jk8055 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * $Id: JK8055Test.java,v 1.4 2008/07/14 07:47:55 pischky Exp $ + * + */ + +package net.sf.libk8055.jk8055; + +import junit.framework.TestCase; + +/** + * JUnit tests for class JK8055. + * + * If you want to run this from eclipse add + * -Djava.library.path=build/c + * to VM arguments in run configuration. + * + * @author Martin Pischky + */ +public class JK8055Test extends TestCase { + + public static final int DEVICE = 0; + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + static void sleep( int ms ) { + try { + Thread.sleep( ms ); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void testGetInstance() { + JK8055.getInstance(); + } + + public void testOpenCloseDevice() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + jk8055.CloseDevice(); + } + + public void testReadAnalogChannel() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + int a1 = jk8055.ReadAnalogChannel(1); + int a2 = jk8055.ReadAnalogChannel(2); + assertTrue("a1>=0", a1>=0 ); + assertTrue("a1<=255",a1<=255); + assertTrue("a2>=0", a2>=0 ); + assertTrue("a2<=255",a2<=255); + jk8055.CloseDevice(); + } + + public void testReadAllAnalog() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + JK8055.AllAnalog aa = jk8055.ReadAllAnalog(); + assertTrue( "aa.data1>=0", aa.data1>=0 ); + assertTrue( "aa.data1<=255",aa.data1<=255 ); + assertTrue( "aa.data2>=0", aa.data2>=0 ); + assertTrue( "aa.data2<=255",aa.data2<=255 ); + int a1 = jk8055.ReadAnalogChannel(1); + int a2 = jk8055.ReadAnalogChannel(2); + assertTrue( "a1 ~= aa.data1", Math.abs(a1-aa.data1)<2 ); + assertTrue( "a2 ~= aa.data2", Math.abs(a2-aa.data2)<2 ); + jk8055.CloseDevice(); + } + + public void testOutputAnalogChannel() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + jk8055.OutputAnalogChannel( 1, 0 ); + jk8055.OutputAnalogChannel( 2, 255 ); + sleep( 500 ); + for (int i = 0; i <= 255; i++) { + jk8055.OutputAnalogChannel( 1, i ); + jk8055.OutputAnalogChannel( 2, 255-i ); + } + for (int i = 255; i >= 0; i--) { + jk8055.OutputAnalogChannel( 1, i ); + jk8055.OutputAnalogChannel( 2, 255-i ); + } + sleep( 500 ); + jk8055.OutputAnalogChannel( 1, 0 ); + jk8055.OutputAnalogChannel( 2, 0 ); + jk8055.CloseDevice(); + } + + public void testOutputAllAnalog() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + jk8055.OutputAllAnalog( 0, 255 ); + sleep( 500 ); + for (int i = 0; i <= 255; i++) { + jk8055.OutputAllAnalog( i, 255-i ); + } + for (int i = 255; i >= 0; i--) { + jk8055.OutputAllAnalog( i, 255-i ); + } + sleep( 500 ); + jk8055.OutputAllAnalog( 0, 0 ); + jk8055.CloseDevice(); + } + + public void testClearAllAnalog() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + jk8055.ClearAllAnalog(); + jk8055.CloseDevice(); + } + + public void testClearAnalogChannel() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + jk8055.ClearAnalogChannel( 1 ); + jk8055.ClearAnalogChannel( 2 ); + jk8055.CloseDevice(); + } + + public void testSetAnalogChannel() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + jk8055.SetAnalogChannel( 1 ); + jk8055.SetAnalogChannel( 2 ); + jk8055.CloseDevice(); + } + + public void testSetAllAnalog() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + jk8055.SetAllAnalog(); + jk8055.CloseDevice(); + } + + public void testWriteAllDigital() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + jk8055.WriteAllDigital( 0 ); + for (int i = 0; i <= 7; i++) { + jk8055.WriteAllDigital( 1<= 0; i--) { + jk8055.WriteAllDigital( 1<=0", data>=0 ); + assertTrue("data<=255",data<=255); + for (int i = 1; i <= 5; i++) { + boolean b = (data & (1<<(i-1))) != 0; + System.out.println( "Inp"+i+"="+b ); + } + jk8055.CloseDevice(); + } + + public void testResetCount() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + jk8055.ResetCount( 1 ); + jk8055.ResetCount( 2 ); + jk8055.CloseDevice(); + } + + public void testReadCounter() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + int c1 = jk8055.ReadCounter( 1 ); + int c2 = jk8055.ReadCounter( 2 ); + assertTrue( "c1", 0<=c1 && c1<=65535 ); + assertTrue( "c2", 0<=c2 && c2<=65535 ); + jk8055.CloseDevice(); + } + + public void testSetCounterDebounceTime() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + jk8055.SetCounterDebounceTime( 1, 1214 ); + jk8055.SetCounterDebounceTime( 2, 1214 ); + jk8055.CloseDevice(); + } + + public void testReadAllValues() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + JK8055.AllValues av = jk8055.ReadAllValues(); + assertTrue( "av.input>=0", av.input>=0 ); + assertTrue( "av.input<=32", av.input<=32 ); + assertTrue( "av.analog1>=0", av.analog1>=0 ); + assertTrue( "av.analog1<=255", av.analog2<=255 ); + assertTrue( "av.analog2>=0", av.analog2>=0 ); + assertTrue( "av.analog2<=255", av.analog2<=255 ); + assertTrue( "av.counter1>=0", av.counter1>=0 ); + assertTrue( "av.counter1<=65535", av.counter1<=65535 ); + assertTrue( "av.counter2>=0", av.counter2>=0 ); + assertTrue( "av.counter2<=65535", av.counter2<=65535 ); + int a1 = jk8055.ReadAnalogChannel(1); + int a2 = jk8055.ReadAnalogChannel(2); + assertTrue( "a1 ~= aa.data1", Math.abs(a1-av.analog1)<2 ); + assertTrue( "a2 ~= aa.data2", Math.abs(a2-av.analog2)<2 ); + jk8055.CloseDevice(); + } + + public void testSetAllValues() throws JK8055Exception { + JK8055 jk8055 = JK8055.getInstance(); + jk8055.OpenDevice( DEVICE ); + jk8055.SetAllValues( 123, 232, 87 ); + jk8055.CloseDevice(); + } + + public void testSetCurrentDevice() throws JK8055Exception { + System.out.println( "---- testSetCurrentDevice()" ); + JK8055 jk8055 = JK8055.getInstance(); + int d = jk8055.SearchDevices(); + if( d == 0 ) { + System.out.println( "No devices found." ); + } else { + for (int i = 0; i <= 3; i++) { + if( (d & (1< 0 ); + System.out.println( "version=\""+JK8055.getInstance().Version()+"\"" ); + } + +} diff --git a/java/src/java/net/sf/libk8055/jk8055/overview.html b/java/src/java/net/sf/libk8055/jk8055/overview.html new file mode 100644 index 0000000..2fff579 --- /dev/null +++ b/java/src/java/net/sf/libk8055/jk8055/overview.html @@ -0,0 +1,7 @@ + + +

+This document is the API specification for JK8055 - A java wrapper for libk8055. +

+ + diff --git a/java/src/java/net/sf/libk8055/jk8055/package.html b/java/src/java/net/sf/libk8055/jk8055/package.html new file mode 100644 index 0000000..4dba573 --- /dev/null +++ b/java/src/java/net/sf/libk8055/jk8055/package.html @@ -0,0 +1,8 @@ + + +

JK8055 - A java wrapper for libk8055.

+

The wrapper can be used on Linux with libk8055 (see +http://libk8055.sourceforge.net/) +or the standard Vellemann DLLs on Windows. + + -- cgit v1.2.3