最近做到一个东西,采用Java串口通信,读取到一串十进制的数据 如下:36.536.236.436.1,实际我想要其显示的是
36.5 36.2 36.4 36.1,然后再对这四个数值进行平均取值处理显示,由于初学JAVA,所以希望能得到论坛朋友的帮助,我的相关程序如下,不知道该怎么改。我的QQ是330598852
byte[] readBuffer = new byte[20];
int numBytes=0;
String readStr="";
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {
}
try {
while (inputStream.available() > 0) {
numBytes = inputStream.read(readBuffer);
} //while end
str = new String(readBuffer);
for(int iii=0;iii<numBytes;iii++){
readStr=readStr + Byte.toString(readBuffer[iii]);
}
recText.append(str + "\n");
recText.append(readStr+"\n");
recText.append(readBuffer+"\n");
} catch (IOException e) {
}
}