We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Serial concurrent thread (Read 1222 times)
Serial concurrent thread
Dec 4th, 2009, 5:22am
 
Hi

I want to have a thread handling the communication with the serial port and then my main program can read the last received data from this thread instead of stopping to read new data all the time.

I am making a small game on my computer that I want to control with Arduino and an accelerometer. The communication is over the serial port. If I have to stop all the time to read the serial port with new movements I guess the game would become really slow. Is there some good tutorials on processing and threads?
Re: Serial concurrent thread
Reply #1 - Dec 5th, 2009, 1:50pm
 
I have a similar issue. I have a interactive game being controlled by devices over the serial port. I am running a counter using the main draw() loop and setting variables in singleton classes using the input from the hardware devices over serial. The problem is that when I am sending or receiving data over serial you notice the counter stop while the data is being transferred. I have tried various methods of implementing threads to handle the I/O but am having no luck... is I/O excluded from multi threading?

I have an example I am trying to get working withing the context of my game... maybe someone can point out an error or offer some advice.

*** This is the test class I am calling that does output to the console

public class TestThread implements Runnable{

     public void run() {
           // TODO Auto-generated method stub
     }
     public TestThread(int num){
           for(int i = 0; i< num ; i++){
                 System.out.println("INSIDE THREAD" + i);
           }
     }
}//end class

*** I am calling it by doing the following once from my main draw() loop. The main draw loop freezes while the "thread" finishes its output to the console.

  Runnable runnable = new TestThread(10000000);
  Thread thread = new Thread(runnable);
  thread.start();

Any help would be greatly appreciated.
Page Index Toggle Pages: 1