com.ibutton
Class SerialAdapterSmall

java.lang.Object
  |
  +--com.ibutton.SerialAdapterSmall

public class SerialAdapterSmall
extends java.lang.Object
implements PortAdapter

Serial Port adapter class for com.iButton package that implements the iButton methods using the DS2480 serial device.


Field Summary
static int OW_EXTERNAL
           
static int OW_INTERNAL
           
 
Constructor Summary
SerialAdapterSmall()
          Initialize SerialAdapter settings.
 
Method Summary
 boolean Adapter5VActivate(int interval)
          Activate the strong-5volts operation now.
 boolean Adapter5VCancel()
          Cancel the current strong-5volts operation.
 boolean Adapter5VPrime()
          Prime the strong-5volts operation to occur after the next iBDataBit.
 boolean Adapter5VPrimeByte()
          Prime the strong-5volts operation to occur after the next iBDataByte.
 boolean iBAccess()
          Initialize communications with the currently selected iButton.
 boolean iBDataBit(int databit)
          Read/Write a single bit of data from/to the currently selected iButton.
 boolean iBDataBlock(int[] input, int start, int length)
          Read/Write a block of data from/to the currently selected iButton.
 int iBDataByte(int databyte)
          Read/Write a single byte of data from/to the currently selected iButton.
 boolean iBDOWCheck()
          Loads the hardware specific drivers needed to perform One-Wire communications.
 java.lang.String iBFailReason()
          Returns the reason for the previous fail.
 boolean iBFastAccess()
          Resets and initializes communications with the currently selected iButton without verifying that it is still connected to the One-Wire bus.
 boolean iBFirst()
          Find the first iButton on the One-Wire bus.
 boolean iBGndTest()
          Test to see if the One-Wire bus is grounded.
 boolean iBKeyClose()
          Closes a One-Wire communications session on the currently selected port.
 boolean iBKeyOpen()
          Opens a One-Wire communications session on the currently selected port.
 boolean iBNext()
          Find the next iButton on the One-Wire bus in the current enumeration.
 boolean iBOverdriveOff()
          Shifts the One-Wire bus to normal speed.
 boolean iBOverdriveOn()
          Shifts the One-Wire bus to Overdrive speed.
 boolean iBReset()
          Resets communications for all devices on the One-Wire bus.
 int[] iBROMData()
          Retrieve the ROM Id of the currently selected iButton.
 boolean iBROMData(int[] romId)
          Sets the internal ROM Id buffer to the given array.
 boolean iBSetup(int newPortNumber)
          Select the port that hosts the One-Wire adapter by specifying the port number.
 boolean iBStream(int[] data, int len)
          This method does following operations: Access the current button using fast access.
 boolean iBStrongAccess()
          Resets the currently selected iButton and verify whether (or not) it is still connected to the One-Wire bus.
 java.lang.String iBVersion()
          Returns the version of the iButton library.
 boolean releasePort()
          Releases the port resources used by this SerialAdapterSmall object.
 boolean SetAdapter5VTime(int interval)
          Set the strong-5volts interval time.
 boolean setAdapterSpeed(int baud)
          Attempt to set the data transfer rate of the currently selected port.
 boolean SetAdapterSpeed(int baud)
          Deprecated. replaced by setAdapterSpeed(int baud).
 void setAdapterSpeedOptimum()
          Attempt to set the data transfer rate of the currently selected port to its optimum value.
 boolean SetAdapterType(int type, java.lang.String ad)
          Sets the adapter type using the type (PORT_TYPE_PARALLEL, PORT_TYPE_SERIAL,...) and a device name ("COM1", "/dev/ttya",...).
 void setPortDeviceName(int typeCode, java.lang.String portDevice)
          Set the port device name as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OW_EXTERNAL

public static final int OW_EXTERNAL

OW_INTERNAL

public static final int OW_INTERNAL
Constructor Detail

SerialAdapterSmall

public SerialAdapterSmall()
Initialize SerialAdapter settings.
Method Detail

SetAdapterType

public boolean SetAdapterType(int type,
                              java.lang.String ad)
Sets the adapter type using the type (PORT_TYPE_PARALLEL, PORT_TYPE_SERIAL,...) and a device name ("COM1", "/dev/ttya",...).
Specified by:
SetAdapterType in interface PortAdapter
Parameters:
type - Type of port being accessed.
ad - Device name for the port being accessed.
Returns:
true if the Adapter can be loaded, false otherwise

