priyapratheep 0 Newbie Poster

I am doing one program which read serial port data (for bar code reader) using java application.

y program is working well and reading serial data but it is not displaying special characters.When i read through hyperterminal i can see all special characters but when see data throught the output of java program these special characters are missing...

I don't know i am doing something wrong in stream or ???

My code is

public void serialEvent(SerialPortEvent event) {
        System.out.println("before serialEvent");
        StringBuffer readBuffer1 = new StringBuffer();

        switch (event.getEventType()) {

        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
            System.out.println("Data empty:");
            break;
        case SerialPortEvent.DATA_AVAILABLE:
               byte[] readBuffer = new byte[100];
               int r = 0;
               try {
                   System.out.print("test");  

                  //t inputStream = serialPort.getInputStream();

                  while((r = inputStream.read(readBuffer)) != -1) {
                     System.out.print(new String(readBuffer, 0, r));
             }
               } catch (Exception e) {
                  e.printStackTrace(System.out);
               }
        }
    }
}

Please help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.