com.eurotech.framework.core.comm
Class CommConnectionImpl

java.lang.Object
  extended by com.eurotech.framework.core.comm.CommConnectionImpl
All Implemented Interfaces:
CommConnection, javax.microedition.io.Connection, javax.microedition.io.InputConnection, javax.microedition.io.OutputConnection, javax.microedition.io.StreamConnection

public class CommConnectionImpl
extends Object
implements CommConnection


Constructor Summary
CommConnectionImpl(CommURI commUri, int mode, boolean timeouts)
           
 
Method Summary
 void close()
           
 byte[] flushSerialBuffer()
          Reads all bytes that are waiting in the serial port buffer and returns them in an array.
 CommURI getURI()
          Returns the URI for this connection.
 DataInputStream openDataInputStream()
           
 DataOutputStream openDataOutputStream()
           
 InputStream openInputStream()
           
 OutputStream openOutputStream()
           
 byte[] sendCommand(byte[] command, int timeout)
          Sends and array of bytes to a CommConnection and returns an array of bytes that represents the 'response' to the command.
 byte[] sendCommand(byte[] command, int timeout, int demark)
           
 void sendMessage(byte[] message)
          Sends and array of bytes to a CommConnection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommConnectionImpl

public CommConnectionImpl(CommURI commUri,
                          int mode,
                          boolean timeouts)
                   throws IOException,
                          javax.comm.NoSuchPortException,
                          javax.comm.PortInUseException
Throws:
IOException
javax.comm.NoSuchPortException
javax.comm.PortInUseException
Method Detail

getURI

public CommURI getURI()
Description copied from interface: CommConnection
Returns the URI for this connection.

Specified by:
getURI in interface CommConnection
Returns:
this connection URI

openDataInputStream

public DataInputStream openDataInputStream()
                                    throws IOException
Specified by:
openDataInputStream in interface javax.microedition.io.InputConnection
Throws:
IOException

openInputStream

public InputStream openInputStream()
                            throws IOException
Specified by:
openInputStream in interface javax.microedition.io.InputConnection
Throws:
IOException

openDataOutputStream

public DataOutputStream openDataOutputStream()
                                      throws IOException
Specified by:
openDataOutputStream in interface javax.microedition.io.OutputConnection
Throws:
IOException

openOutputStream

public OutputStream openOutputStream()
                              throws IOException
Specified by:
openOutputStream in interface javax.microedition.io.OutputConnection
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface CommConnection
Specified by:
close in interface javax.microedition.io.Connection
Throws:
IOException

sendMessage

public void sendMessage(byte[] message)
                 throws EsfException,
                        IOException
Description copied from interface: CommConnection
Sends and array of bytes to a CommConnection

Specified by:
sendMessage in interface CommConnection
Parameters:
message - the array of bytes to send to the CommConnection
Throws:
EsfException
IOException

sendCommand

public byte[] sendCommand(byte[] command,
                          int timeout)
                   throws EsfException,
                          IOException
Description copied from interface: CommConnection
Sends and array of bytes to a CommConnection and returns an array of bytes that represents the 'response' to the command. If the timeout is exceeded before any bytes are read on the InputStream null is returned. This is meant to be used in common command/response type situations when communicating with serial devices

Specified by:
sendCommand in interface CommConnection
Parameters:
command - the array of bytes to send to the CommConnection
timeout - the maximum length of time to wait before returning a null response in the event no response is ever returned.
Returns:
an array of bytes representing the response
Throws:
EsfException
IOException

sendCommand

public byte[] sendCommand(byte[] command,
                          int timeout,
                          int demark)
                   throws EsfException,
                          IOException
Specified by:
sendCommand in interface CommConnection
Throws:
EsfException
IOException

flushSerialBuffer

public byte[] flushSerialBuffer()
                         throws EsfException,
                                IOException
Description copied from interface: CommConnection
Reads all bytes that are waiting in the serial port buffer and returns them in an array. This can be used to read unsolicited messages from an attached serial device.

Specified by:
flushSerialBuffer in interface CommConnection
Returns:
the array of bytes buffered on the InputStream if any
Throws:
EsfException
IOException


Copyright © 2013. All Rights Reserved.