|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.dalsemi.onewire.adapter.NetAdapter
NetAdapter is a network-based DSPortAdapter. It allows for the use of an actual DSPortAdapter which isn't on the local machine, but rather is connected to another device which is reachable via a TCP/IP network connection.
The syntax for the selectPort(String)
command is the
hostname of the computer which hosts the actual DSPortAdapter and the
TCP/IP port that the host is listening on. If the port number is not
specified, a default value of 6161 is used. Here are a few examples to
illustrate the syntax:
In the onewire.properties file, you can add a host to your list of valid
hosts by making a NetAdapter.host with an integer to distinguish the hosts.
There is no limit on the number of hosts which can appear in this list, but
the first one must be numbered '0'. These hosts will then be returned in
the list of valid 'ports' from the selectPortNames()
method.
Note that there do not have to be any servers returned from
selectPortNames()
for the NetAdapter to be able to connect
to them (so it isn't necessary to add these entries for it to function),
but applications which allow a user to automatically select an appropriate
adapter and a port from a given list will not function properly without it.
For example:
The multicast socket technique allows you to automatically discover
hosts on your subnet which are listening for multicast packets. By
default, the multicast discovery of NetAdapter hosts is disabled.
When enabled, the NetAdapter creates a multicast socket and looks for servers
every time you call selectPortNames()
. This will add a
1 second delay (due to the socket timeout) on calling the method. If you'd
like to enable this feature, add the following line to your
onewire.properties file:
Once the NetAdapter is connected with a host, a version check is performed followed by a simple authentication step. The authentication is dependent upon a secret shared between the NetAdapter and the host. Both will use a default value, that each will agree with if you don't provide a secret of your own. To set the secret, add the following line to your onewire.properties file:
All of the above mentioned properties can be set on the command-line as well as being set in the onewire.properties file. To set the properties on the command-line, use the -D option: java -DNetAdapter.Secret="custom secret" myApplication
The following is a list of all parameters that can be set for the
NetAdapter, followed by default values where applicable.
If you wanted added security on the communication channel, an SSL socket
(or similar custom socket implementation) can be used by circumventing the
standard DSPortAdapter's selectPort(String)
and using the
NetAdapter-specific selectPort(Socket)
. For example:
NetAdapter na = new NetAdapter(); Socket secureSocket = // insert fancy secure socket implementation here na.selectPort(secureSocket);For information on setting up the host component, see the JavaDocs for the
NetAdapterHost
NetAdapterHost
Constructor Summary | |
NetAdapter()
Creates an instance of NetAdapter that isn't connected. |
Method Summary | |
boolean |
adapterDetected()
Detects adapter presence on the selected port. |
boolean |
beginExclusive(boolean blocking)
Gets exclusive use of the 1-Wire to communicate with an iButton or 1-Wire Device. |
boolean |
canBreak()
Returns whether adapter can physically support 0 volt 'break' mode. |
boolean |
canDeliverPower()
Returns whether the adapter can physically support strong 5 volt power mode. |
boolean |
canDeliverSmartPower()
Returns whether the adapter can physically support "smart" strong 5 volt power mode. |
boolean |
canFlex()
Returns whether the adapter can physically support flex speed mode. |
boolean |
canHyperdrive()
Returns whether the adapter can physically support hyperdrive mode. |
boolean |
canOverdrive()
Returns whether adapter can physically support overdrive mode. |
boolean |
canProgram()
Returns whether adapter can physically support 12 volt power mode. |
void |
dataBlock(byte[] dataBlock,
int off,
int len)
Sends a block of data and returns the data received in the same array. |
void |
endExclusive()
Relinquishes exclusive control of the 1-Wire Network. |
void |
excludeFamily(byte[] family)
Takes an array of bytes containing family codes to avoid when finding iButtons or 1-Wire devices. |
void |
excludeFamily(int family)
Takes an integer family code to avoid when searching for iButtons. |
boolean |
findFirstDevice()
Returns true if the first iButton or 1-Wire device
is found on the 1-Wire Network. |
boolean |
findNextDevice()
Returns true if the next iButton or 1-Wire device
is found. |
void |
freePort()
Frees ownership of the selected port, if it is currently owned, back to the system. |
String |
getAdapterName()
Retrieves the name of the port adapter as a string. |
void |
getAddress(byte[] address)
Copies the 'current' 1-Wire device address being used by the adapter into the array. |
boolean |
getBit()
Gets a bit from the 1-Wire Network. |
void |
getBlock(byte[] arr,
int len)
Gets a block of data from the 1-Wire Network and write it into the provided array. |
void |
getBlock(byte[] arr,
int off,
int len)
Gets a block of data from the 1-Wire Network and write it into the provided array. |
byte[] |
getBlock(int len)
Gets a block of data from the 1-Wire Network. |
int |
getByte()
Gets a byte from the 1-Wire Network. |
String |
getClassVersion()
Retrieves a version string for this class. |
String |
getPortName()
Retrieves the name of the selected port as a String . |
Enumeration |
getPortNames()
Retrieves a list of the platform appropriate port names for this adapter. |
String |
getPortTypeDescription()
Retrieves a description of the port required by this port adapter. |
int |
getSpeed()
Returns the current data transfer speed on the 1-Wire Network. |
void |
pingHost()
Sends a ping to the host, just to keep the connection alive. |
void |
putBit(boolean bitValue)
Sends a bit to the 1-Wire Network. |
void |
putByte(int byteValue)
Sends a byte to the 1-Wire Network. |
int |
reset()
Sends a Reset to the 1-Wire Network. |
void |
resetSecret()
Resets the secret to be the default stored in the onewire.properties file (if there is one), or the default as defined by NetAdapterConstants. |
boolean |
selectPort(Socket sock)
New method, unique to NetAdapter. |
boolean |
selectPort(String portName)
Specifies a platform appropriate port name for this adapter. |
void |
setNoResetSearch()
Sets the 1-Wire Network search to not perform a 1-Wire reset before a search. |
void |
setPowerDuration(int timeFactor)
Sets the duration to supply power to the 1-Wire Network. |
void |
setPowerNormal()
Sets the 1-Wire Network voltage to normal level. |
void |
setProgramPulseDuration(int timeFactor)
Sets the duration for providing a program pulse on the 1-Wire Network. |
void |
setSearchAllDevices()
Sets the 1-Wire Network search to find all iButtons and 1-Wire devices whether they are in an 'Alarm' state or not and restores the default setting of providing a 1-Wire reset command before each search. |
void |
setSearchOnlyAlarmingDevices()
Sets the 1-Wire Network search to find only iButtons and 1-Wire devices that are in an 'Alarm' state that signals a need for attention. |
void |
setSecret(String secret)
Sets the shared secret for authenticating this NetAdapter with a NetAdapterHost. |
void |
setSpeed(int speed)
Sets the new speed of data transfer on the 1-Wire Network. |
void |
startBreak()
Sets the 1-Wire Network voltage to 0 volts. |
boolean |
startPowerDelivery(int changeCondition)
Sets the 1-Wire Network voltage to supply power to a 1-Wire device. |
boolean |
startProgramPulse(int changeCondition)
Sets the 1-Wire Network voltage to eprom programming level. |
void |
targetAllFamilies()
Removes any selectivity during a search for iButtons or 1-Wire devices by family type. |
void |
targetFamily(byte[] family)
Takes an array of bytes to use for selectively searching for acceptable family codes. |
void |
targetFamily(int family)
Takes an integer to selectively search for this desired family type. |
Constructor Detail |
public NetAdapter()
Method Detail |
public void setSecret(String secret)
secret
- the new secret for authenticating this client.public void resetSecret()
public void pingHost() throws OneWireException, OneWireIOException
public boolean adapterDetected() throws OneWireIOException, OneWireException
true
if the adapter is confirmed to be connected to
the selected port, false
if the adapter is not connected.OneWireIOException
- OneWireException
- public String getAdapterName()
String
representation of the port adapter.public String getPortTypeDescription()
String
description of the port type required.public String getClassVersion()
public Enumeration getPortNames()
OneWireException
exception.Enumeration
of type String
that contains the port
namespublic boolean selectPort(String portName) throws OneWireIOException, OneWireException
PortInUseException
will be thrown.portName
- Address to connect this NetAdapter to, in the form of
"hostname:port". For example, "shughes.dalsemi.com:6161", where 6161
is the port number to connect to. The use of NetAdapter.DEFAULT_PORT
is recommended.true
if the port was aquired, false
if the port is not available.OneWireIOException
- If port does not exist, or unable to communicate with port.OneWireException
- If port does not existpublic boolean selectPort(Socket sock) throws OneWireIOException, OneWireException
sock
- Socket connection to NetAdapterHosttrue
if connection to host was successfulOneWireIOException
- If port does not exist, or unable to communicate with port.OneWireException
- If port does not existpublic void freePort() throws OneWireException
OneWireException
- If port does not existpublic String getPortName() throws OneWireException
String
.String
of selected portOneWireException
- if valid port not yet selectedpublic boolean canOverdrive() throws OneWireIOException, OneWireException
true
if this port adapter can do OverDrive,
false
otherwise.OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire
adapterpublic boolean canHyperdrive() throws OneWireIOException, OneWireException
true
if this port adapter can do HyperDrive,
false
otherwise.OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire
adapterpublic boolean canFlex() throws OneWireIOException, OneWireException
true
if this port adapter can do flex speed,
false
otherwise.OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire
adapterpublic boolean canProgram() throws OneWireIOException, OneWireException
true
if this port adapter can do Program voltage,
false
otherwise.OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire
adapterpublic boolean canDeliverPower() throws OneWireIOException, OneWireException
true
if this port adapter can do strong 5 volt
mode, false
otherwise.OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire
adapterpublic boolean canDeliverSmartPower() throws OneWireIOException, OneWireException
true
if this port adapter can do "smart" strong
5 volt mode, false
otherwise.OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire
adapterpublic boolean canBreak() throws OneWireIOException, OneWireException
true
if this port adapter can do break,
false
otherwise.OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire
adapterpublic boolean findFirstDevice() throws OneWireIOException, OneWireException
true
if the first iButton or 1-Wire device
is found on the 1-Wire Network.
If no devices are found, then false
will be returned.true
if an iButton or 1-Wire device is found.OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic boolean findNextDevice() throws OneWireIOException, OneWireException
true
if the next iButton or 1-Wire device
is found. The previous 1-Wire device found is used
as a starting point in the search. If no more devices are found
then false
will be returned.true
if an iButton or 1-Wire device is found.OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic void getAddress(byte[] address)
address
- An array to be filled with the current iButton address.Address
public void setSearchOnlyAlarmingDevices()
setNoResetSearch()
public void setNoResetSearch()
public void setSearchAllDevices()
setNoResetSearch()
public void targetAllFamilies()
targetFamily(int)
,
targetFamily(byte[])
,
excludeFamily(int)
,
excludeFamily(byte[])
public void targetFamily(int family)
family
- the code of the family type to target for searchesAddress
,
targetAllFamilies()
public void targetFamily(byte[] family)
family
- array of the family types to target for searchesAddress
,
targetAllFamilies()
public void excludeFamily(int family)
family
- the code of the family type NOT to target in searchesAddress
,
targetAllFamilies()
public void excludeFamily(byte[] family)
family
- array of family cods NOT to target for searchesAddress
,
targetAllFamilies()
public boolean beginExclusive(boolean blocking) throws OneWireException
It can be called through the OneWireContainer class by the end application if they want to ensure exclusive use. If it is not called around several methods then it will be called inside each method.
blocking
- true
if want to block waiting
for an excluse access to the adaptertrue
if blocking was false and a
exclusive session with the adapter was aquiredOneWireException
- on a setup error with the 1-Wire adapterpublic void endExclusive()
public int reset() throws OneWireIOException, OneWireException
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic void putBit(boolean bitValue) throws OneWireIOException, OneWireException
bitValue
- the bit value to send to the 1-Wire Network.OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic boolean getBit() throws OneWireIOException, OneWireException
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic void putByte(int byteValue) throws OneWireIOException, OneWireException
byteValue
- the byte value to send to the 1-Wire Network.OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic int getByte() throws OneWireIOException, OneWireException
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic byte[] getBlock(int len) throws OneWireIOException, OneWireException
len
- length of data bytes to receiveOneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic void getBlock(byte[] arr, int len) throws OneWireIOException, OneWireException
arr
- array in which to write the received byteslen
- length of data bytes to receiveOneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic void getBlock(byte[] arr, int off, int len) throws OneWireIOException, OneWireException
arr
- array in which to write the received bytesoff
- offset into the array to startlen
- length of data bytes to receiveOneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic void dataBlock(byte[] dataBlock, int off, int len) throws OneWireIOException, OneWireException
dataBlock
- array of data to transfer to and from the 1-Wire Network.off
- offset into the array of data to startlen
- length of data to send / receive starting at 'off'OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic void setPowerDuration(int timeFactor) throws OneWireIOException, OneWireException
Note: to avoid getting an exception, use the canDeliverPower() and canDeliverSmartPower() method to check it's availability.
timeFactor
- OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic boolean startPowerDelivery(int changeCondition) throws OneWireIOException, OneWireException
Note: to avoid getting an exception, use the canDeliverPower() and canDeliverSmartPower() method to check it's availability.
changeCondition
- true
if the voltage change was successful,
false
otherwise.OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic void setProgramPulseDuration(int timeFactor) throws OneWireIOException, OneWireException
Note: to avoid getting an exception, use the canDeliverPower() method to check it's availability.
timeFactor
- OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapterpublic boolean startProgramPulse(int changeCondition) throws OneWireIOException, OneWireException
Note: to avoid getting an exception, use the canProgram() method to check it's availability.
changeCondition
- true
if the voltage change was successful,
false
otherwise.OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
or the adapter does not support this operationpublic void startBreak() throws OneWireIOException, OneWireException
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
or the adapter does not support this operationpublic void setPowerNormal() throws OneWireIOException, OneWireException
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
or the adapter does not support this operationpublic void setSpeed(int speed) throws OneWireIOException, OneWireException
speed
- OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
or the adapter does not support this operationpublic int getSpeed()
int
representing the current 1-Wire speed
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |