这里是基于modbus协议一个读取电表数据的RTU程序,发送请求后很就才响应,已经远远超过了TIMEOUT的时间了,而且返回的数据是错误的,求高手指教下CommPortIdentifier c=CommPortIdentifier.getPortIdentifier("COM1");
SerialPort s=(SerialPort)c.open("Mycom", 5000);
s.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
s.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
DataInputStream in;
DataOutputStream out;
in=new DataInputStream(new BufferedInputStream(s.getInputStream()));
out=new DataOutputStream(new BufferedOutputStream(s.getOutputStream()));
out.flush();
in.skip(in.available());
out.write(new byte[]{8, 3, 1, 48, 0, 3}, 0, 6);
out.flush();
for(int i=0;i<15;i++){
System.out.println(in.readUnsignedShort());
}