import java.io.*;import java.util.*;import javax.comm.*;public classIP1725_reg_read {
CommPortIdentifier portId;
SerialPort serialPort;
OutputStream outputStream;
InputStream inputStream;public voidopen_port(String port) {try{
portId=CommPortIdentifier.getPortIdentifier(port);
serialPort= (SerialPort) portId.open("IP1725_reg_readApp", 2000);
outputStream=serialPort.getOutputStream();
inputStream=serialPort.getInputStream();
serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
}catch (NoSuchPortException | PortInUseException |IOException|UnsupportedCommOperationException e) {
e.printStackTrace();
}
}public voiddo_get_reg() {
open_port("COM15");
FileWriter fw= null;
String s;byte[] readBuffer = new byte[4];byte[] buf = new byte[2];inti;try{
fw= new FileWriter("ip1725reg.txt");
}catch(IOException e) {
e.printStackTrace();
}for (i = 0; i < 256; i++) {try{
buf[0] = (byte) 0xdd;
buf[1] = (byte) i;
outputStream.write(buf,0, 2);
outputStream.flush();
s= String.format("%02x:", buf[1]);
System.out.print(s);
fw.write(s);
}catch(IOException e) {
System.out.println("." +e);
}try{
Thread.sleep(10);
}catch(InterruptedException e) {
}try{
inputStream.read(readBuffer);
s= String.format("%02x", readBuffer[0])+ String.format("%02x", readBuffer[1]) + "\r\n";
System.out.print(s);
fw.write(s);
}catch(IOException e) {
System.out.print(".");
}
}try{
fw.close();
}catch(IOException e) {
e.printStackTrace();
}
}public static voidmain(String[] args) {newIP1725_reg_read().do_get_reg();
}
}