How to plot real time data (read with jSerialComm) from serial port using to Xchart

82 Views Asked by At

I am using com.fazecast.jSerialComm to connect to a serial port and read data from a sensor connected to the port.

The code below is contained in "getSensorData()" and output the data in the console correctly.

                while (true)
                {                        
                    byte[] readBuffer = new byte[200];                    
                    String S = new String(readBuffer, "ASCII"); 
                    System.out.println(S);                      
                }

I need to plot this data in real time, and to do so I am using XChart.

I use the code below to update che chart:

      public void updateData() {

         // Get some new data
         List<Double> newData = getSensorData();

         yData.addAll(newData);

         // Limit the total number of points
         while (yData.size() > 20) {
         yData.remove(0);
      }

How can I format the output of the first snippet "getSensorData()" in a List so that can be read and plotted by XChart ? Can anyone point me in the right direction, please ?

Thanks Alb

0

There are 0 best solutions below