public class TcpSocketChannel extends Object implements ICommandLineDevice, IBytesCommand
Constructor and Description |
---|
TcpSocketChannel(InetAddress inetAddress,
int portNumber,
int timeout,
boolean verbose,
TcpSocketPort.ConnectionMode connectionMode) |
TcpSocketChannel(String hostIp,
int portNumber,
int timeout,
boolean verbose,
TcpSocketPort.ConnectionMode connectionMode) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
close(boolean force) |
void |
connect() |
void |
flushInput() |
BufferedReader |
getBufferedIn() |
InputStream |
getIn() |
OutputStream |
getOut() |
boolean |
getVerbose() |
String |
getVersion()
Returns the hardware version (not the version of the driver software).
|
boolean |
isValid()
Tries to identify instances that are not valid.
|
void |
open()
Opens the device with previously set parameters.
|
byte[] |
readBytes(int length) |
String |
readString()
Reads a line of text.
|
String |
readString(boolean wait)
Reads a line of text.
|
boolean |
ready()
Tells whether this stream is ready to be read.
|
void |
sendBytes(byte[] cmd) |
void |
sendString(String cmd)
Sends a command (a String) to the instance.
|
void |
setDebug(int debug)
Sets a debug parameter.
|
void |
setTimeout(int timeout)
Set timeout in milliseconds.
|
void |
setVerbosity(boolean verbose)
Sets a verbosity flag, causing commands to be executed verbosely.
|
public TcpSocketChannel(String hostIp, int portNumber, int timeout, boolean verbose, TcpSocketPort.ConnectionMode connectionMode) throws UnknownHostException
hostIp
- portNumber
- timeout
- verbose
- connectionMode
- UnknownHostException
public TcpSocketChannel(InetAddress inetAddress, int portNumber, int timeout, boolean verbose, TcpSocketPort.ConnectionMode connectionMode)
inetAddress
- portNumber
- timeout
- verbose
- connectionMode
- public void connect() throws IOException
IOException
public void close(boolean force) throws IOException
force
- IOException
public OutputStream getOut()
public InputStream getIn()
public BufferedReader getBufferedIn()
public boolean isValid()
IHarcHardware
isValid
in interface IHarcHardware
public void setTimeout(int timeout) throws SocketException
IHarcHardware
setTimeout
in interface IHarcHardware
timeout
- Timeout in milliseconds.SocketException
public void setVerbosity(boolean verbose)
IHarcHardware
setVerbosity
in interface IHarcHardware
verbose
- on or offpublic void setDebug(int debug)
IHarcHardware
setDebug
in interface IHarcHardware
public void sendString(String cmd) throws IOException
ICommandLineDevice
sendString
in interface ICommandLineDevice
cmd
- Command string to be sent.IOException
public String readString() throws IOException
ICommandLineDevice
readString
in interface ICommandLineDevice
IOException
public String readString(boolean wait) throws IOException
ICommandLineDevice
readString
in interface ICommandLineDevice
wait
- if true, wait until something arrives, otherwise return null if nothing there.IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void sendBytes(byte[] cmd) throws IOException
sendBytes
in interface IBytesCommand
IOException
public byte[] readBytes(int length) throws IOException
readBytes
in interface IBytesCommand
IOException
public String getVersion()
IHarcHardware
getVersion
in interface IHarcHardware
public void open()
IHarcHardware
open
in interface IHarcHardware
public boolean ready() throws IOException
ICommandLineDevice
ready
in interface ICommandLineDevice
IOException
- If an I/O error occurspublic void flushInput() throws IOException
flushInput
in interface ICommandLineDevice
IOException
public boolean getVerbose()
Copyright © 2016. All rights reserved.