【发布时间】:2019-02-14 18:50:37
【问题描述】:
我正在研究 RFID 串行端口。在这个我有一个源代码,像这样new SerialPort(new File("/dev/ttyS3"), 19200);它的工作完美我得到了一个输出,但不是很好的编码我尝试了所有的编码,但它不起作用。
我从InputStream 得到一个输出:
mInputStream = mSerialPort.getInputStream();
private byte[] reciveBuffer=new byte[128];;
private int size = 0;
size = mInputStream.read(reciveBuffer);
//i checked all encodings
String message = new String(reciveBuffer,0, size,Charset.forName("iso-8859-1"));
String message2 = new String(reciveBuffer,0, size,Charset.forName("windows-1252"));
assert message2.charAt(1) == '\u00E4';
String message3 = new String(reciveBuffer,0, size,Charset.forName("US-ASCII"));
String encode=((reciveBuffer[0] & 128) == 0) ? "UTF-8" : "windows-1252";
String display = new String(reciveBuffer, 0, size);
但我得到的是字符串:
3������`������`��xf���f���
来自所有编码。
【问题讨论】:
标签: android arduino serial-port inputstream bytearrayoutputstream