2
我想通过串口使用java中的RxTx检测设备,并且设备已编程,如果它从计算机接收到特定单词,它将回复“ok”,如果计算机收到确定..它将停止发送该单词并突出显示设备已连接。请帮帮我。还有一件事..我必须检查每个端口..请你会编码一种方法,自动循环通过端口,直到设备被检测到。 即使处于无限循环,我的代码也只发送一次该字。 代码:谷歌搜索的我想在java中使用RxTx通过串行端口检测设备
private void cb1KeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
try{
l1.setText("Port: "+cb1.getSelectedItem().toString()+" is Selected");
selectedPort = cb1.getSelectedItem().toString();// TODO add your handling code here
rs.connect(selectedPort);
for(;;)
{
CommPortSender.send(new ProtocolImpl().getMessage("KITM"));//send message
if(pi.rmess().equalsIgnoreCase("OK"))//received message
{
l1.setText("The Device is attached to: "+selectedPort);
CommPortSender.send(new ProtocolImpl().getMessage("OK ACK"));//send message
break;
}
else
{
rs.disconnect(selectedPort);
continue;
}
}
}
catch(Exception e){}
}
ghostbust555>嘿感谢哥们为你付出的努力..但是这不是我a了...这是任何人都可以做的最简单的事情..请你再回顾我的问题:) – Manu 2012-07-30 06:22:04