From: Skuld <tan...@ho...> - 2009-04-20 12:56:33
|
^^ Sure I can. As I told you in my first reply, you have to call the Read method to fill up your structure's fields, from a communication pipe with Player. That is the code of the JavaClient (2.0.1 version, but all versions should work the same.) public void runThreaded (long millis, int nanos) { if (isThreaded) { System.err.println ("[PlayerClient]: A second call for runThreaded, ignoring!"); return; } this.millis = millis; this.nanos = nanos; isThreaded = true; this.start (); } As you can see, when you call RunThreaded, you just set some special fields before launching the start method. I guess you know how works Threads in java, so I'll just show you the run method (which is called by the start method): public void run () { try { while (isThreaded) { if (this.datamode == PLAYER_DATAMODE_PULL) { this.requestData (); while (read () != PLAYER_MSGTYPE_SYNCH && isThreaded); } else // while (is.available () != 0) // while (read () != PLAYER_MSGTYPE_SYNCH && isThreaded); read (); if (millis < 0) Thread.yield (); else if (nanos <= 0) Thread.sleep (millis); else Thread.sleep (millis, nanos); } } catch (InterruptedException e) { throw new PlayerException (e); } // } catch (IOException e) { throw new PlayerException (e); } } Do you understand? This function have a while's loop. This loop first wait for data from Player, and dispatch it in the structures's fields with a read() 's loop. There is the call of the Read function. (an equivalent to be meticulous, because Read function is available in C library, but in Java, read is a private function. You just can call it by readAll(), which does the same things that the C one does, and the simple read does too -but with verifications.) So, in fact when you call RunThreaded, one Thread is specially created to catch information from Player and dispatch it into structures, for the other Thread (because threads share memory.), so for your code, so you doesn't have to call Read() anymore. And you still have informations from Player. Here it is ! I hope I was clear enough ^^ If I wasn't, tell me so. Have a nice day! Skuld kevinl wrote: > > Hi Skuld, > Thank you for your advice, I call runThreaded(-1,-1) before my code and I > can get the data now. And I'm sorry to reply your message so late. And I > am confused why the fuction of runThreaded(-1,-1) will call an equivalent > of Read. Could you tell me why? > > Thanks a lot, > kevin > > -- View this message in context: http://www.nabble.com/Problems-with-laserinterface-tp22986701p23136166.html Sent from the java-player-users mailing list archive at Nabble.com. |