package comm_counter; import gnu.io.CommPort; import gnu.io.CommPortIdentifier; import gnu.io.SerialPort;import java.io.DataInputStream; import java.io.FileDescriptor; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.ByteArrayInputStream; public class SerialReader_counter implements Runnable { InputStream in; BufferedReader br; params params; public SerialReader_counter(InputStream in, params params) { this.in = in; this.params = params; } // table to convert a nibble to a hex char. static char[] hexChar = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f'}; public void dumpHexFromStream(InputStream in, PrintWriter out) throws IOException { //int length = 4096; int length = 16; byte[] buf = new byte[length]; int bytesRead = 0; int count = 0; char s1,s2; String s3; while(true){ while((bytesRead = in.read(buf)) > 0) { for(int i = 0; i < bytesRead; i++) { s1= (hexChar[(buf[i] & 0xf0) >> 4]); s2= (hexChar[(buf[i] & 0x0f)]); s3=(s1+" "+s2); System.out.print(s3); // params.commHandler2.putFromCounter(s3); count++; if(count % 16 == 0){ out.println(); } else out.print(' '); out.flush(); } } } } public void run() { try { PrintWriter out = new PrintWriter(System.out); dumpHexFromStream(this.in, out); out.flush(); } catch(Exception e){} try{ Thread.sleep(1000); } catch(Exception e){ } } //public static void main(String[] pArgs) throws Exception { // ByteArrayInputStream in = new ByteArrayInputStream("Test! This is only a test!".getBytes()); // SerialReader_counter src = new SerialReader_counter(in,null); // src.run(); //} }