-1

I'll start of with a brief description: I'm building a system to monitor the temperatures in a chemical reactor as a school project. We measure with an arduino that sends the data as a string to a pc. On the pc we have a Java code to read out that string, parse it, and show it in a gui.

The problem we're facing is the following: We have a

  • Class that reads the input string and prints it to the console
  • Class that takes a dummy string of the correct format, parses it, and shows it in the GUI

The problem is that we're looking for a way to pass the data from the reader to the parser without interrupting the loop, and to make it threadsafe so we don't lose data. Is there an efficient way to do this?

Wouter
  • 149
  • 1
  • 3
  • 12

1 Answers1

0

You need to separate the functions into separate classes and arrange for inter-object communications via Queues.

Refactor your code into:

  • Class that reads the input string and posts it into a queue.
  • Class that reads the input string queue and posts each string into a console queue and a GUI queue.
  • Class that consumes the console queue writing everything to the console.
  • Class that consumes the GUI queue, parses the string and updates the gui.

There are other architectures (such as publish/subscribe using listeners) but this should work for you.

OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213
  • the console was just for testing, so i won't need it, but the rest of your post was very helpfull, thanks – Wouter Mar 06 '15 at 13:12