JSSC + Xbee Explorer Dropping Bytes

First my setup:

1 Xbee Pro S2B module with Coordinator API firmware (21A7) plugged into a xbee usb explorer board and in to my computer.

Another Xbee PRO S2B module with Router API firmware (23A7) plugged into a breadboard and configured to send analog samples on pins 19 and 18 every 5 seconds.

My computer is running a simple java program I’ve written to read the serial input from the coordinator module and write it to the screen. I’m using the JSSC library to read the port and JavaFX to write to the screen.

The problem:

Everything with the above setup works fine (I receive a packet which agrees with the packets I receive in XCTU) until the Xbee coordinator is unplugged or the computer loses power without closing the port. Once reconnected, the packets continue to come in at 5s intervals, but only the first 3 bytes are received and the rest seem to be dropped. The only method I’ve found to recover is to connect to the serial monitor in XCTU at which point everything works fine again. Unplugging and replugging the module, closing and reopening the port, plugging the module in to another computer, and restarting the computer all have no effect.

Any help/advice pointing me in the right direction to fix this problem is VERY much appreciated and thank you to everyone who read this far!

Java Code (Using JavaFX & JSSC):

public class Main extends Application implements SerialPortEventListener {
private TextArea txtSerial = new TextArea();
private SerialPort port;

public static void main(String args[]) {

public void start(Stage primaryStage) throws Exception {
	String[] portNameList = SerialPortList.getPortNames();
	port = new SerialPort(portNameList[0]);


	AnchorPane.setTopAnchor(txtSerial, 0.0);
	AnchorPane.setLeftAnchor(txtSerial, 0.0);
	AnchorPane.setBottomAnchor(txtSerial, 0.0);
	AnchorPane.setRightAnchor(txtSerial, 0.0);

	AnchorPane anchor = new AnchorPane();

	primaryStage.setScene(new Scene(anchor));
	primaryStage.setTitle("Serial Monitor");

public void stop() throws SerialPortException {

public void serialEvent(SerialPortEvent evt) {
	if (!evt.isRXCHAR())

	final byte[] data;
	try {
		data = port.readBytes(evt.getEventValue());
		Platform.runLater(new Runnable() {
			public void run() {
				for (int i = 0; i < data.length; i++) {
					txtSerial.appendText(String.format("%2s", Integer.toHexString(data[i] & 0xFF)).replace(" ", "0") + " ");



	} catch (SerialPortException e) {
		// TODO Auto-generated catch block


You are going to need to modify your application to look for the first 7E and verify that the 3rd byte is the expected 0x92 frame time. All other bytes before the 7E should be purged out.

Hi adbrock,

The scm is an alternative library to rxtx/javaxcom.
Wiki : http://www.embeddedunveiled.com/
Repository : https://github.com/RishiGupta12/serial-communication-manager
Video : https://www.youtube.com/watch?v=fYLQbelGunQ

It supports RS-232 control signals handshaking, monitoring and has been ported to Linux, MAC, Solaris and Windows operating system. It is consistent, portable, efficient, reliable, testable, extensible, modifiable, scalable library.