iBSetup

public boolean iBSetup(int newPortNumber)
Select the port that hosts the One-Wire adapter by specifying the port number. If the device name is null in setAdaptor type then the port number is used, otherwise it is ignored.
Specified by:
iBSetup in interface PortAdapter
Parameters:
newPortNumber - com port number that the One-Wire adapter is on.
Returns:
'true' if no error occurred.

iBGndTest

public boolean iBGndTest()
Test to see if the One-Wire bus is grounded.
Specified by:
iBGndTest in interface PortAdapter
Returns:
true if the bus is not grounded.

iBDOWCheck

public boolean iBDOWCheck()
Loads the hardware specific drivers needed to perform One-Wire communications. May not apply to all iButton port adapters.
Specified by:
iBDOWCheck in interface PortAdapter
Returns:
'true' if the drivers were loaded or no drivers were required. 'false' if could not load the drivers.

iBKeyOpen

public boolean iBKeyOpen()
Opens a One-Wire communications session on the currently selected port. iBKeyClose should be called after the session is complete. iBKeyOpen and iBKeyClose administrate sharing with other devices on the port (i.e. Printers,...). Certain hardware configurations may not allow One-Wire communication before iBKeyOpen is executed.
Specified by:
iBKeyOpen in interface PortAdapter
Returns:
'true' if the One-Wire session was acquired

iBKeyClose

public boolean iBKeyClose()
Closes a One-Wire communications session on the currently selected port. Each call to iBKeyOpen should be followed by a call to iBKeyClose after a data transfer session has been completed.
Specified by:
iBKeyClose in interface PortAdapter
Returns:
'true' if the One-Wire session was released

iBFirst

public boolean iBFirst()
Find the first iButton on the One-Wire bus.
Specified by:
iBFirst in interface PortAdapter
Returns:
'true' if an iButton is found and the ROM ID is in the internal buffer. 'false' if no iButton is on the bus.

iBNext

public boolean iBNext()
Find the next iButton on the One-Wire bus in the current enumeration. Calling this method again after a false return will restart the iButton enumeration.
Specified by:
iBNext in interface PortAdapter
Returns:
'true' if an iButton is found and the ROM ID is in the internal buffer. 'false' if the last iButton was the last device in the iButton enumeration.

iBAccess

public boolean iBAccess()
Initialize communications with the currently selected iButton.
Specified by:
iBAccess in interface PortAdapter
Returns:
true if iButton responded. False otherwise.

iBFastAccess

public boolean iBFastAccess()
Resets and initializes communications with the currently selected iButton without verifying that it is still connected to the One-Wire bus.
Specified by:
iBFastAccess in interface PortAdapter
Returns:
true if any iButton responded. False otherwise.

iBStrongAccess

public boolean iBStrongAccess()
Resets the currently selected iButton and verify whether (or not) it is still connected to the One-Wire bus.
Specified by:
iBStrongAccess in interface PortAdapter
Returns:
true if the iButton is connected.

iBROMData

public int[] iBROMData()
Retrieve the ROM Id of the currently selected iButton.
Specified by:
iBROMData in interface PortAdapter
Returns:
the serial number (ROM Id) of the currently selected iButton as an integer array.

iBROMData

public boolean iBROMData(int[] romId)
Sets the internal ROM Id buffer to the given array. This method is usually followed by a call to Access();
Specified by:
iBROMData in interface PortAdapter
Parameters:
romId - the ROM Id array to be used internally.
Returns:
true if the buffer is set successfully.

iBReset

public boolean iBReset()
Resets communications for all devices on the One-Wire bus.
Specified by:
iBReset in interface PortAdapter
Returns:
true if the reset succeeded.

iBDataByte

public int iBDataByte(int databyte)
Read/Write a single byte of data from/to the currently selected iButton.
Specified by:
iBDataByte in interface PortAdapter
Parameters:
databyte - Data to be written for write operations. Must be set to 0xFF for Read operations. Lower 8 bits of integer provided used.
Returns:
Data byte read from the One-Wire bus.

iBDataBit

public boolean iBDataBit(int databit)
Read/Write a single bit of data from/to the currently selected iButton.
Specified by:
iBDataBit in interface PortAdapter
Parameters:
databit - Data to be written for write operations. Must be set to 1 for Read operations.
Returns:
Data bit read from the One-Wire bus.

