【发布时间】:2016-01-20 21:56:29
【问题描述】:
我正在尝试使用 jssc 库在 Java 中通过串行端口将数据发送到 Xbee 天线。
我希望能够在同一连接上发送和接收多个数据包。
我遇到的问题是我的代码仅在我关闭端口或结束程序后才发送我的第一个数据包。
我的代码基于此链接上的教程:http://www.codeproject.com/Tips/801262/Sending-and-receiving-strings-from-COM-port-via-jS
这是我的代码:
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);
接收数据的事件正在工作,我唯一的问题是发送。我已经检查了与我的 Xbee 通话的其他设备的波特率。
编辑
当我将 Xbee 连接到 FT232 的 UART (http://www.seeedstudio.com/depot/UartSBee-V5-p-1752.html) 时,就会出现这种情况。
当我将 RS-232 直接连接到 XBee 时,传输会立即发送。
【问题讨论】:
标签: java serial-port xbee jssc