前段时间做了一个串口通信的系统,当时测试的时候是232直接对接的,通信时没异常。
但后来经常要出去演示所以得带笔记本,但笔记本上没有232接口。所以我去市面上买了一根USB转串口的线回来,安装了驱动程序以后链接串口,打开串口的时候发现发送到命令返回值会丢失,接收到返回的数据残缺不完整。不知道是为什么。请问哪位高手是否也遇见过这种问题???
但后来经常要出去演示所以得带笔记本,但笔记本上没有232接口。所以我去市面上买了一根USB转串口的线回来,安装了驱动程序以后链接串口,打开串口的时候发现发送到命令返回值会丢失,接收到返回的数据残缺不完整。不知道是为什么。请问哪位高手是否也遇见过这种问题???
int result = -1;
int[] TagIdentify = new int[] {0xAA, 0xFF, 0x02, 0x80, 0x00};
TagIdentify[TagIdentify.length -
1] = Check(TagIdentify, (TagIdentify.length - 1));
for (int i = 0; i < TagIdentify.length; i++) {
try {
outputStream.write(TagIdentify[i]);
} catch (IOException ex1) {
ex1.printStackTrace();
return result = 1;
}
}
//************************************************
int countt = 0;
while (countt == 0) {
try {
countt = inputStream.available();
} catch (IOException ex) {
}
}
//************************************************
byte[] TagIdentify2 = new byte[countt];
try {
inputStream.read(TagIdentify2);
this.ISO = TagIdentify2;
} catch (IOException ex1) {
ex1.printStackTrace();
return result = 1;
}
return result = 0;
}我知道什么原因了,就因为我加了
int countt = 0;
while (countt == 0) {
try {
countt = inputStream.available();
} catch (IOException ex) {
}
}
加了这个就会在用USB转串口的线的时候出问题。
如果 byte[] TagIdentify2 = new byte[6]; 直接这样的话不会有问题!请问谁知道怎么解决?我觉得加了countt = inputStream.available();
程序运行速度明显的加快了很多~~~~