Results 1 to 2 of 2
  1. #1
    the_dude is offline Member
    Join Date
    Jan 2015
    Posts
    21
    Rep Power
    0

    Default StringProperty not holding correct data

    This first number of the output is meant to be a timestamp for the data (formatted to show only minutes). The second part of data, after the ':', is the data being read from the serialport. This number is not correct, and is changed within this bit of code. The data is read as "Solar: A.AA", where A.AA is a number read from a sensor. I am able to read the data fine right before this if statement, but after that the data output changes. I'm not sure why. StringProperty is not printing out the correct data:

    Java Code:
    serialPort.addEventListener(event -> {
                    if(event.isRXCHAR()) {
                        try {
                            sb = new StringBuilder();
                            sb.append(serialPort.readString(event.getEventValue()));
                            String str = sb.toString();
                            if(str.endsWith("\r\n")) {
                                //timestamp
                                sb = new StringBuilder();
                                line.setValue(sb.append(df.format(time) + ":").append(str.substring(0,str.indexOf("\r\n"))).toString());
                                System.out.println(line);                       
                            }
                        } catch (SerialPortException ex) {
                            Logger.getLogger(SerialComm.class.getName()).log(Level.SEVERE, null, ex);                    }
                    }
    output:
    StringProperty [value: 40:]
    StringProperty [value: 40:36]
    StringProperty [value: 40:]
    StringProperty [value: 40:3]
    StringProperty [value: 40:]
    StringProperty [value: 40:45]

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: StringProperty not holding correct data

    What is the purpose of those StringBuilders?
    They look unnecessary at first glance.

    So, you read a String from that port.
    Log the value of that String.
    Then log the value of
    Java Code:
    df.format(time) + ":" + str.substring(0,str.indexOf("\r\n"));
    Your code is not going to be making stuff up.
    It's doing exactly what you've asked it to.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Holding mouse
    By d2r123 in forum New To Java
    Replies: 10
    Last Post: 03-13-2012, 09:55 PM
  2. Replies: 0
    Last Post: 07-29-2011, 05:09 PM
  3. Replies: 22
    Last Post: 05-01-2010, 10:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •