Home/Support/Support Forum/JSSC + Xbee Explorer Dropping Bytes

JSSC + Xbee Explorer Dropping Bytes

0 votes
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[]) {
Main.launch(args);
}

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

port.openPort();
port.addEventListener(this);

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

AnchorPane anchor = new AnchorPane();
anchor.getChildren().add(txtSerial);

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

@Override
public void stop() throws SerialPortException {
port.removeEventListener();
port.closePort();
}

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

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 & 0xFF)).replace(" ", "0") + " ");
}
txtSerial.appendText("\n");
}

});

} catch (SerialPortException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
asked Jul 22, 2014 in RF Solutions and XBee by adbrock New to the Community (0 points)
edited Jul 22, 2014 by adbrock

Please log in or register to answer this question.

2 Answers

0 votes
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.
answered Nov 12, 2014 by mvut Veteran of the Digi Community (13,650 points)
0 votes
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.
answered Mar 27, 2015 by victor296621 New to the Community (1 point)
...