com.alarexgroup.m2mplf.adapters.serial
Interface SerialAdapterListener

All Known Implementing Classes:
SerialDemo
public interface SerialAdapterListener

Listener for SerialAdapter
Methods of this interface are called in case of incomming data on serial port.

Method Summary
 void onSerialDataReceived(byte[] receivedData, int adapterId)
          Method is called if there were incomming data on port including data closing sequence, see: SerialAdapter.DATA_SEPARATOR_CR_LF and more.
 void onSerialDataReceivedInStream(java.io.InputStream receivedData, int adapterId)
          Method is called when there are incomming data on port.
 

Method Detail

onSerialDataReceived

void onSerialDataReceived(byte[] receivedData,
                          int adapterId)
Method is called if there were incomming data on port including data closing sequence, see: SerialAdapter.DATA_SEPARATOR_CR_LF and more.

Parameters:
adapterId - ID of adapter, that called this method
receivedData - Byte array of incomming data. Data contain closing char sequence.

onSerialDataReceivedInStream

void onSerialDataReceivedInStream(java.io.InputStream receivedData,
                                  int adapterId)
Method is called when there are incomming data on port.

This method can handle data with unknown length and withou data closing sequences.

Example of data handling:

public void onSerialDataReceivedInStream(InputStream receivedData, int adapterId) {
     int nums;
     try {
          nums = receivedData.available();
          byte[] b = new byte[nums];
          receivedData.read(b);
          serialAdapter.writeData(b);
     } catch (IOException ex) {
          ex.printStackTrace();
     }

}

Parameters:
adapterId - ID of adapter that called this method
receivedData - Received data - refference to InputStream with received data.
See Also:
SerialAdapter.openPort(String)