I'm trying to send data to an Xbee antenna with a serial port in Java using the jssc library.
I want to be able to send and receive multiple data packets on the same connection.
The problem I have is that my code only send my first packet after either I close the port, or I end the program.
I based my code on the tutorial at this link: http://www.codeproject.com/Tips/801262/Sending-and-receiving-strings-from-COM-port-via-jS
Here is my code:
serialPort = new SerialPort("COM4");
try {
// opening port
serialPort.openPort();
serialPort.setParams(SerialPort.BAUDRATE_38400,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN |
SerialPort.FLOWCONTROL_RTSCTS_OUT);
serialPort.addEventListener(new PortReader(), SerialPort.MASK_RXCHAR);
byte[] fifo = new byte[13];
fifo[0] = 0x7E;
fifo[1] = 0x00;
fifo[2] = 0x09;
fifo[3] = 0x01;
fifo[4] = 0x01;
fifo[5] = 0x00;
fifo[6] = 0x01;
fifo[7] = 0x00;
fifo[8] = 0x54;
fifo[9] = 0x65;
fifo[10] = 0x73;
fifo[11] = 0x74;
fifo[12] = 0x5C;
result = serialPort.writeBytes(fifo);
The event for the reception of data is working, my only problem is sending. I already checked the baud rate of the other device my Xbee is talking to.
EDIT
When I connect my Xbee to an FT232's UART (http://www.seeedstudio.com/depot/UartSBee-V5-p-1752.html), this situation occurs.
When I connect directly the RS-232 to the XBee, the transmission is sent immediately.
How long are you waiting for the bytes to go out before you close/exit? You might need to go into the FTDI driver properties and update the settings for packetization and latency. It's likely waiting for more data in the driver on your PC before sending it over the USB connection to the FT232.
If you have your program wait a few seconds, you should find that the message is eventually going out without needing to close the serial port or exit the program (which closes the serial port as well).