NXT sends data via bluetooth to pc?

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

NXT sends data via bluetooth to pc?

Postby kumi » Thu Jan 10, 2008 7:49 am

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?

thanks
regards kumi
kumi
New User
 
Posts: 2
Joined: Thu Jan 10, 2008 7:36 am

Re: NXT sends data via bluetooth to pc?

Postby roger » Thu Jan 10, 2008 9:09 pm

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?

thanks
regards kumi

Hi Kumi,
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.
Roger
roger
Moderator
 
Posts: 350
Joined: Fri Jun 01, 2007 4:31 am
Location: Berkeley, CA


Return to NXJ Software

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 2 guests

cron
more stuff