帮助我找出发生异常的原因。我的应用程序在启动时工作正常,但过了一会儿它停止工作,我的代码有什么不对。
ModbusTCPTransaction trans = new ModbusTCPTransaction(con);
Runnable r = new Runnable(){
@Override
public void run() {
while(isRunning){
try {
Thread.sleep(10);
trans.setRequest(req);
trans.execute();
ReadMultipleRegistersResponse res = (ReadMultipleRegistersResponse) trans.getResponse();
tf1.setText(String.valueOf(res.getRegisterValue(0)));
tf2.setText(String.valueOf(res.getRegisterValue(1)));
tf3.setText(String.valueOf(res.getRegisterValue(2)));
} catch (InterruptedException ex) {
Logger.getLogger(Modbusconn.class.getName()).log(Level.SEVERE, null, ex);
} catch (ModbusSlaveException ex) {
Logger.getLogger(Modbusconn.class.getName()).log(Level.SEVERE, null, ex);
} catch (ModbusException ex) {
Logger.getLogger(Modbusconn.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(Modbusconn.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
};
new Thread(r).start();