Package com.dalsemi.onewire.adapter
Class SerialService
java.lang.Object
com.dalsemi.onewire.adapter.SerialService
- All Implemented Interfaces:
gnu.io.SerialPortEventListener
,EventListener
The SerialService class provides serial IO services to the USerialAdapter class.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SerialService
(String strComPort) this constructor only for use in the static method: getSerialService(String) -
Method Summary
Modifier and TypeMethodDescriptionint
boolean
beginExclusive
(boolean blocking) Gets exclusive use of the 1-Wire to communicate with an iButton or 1-Wire Device.static void
Cleans up the resources used by the thread argument.void
Close this serial port.void
Relinquishes exclusive control of the 1-Wire Network.void
flush()
int
static Enumeration<String>
static SerialService
getSerialService
(String strComPort) boolean
Check if this thread has exclusive control of the port.boolean
isDTR()
boolean
boolean
isRTS()
void
openPort()
void
openPort
(gnu.io.SerialPortEventListener spel) int
read()
int
read
(byte[] buffer) int
read
(byte[] buffer, int offset, int length) int
readWithTimeout
(byte[] buffer, int offset, int length) char[]
readWithTimeout
(int length) void
sendBreak
(int duration) Send a break on this serial portvoid
serialEvent
(gnu.io.SerialPortEvent spe) SerialPortEventListener method.void
setBaudRate
(int baudRate) void
setDTR
(boolean newDTR) void
setNotifyOnDataAvailable
(boolean notify) void
setRTS
(boolean newRTS) void
write
(byte[] data) void
write
(byte[] data, int offset, int length) void
write
(char data) void
write
(char[] data) void
write
(char[] data, int offset, int length) void
write
(int data) void
-
Constructor Details
-
SerialService
this constructor only for use in the static method: getSerialService(String)
-
-
Method Details
-
CleanUpByThread
Cleans up the resources used by the thread argument. If another thread starts communicating with this port, and then goes away, there is no way to relinquish the port without stopping the process. This method allows other threads to clean up.- Parameters:
thread
- that may have used aUSerialAdapter
-
getSerialService
-
serialEvent
public void serialEvent(gnu.io.SerialPortEvent spe) SerialPortEventListener method. This just calls the notify method on this object, so that all blocking methods are kicked awake whenever a serialEvent occurs.- Specified by:
serialEvent
in interfacegnu.io.SerialPortEventListener
-
openPort
- Throws:
IOException
-
openPort
- Throws:
IOException
-
setNotifyOnDataAvailable
public void setNotifyOnDataAvailable(boolean notify) -
getSerialPortIdentifiers
-
getPortName
-
isPortOpen
public boolean isPortOpen() -
isDTR
public boolean isDTR() -
setDTR
public void setDTR(boolean newDTR) -
isRTS
public boolean isRTS() -
setRTS
public void setRTS(boolean newRTS) -
sendBreak
public void sendBreak(int duration) Send a break on this serial port- Parameters:
duration
- - break duration in ms
-
getBaudRate
public int getBaudRate() -
setBaudRate
- Throws:
IOException
-
closePort
Close this serial port.- Throws:
IOException
- - if port is in use by another application
-
flush
- Throws:
IOException
-
beginExclusive
public boolean beginExclusive(boolean blocking) Gets exclusive use of the 1-Wire to communicate with an iButton or 1-Wire Device. This method should be used for critical sections of code where a sequence of commands must not be interrupted by communication of threads with other iButtons, and it is permissible to sustain a delay in the special case that another thread has already been granted exclusive access and this access has not yet been relinquished.- Parameters:
blocking
-true
if want to block waiting for exclusive access to the adapter- Returns:
true
if blocking was false and a exclusive session with the adapter was acquired
-
endExclusive
public void endExclusive()Relinquishes exclusive control of the 1-Wire Network. This command dynamically marks the end of a critical section and should be used when exclusive control is no longer needed. -
haveExclusive
public boolean haveExclusive()Check if this thread has exclusive control of the port. -
available
- Throws:
IOException
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
readWithTimeout
- Throws:
IOException
-
readWithTimeout
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-