iBDataBlock

public boolean iBDataBlock(int[] input,
                           int start,
                           int length)
Read/Write a block of data from/to the currently selected iButton.
Specified by:
iBDataBlock in interface PortAdapter
Parameters:
input - Data buffer to be written for write operations. All elements must be set to 0xFF for Read operations.
start - Offset of data in input.
length - Length of data to transfer.
Returns:
'true' if no error occurred

iBOverdriveOn

public boolean iBOverdriveOn()
Shifts the One-Wire bus to Overdrive speed.
Specified by:
iBOverdriveOn in interface PortAdapter
Returns:
'true' if no error occurred

iBOverdriveOff

public boolean iBOverdriveOff()
Shifts the One-Wire bus to normal speed.
Specified by:
iBOverdriveOff in interface PortAdapter
Returns:
'true' if no error occurred

SetAdapter5VTime

public boolean SetAdapter5VTime(int interval)
Set the strong-5volts interval time. Strong-5volts is used to provide power to an iButton between communcation.
Specified by:
SetAdapter5VTime in interface PortAdapter
Parameters:
interval - strong 5 volt interval in microseconds
Returns:
'true' if no error occurred

Adapter5VPrimeByte

public boolean Adapter5VPrimeByte()
Prime the strong-5volts operation to occur after the next iBDataByte.
Specified by:
Adapter5VPrimeByte in interface PortAdapter
Returns:
'true' if no error occurred

Adapter5VPrime

public boolean Adapter5VPrime()
Prime the strong-5volts operation to occur after the next iBDataBit.
Specified by:
Adapter5VPrime in interface PortAdapter
Returns:
'true' if no error occurred

Adapter5VCancel

public boolean Adapter5VCancel()
Cancel the current strong-5volts operation.
Specified by:
Adapter5VCancel in interface PortAdapter
Returns:
'true' if no error occurred

Adapter5VActivate

public boolean Adapter5VActivate(int interval)
Activate the strong-5volts operation now. The strong-5volts interval is provided as a parameter. This function does nothing on the TINI board at the present time.
Specified by:
Adapter5VActivate in interface PortAdapter
Parameters:
interval - strong 5 volt interval in microseconds (not used)
Returns:
'true' if no error occurred

iBStream

public boolean iBStream(int[] data,
                        int len)
This method does following operations:
Specified by:
iBStream in interface PortAdapter
Parameters:
data - Data buffer to be written for write operations. All elements must be set to 0xFF for Read operations.
len - length of data buffer (0.21)
Returns:
'true' if an iButton presence was detected and the data was successfully sent to the One-Wire Bus.

iBVersion

public java.lang.String iBVersion()
Returns the version of the iButton library.
Specified by:
iBVersion in interface PortAdapter
Returns:
version string.

iBFailReason

public java.lang.String iBFailReason()
Returns the reason for the previous fail.
Specified by:
iBFailReason in interface PortAdapter
Returns:
fail message string.

setAdapterSpeed

public boolean setAdapterSpeed(int baud)
Attempt to set the data transfer rate of the currently selected port.
Specified by:
setAdapterSpeed in interface PortAdapter
Parameters:
baud - Speed desired in bits per second (values depend on adapter type).

setAdapterSpeedOptimum

public void setAdapterSpeedOptimum()
Attempt to set the data transfer rate of the currently selected port to its optimum value.
Specified by:
setAdapterSpeedOptimum in interface PortAdapter

SetAdapterSpeed

public boolean SetAdapterSpeed(int baud)
Deprecated. replaced by setAdapterSpeed(int baud).
Attempt to set the data transfer rate of the currently selected port.
Specified by:
SetAdapterSpeed in interface PortAdapter
Parameters:
baud - Speed desired in bits per second (values depend on adapter type).
Returns:
'true' if adapter speed set correctly (0.21)

setPortDeviceName

public void setPortDeviceName(int typeCode,
                              java.lang.String portDevice)
Set the port device name as a string. This device name will override the portnumber specified in iBSetup
Specified by:
setPortDeviceName in interface PortAdapter
Parameters:
typeCode - Device port type code. (not always used) (0.23)
portDevice - Device name for the port being accessed. (0.21)

releasePort

public boolean releasePort()
Releases the port resources used by this SerialAdapterSmall object.
Specified by:
releasePort in interface PortAdapter
Returns:
always returns true on TINI.