This discussion is archived
6 Replies Latest reply: May 10, 2011 7:11 AM by 860088 RSS

Problem with displaying data

860088 Newbie
Currently Being Moderated
Hello!

I am working on an application that is used to read serial port data and parse it.

The following problem arise:

When i print the data using
System.out.println("10.05.1108:12:19  1    11     00:00:02080012345                            2                                    ");
the program outputs the data in the correct way.
10.05.1108:12:19  1    11     00:00:02080012345                            2                                    
but when i add the data to the GUI
gui.addText("10.05.1108:12:19  1    11     00:00:02080012345                            2                                    ");
the program outputs:
:10:.05:.110:8:::1:2::1:9  1    11     00:0:0::02:0:8:0:0:1:2:345                :  : : : : : : : :   2               : : : : : : :  : :            
Any idea on solving this problem?

Thanks in advance!

Best Regards,
Dean
  • 1. Re: Problem with displaying data
    793415 Pro
    Currently Being Moderated
    dkocevski wrote:
    ..Any idea on solving this problem?
    I'm pretty sure I could code an example that says 'it works for me', but then, I would be making many assumptions about your code, and I don't like guessing. For better help sooner, post an SSCCE.
  • 2. Re: Problem with displaying data
    860088 Newbie
    Currently Being Moderated
    Here is the app code...

    Serial port reader

    I was asking other questions...
  • 3. Re: Problem with displaying data
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    dkocevski wrote:
    Here is the app code...
    Serial port reader
    Just guessing: CallLogRGUI expects the String given in it's <tt>addText(String text)</tt> method to have some structure and adds the additional colons (:) at positions it thinks they where usefull.

    So please show the implementation of CallLogRGUI .

    bye
    TPD
  • 4. Re: Problem with displaying data
    860088 Newbie
    Currently Being Moderated
    CallLogRGUI.java :
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /*
     * CallLogRGUI.java
     *
     * Created on 5.5.2011, 09:18:
     */
    package calllogr;
    import java.io.*;
    
    /**
     *
     * @author Dean
     */
    public class CallLogRGUI extends javax.swing.JFrame {
    
        /** Creates new form CallLogRGUI */
        public CallLogRGUI() {
            initComponents();
        }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            ScroolPane = new javax.swing.JScrollPane();
            txtOutput = new javax.swing.JTextArea();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("CallLogR - Резерва ДКМ дооел");
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    formWindowClosing(evt);
                }
            });
    
            txtOutput.setColumns(20);
            txtOutput.setRows(5);
            ScroolPane.setViewportView(txtOutput);
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(ScroolPane, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(ScroolPane, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
                    .addContainerGap())
            );
    
            pack();
        }// </editor-fold>                        
    
        private void formWindowClosing(java.awt.event.WindowEvent evt) {                                   
            try{
        // Create file 
        FileWriter fstream = new FileWriter("C:/test/CDR.txt");
            BufferedWriter out = new BufferedWriter(fstream);
        out.write(txtOutput.getText());
        //Close the output stream
        out.close();
        
        }catch (Exception e){//Catch exception if any
          System.err.println("Error: " + e.getMessage());
        }
        }                                  
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
    
                public void run() {
                    new CallLogRGUI().setVisible(true);
                }
            });
        }
        public void addText(String s){
            txtOutput.setText(txtOutput.getText()+":"+s);
        }
        // Variables declaration - do not modify                     
        private javax.swing.JScrollPane ScroolPane;
        private javax.swing.JTextArea txtOutput;
        // End of variables declaration 
                      
    }
  • 5. Re: Problem with displaying data
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    I'd say the problem is
    while (inputStream.available() > 0) {
       int numBytes = inputStream.read(readBuffer);
    }
    where you are not waiting for a line to be completely red.

    I'd sugest to use <tt>readLine()</tt> method of BufferedReader here.

    bye
    TPD
  • 6. Re: Problem with displaying data
    860088 Newbie
    Currently Being Moderated
    I had a problem in parsing the string. Problem solved. Thank you all!

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points