📄 tmexadapter.java
字号:
* <ul> * <li> 0 (RESET_NOPRESENCE) no devices present on the 1-Wire Network. * <li> 1 (RESET_PRESENCE) normal presence pulse detected on the 1-Wire * Network indicating there is a device present. * <li> 2 (RESET_ALARM) alarming presence pulse detected on the 1-Wire * Network indicating there is a device present and it is in the * alarm condition. This is only provided by the DS1994/DS2404 * devices. * <li> 3 (RESET_SHORT) inticates 1-Wire appears shorted. This can be * transient conditions in a 1-Wire Network. Not all adapter types * can detect this condition. * </ul> * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter */ public native int reset () throws OneWireIOException, OneWireException; //-------- //-------- 1-Wire Network power methods //-------- /** * Sets the duration to supply power to the 1-Wire Network. * This method takes a time parameter that indicates the program * pulse length when the method startPowerDelivery().<p> * * Note: to avoid getting an exception, * use the canDeliverPower() and canDeliverSmartPower() * method to check it's availability. <p> * * @param timeFactor * <ul> * <li> 0 (DELIVERY_HALF_SECOND) provide power for 1/2 second. * <li> 1 (DELIVERY_ONE_SECOND) provide power for 1 second. * <li> 2 (DELIVERY_TWO_SECONDS) provide power for 2 seconds. * <li> 3 (DELIVERY_FOUR_SECONDS) provide power for 4 seconds. * <li> 4 (DELIVERY_SMART_DONE) provide power until the * the device is no longer drawing significant power. * <li> 5 (DELIVERY_INFINITE) provide power until the * setPowerNormal() method is called. * </ul> * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter */ public void setPowerDuration (int timeFactor) throws OneWireIOException, OneWireException { // Right now we only support infinite pull up. if (timeFactor != DELIVERY_INFINITE) throw new OneWireException( "No support for other than infinite power duration"); } /** * Sets the 1-Wire Network voltage to supply power to an iButton device. * This method takes a time parameter that indicates whether the * power delivery should be done immediately, or after certain * conditions have been met. <p> * * Note: to avoid getting an exception, * use the canDeliverPower() and canDeliverSmartPower() * method to check it's availability. <p> * * @param changeCondition * <ul> * <li> 0 (CONDITION_NOW) operation should occur immediately. * <li> 1 (CONDITION_AFTER_BIT) operation should be pending * execution immediately after the next bit is sent. * <li> 2 (CONDITION_AFTER_BYTE) operation should be pending * execution immediately after next byte is sent. * </ul> * * @return <code>true</code> if the voltage change was successful, * <code>false</code> otherwise. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter */ public native boolean startPowerDelivery (int changeCondition) throws OneWireIOException, OneWireException; /** * Sets the duration for providing a program pulse on the * 1-Wire Network. * This method takes a time parameter that indicates the program * pulse length when the method startProgramPulse().<p> * * Note: to avoid getting an exception, * use the canDeliverPower() method to check it's * availability. <p> * * @param timeFactor * <ul> * <li> 6 (DELIVERY_EPROM) provide program pulse for 480 microseconds * <li> 5 (DELIVERY_INFINITE) provide power until the * setPowerNormal() method is called. * </ul> * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter */ public void setProgramPulseDuration (int timeFactor) throws OneWireIOException, OneWireException { if (timeFactor != DELIVERY_EPROM) throw new OneWireException( "Only support EPROM length program pulse duration"); } /** * Sets the 1-Wire Network voltage to eprom programming level. * This method takes a time parameter that indicates whether the * power delivery should be done immediately, or after certain * conditions have been met. <p> * * Note: to avoid getting an exception, * use the canProgram() method to check it's * availability. <p> * * @param changeCondition * <ul> * <li> 0 (CONDITION_NOW) operation should occur immediately. * <li> 1 (CONDITION_AFTER_BIT) operation should be pending * execution immediately after the next bit is sent. * <li> 2 (CONDITION_AFTER_BYTE) operation should be pending * execution immediately after next byte is sent. * </ul> * * @return <code>true</code> if the voltage change was successful, * <code>false</code> otherwise. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * or the adapter does not support this operation */ public native boolean startProgramPulse (int changeCondition) throws OneWireIOException, OneWireException; /** * Sets the 1-Wire Network voltage to 0 volts. This method is used * rob all 1-Wire Network devices of parasite power delivery to force * them into a hard reset. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * or the adapter does not support this operation */ public native void startBreak () throws OneWireIOException, OneWireException; /** * Sets the 1-Wire Network voltage to normal level. This method is used * to disable 1-Wire conditions created by startPowerDelivery and * startProgramPulse. This method will automatically be called if * a communication method is called while an outstanding power * command is taking place. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * or the adapter does not support this operation */ public native void setPowerNormal () throws OneWireIOException, OneWireException; //-------- //-------- 1-Wire Network speed methods //-------- /** * This method takes an int representing the new speed of data * transfer on the 1-Wire Network. <p> * * @param speed * <ul> * <li> 0 (SPEED_REGULAR) set to normal communciation speed * <li> 1 (SPEED_FLEX) set to flexible communciation speed used * for long lines * <li> 2 (SPEED_OVERDRIVE) set to normal communciation speed to * overdrive * <li> 3 (SPEED_HYPERDRIVE) set to normal communciation speed to * hyperdrive * <li> >3 future speeds * </ul> * * @param desiredSpeed * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * or the adapter does not support this operation */ public native void setSpeed (int desiredSpeed) throws OneWireIOException, OneWireException; /** * This method returns the current data transfer speed through a * port to a 1-Wire Network. <p> * * @return * <ul> * <li> 0 (SPEED_REGULAR) set to normal communication speed * <li> 1 (SPEED_FLEX) set to flexible communication speed used * for long lines * <li> 2 (SPEED_OVERDRIVE) set to normal communication speed to * overdrive * <li> 3 (SPEED_HYPERDRIVE) set to normal communication speed to * hyperdrive * <li> >3 future speeds * </ul> */ public native int getSpeed (); //-------- //-------- Misc //-------- /** * Select the TMEX specified port type (0 to 15) Use this * method if the constructor with the PortType cannot be used. * * * @param newPortType * @return true if port type valid. Instance is only usable * if this returns false. */ public boolean setTMEXPortType (int newPortType) { // set default port type portType = newPortType; // attempt to set the portType, return result return setPortType_Native(portType); } //-------- //-------- Additional Native Methods //-------- /** * CleanUp the native state for classes owned by the provided * thread. */ public static native void CleanUpByThread (Thread thread); /** * Get the default Adapter Name. * * @return String containing the name of the default adapter */ public static native String getDefaultAdapterName (); /** * Get the default Adapter Port name. * * @return String containing the name of the default adapter port */ public static native String getDefaultPortName (); /** * Get the default Adapter Type number. * * @return int, the default adapter type */ private static native int getDefaultTypeNumber (); /** * Attempt to set the desired TMEX Port type. This native * call will attempt to get a session handle to verify that * the portType exists. * * @return true if portType exists, false if not */ private native boolean setPortType_Native (int portType); /** * Perform a 1-Wire bit operation * * @param bitValue boolean bit value, true=1, false=0 to send * to 1-Wire net * * @return boolean true for 1 return , false for 0 return * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter */ private native boolean dataBit_Native (boolean bitValue) throws OneWireIOException, OneWireException; /** * Perform a 1-Wire byte operation * * @param byteValue integer with ls byte containing the 8 bits value * to send to the 1-Wire net * * @return int containing the 1-Wire return 8 bits in the ls byte. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter */ private native int dataByte_Native (int byteValue) throws OneWireIOException, OneWireException; /** * Get the TMEX main and porttype version strings concatinated * * @return string containing the TMEX version */ private native String getVersion_Native (); /** * Peform a search * * @param skipResetOnSearch boolean, true to skip 1-Wire reset on search * @param resetSearch boolean, true to reset search (First) * @param doAlarmSearch boolean, true if only want to find alarming * @param RomDta byte array to hold ROM of device found * * @return boolean, true if search found a device else false * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter */ private native boolean romSearch_Native (boolean skipResetOnSearch, boolean resetSearch, boolean doAlarmSearch, byte[] RomDta) throws OneWireIOException, OneWireException; /** * Return the port name header (taken from porttype version) * * @return String containing the port name header */ private native String getPortNameHeader_Native (); /** * Cleanup native (called on finalize of this instance) */ private native void cleanup_Native (); //-------- //-------- Native driver loading //-------- /** * Static method called before instance is created. Attempt * verify native driver's installed and to load the * driver (IBTMJAVA.DLL). */ static { driverLoaded = false; // check if on OS that can have native TMEX drivers if ((System.getProperty("os.arch").indexOf("86") != -1) && (System.getProperty("os.name").indexOf("Windows") != -1)) { // check if TMEX native drivers installed int index = 0, last_index = 0; String search_path = System.getProperty("java.library.path"); String path; File file; boolean tmex_loaded = false; // check for a path to search if (search_path != null) { // loop to look through the library search path do { index = search_path.indexOf(File.pathSeparatorChar, last_index); if (index > -1) { path = search_path.substring(last_index, index); // look to see if IBFS32.DLL is in this path file = new File(path + File.separator + "IBFS32.DLL"); if (file.exists()) { tmex_loaded = true; break; } } last_index = index + 1; } while (index > -1); } // jdk must not support "java.library.path" so assume it is loaded else tmex_loaded = true; if (tmex_loaded) { try { System.loadLibrary("ibtmjava"); driverLoaded = true; } catch (UnsatisfiedLinkError e) { if (search_path != null) { System.err.println( "Could not load Java to TMEX-native bridge driver: ibtmjava.dll"); } else { System.err.println( "Native drivers not found, download iButton-TMEX RTE Win32 from www.ibutton.com"); } } } else System.err.println( "Native drivers not found, download iButton-TMEX RTE Win32 from www.ibutton.com"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -