/* * 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(); } }