kumi wrote:hi, i have a variable with the value of the ultrasonicsensor
now i want the nxt to send this variable to my pc, so i can work with this value
or is there any chance to live stream the value of the sensor @ my pc?
Yes, and you can use either bluetooth or usb to do it.
I always use streams to move data between NXT and PC, (or almost anywhere else).
I recommend DataInputStream and DataOutpuStream so you can read and write any data type you need.
On the NXT, you need a Connection object to open the streams. They come in 2 flavors: Bluetooth and USB and are in the package lejos.nxt.comm.
To learn how to use them, study and try out the sample code : BTRecieve and USBRecieve.
On the PC side, you will need a NXTComm object to open the streams for you. Study and try out .BTSend and USBSend to see how this is done.
A class that can deal with either Bluetooth or USB is the Connect class. - source code in lejos_nxj\src\java\pctools\lejos\pc\tools. To link it into your PC code, the class file is in lejos_nxj\lib\pctools.jar. This class will to all the grubby detail work of finding the NXT, establishing a connection to it, and then opening the streams.
Notice that in the sample code, the NXT runs first and waits for a connection. Then the PC code initiates the connection. This is the best order of events because initiating a Bluetooth connection from the NXT is not so simple.
A couple of things to remember when using streams:
(1) methods like readInt() will block until data is available.
(2) On the output side, you must flush() the output stream to be sure data is actually sent.
I hope this helps.