private void readComm() {
byte[] readBuffer = new byte[15];
try {
int len = 0;
while ((len = inputStream.read(readBuffer)) != -1) {
test += new String(readBuffer,0, len).trim();
break;
}
StringBuilder sb=new StringBuilder();
for (byte b : readBuffer) {
String a="";
if (b < 0) {
//byte的范围是-128到+127
int i = 128 + (int) b + 127 + 1;
//转换成16进制
a=Integer.toHexString(i);
}else {
a=Integer.toHexString(b);
}
if(a.length()==1){
a="0"+a;
}
sb.append(a);
}
System.out.println("接收的数据:"+sb);
} catch (IOException e) {
e.printStackTrace();
}
}