我正在开发一个项目,该项目使用RXTX和protobuf与开发板上的应用程序进行通信,并且我遇到了一些问题,这意味着我可能会以错误的方式进行操作。这是我目前有书面请求董事会(读取的代码是相似的):如何使用Google protobuf通过串口进行通信?
public void write(CableCommandRequest request, OutputStream out) {
CodedOutputStream outStream = CodedOutputStream.newInstance(out);
request.writeTo(outStreatm);
outStream.flush();
}
下面是用来准备这又suplies被使用的OutputStream
的RXTX串行连接的设置write
命令:
// The baud rate to use when connecting to the development board
private final static int BAUD_RATE = 115200;
// The timeout to use for the serial port
private final static int CONNECTION_TIMEOUT = 50;
// The serial break for the development board, 100
private final static int SERIAL_BREAK = 100;
// <SNIP> ...
SerialPort serialPort = (SerialPort)port.open(appName, CONNECTION_TIMEOUT);
serialPort.setSerialPortParams(BAUD_RATE,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
serialPort.sendBreak(SERIAL_BREAK);
所使用的OutputStream
由RXTX制备和开发板似乎表明正在接收的数据,但它是越来越乱码或以其它方式不被理解。
到目前为止,所有常见的嫌疑人(例如串行连接未建立,通信问题等)已被消除,因此看起来问题在于如何调用writeTo
,因为串行连接上的通信是成功的。
似乎很少有关于通过串行连接使用protobuf的文档,所以我假设通过OutputStream
应该足够了。这实际上是正确的,还是这是通过串行连接发送响应的错误方式?
您的硬件是否真的了解protobuf的独特格式? – bmargulies