Bluetooth connection NXJ - PC

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

Moderators: 99jonathan, roger, imaqine

Bluetooth connection NXJ - PC

Postby zatteschacht » Tue Dec 06, 2011 6:05 pm

Hi everyone,

I want to let the NXT brick connect to my PC using Bluetooth and send over a java.lang.String object.
Is there any example code available online using bluetooth with Lejos NXJ?


Grtz
zatteschacht
New User
 
Posts: 6
Joined: Tue Nov 29, 2011 11:13 am

Re: Bluetooth connection NXJ - PC

Postby guntram » Tue Dec 06, 2011 7:44 pm

Check out the samples folder.
For me, it is in the %user%/leJOSNXJProjects. I think in the sourcecode there are also sample folders...
guntram
New User
 
Posts: 11
Joined: Fri Dec 02, 2011 3:10 pm
Location: Cologne University of Applied Sciences, Germany

Re: Bluetooth connection NXJ - PC

Postby skoehler » Tue Dec 06, 2011 7:47 pm

"samples" is the folder for samples that run on the NXT
"pcsamples" is the folder for samples that run on the PC
skoehler
leJOS Team Member
 
Posts: 1458
Joined: Thu Oct 30, 2008 4:54 pm

Re: Bluetooth connection NXJ - PC

Postby gloomyandy » Tue Dec 06, 2011 11:43 pm

Hi,
There is no sample code to listen for a connection on the PC nor is there any support in the PC comms code for this. The reason is that it is very tricky to do. The nxt will only open a connection to the first Bluetooth endpoint offering the correct service type. The problem is that on many systems especially windows PCs this'll first end point is already in use, typically as Bluetooth serial port... so to be able to connect from the nxt to a windows PC you must ensure that all such listening services are disabled before your PC program starts to listen. It is not always possible to do this. It is much easier to open a connection from the PC to the nxt and unless you really need to do things the other way and are very sure you know what you are doing I would not attempt to open connections from the nxt to the PC...

Good luck...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4240
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Bluetooth connection NXJ - PC

Postby guntram » Wed Dec 07, 2011 2:01 pm

@zatteschacht
Oh! Now i realize that you want to connect from the NXT to the pc and not the other way round...
That is quite exactly the problem i am trying to deal with. I already put a similar question into this post where i ask how i could connect from the NXT to a droid phone.

As the NXTs dont even succeed in pairing a phone or a pc, but are able to pair each other, this seems to be a problem on the pc/phone side...

So my problem is that we would like to distribute the bluetooth traffic evenly on two sockets. The one thing is that i cannot establish a second socket from the phone to the NXT. The other thing is that a connection from the NXT to the phone (or the pc) is not possible.
gloomyandy wrote:The problem is that on many systems especially windows PCs this'll first end point is already in use, typically as Bluetooth serial port...
So what exactly is this that is blocking the connection? An SPP daemon running in the background?
Do you have a hint on this, Andy?

This would be the easier way than to construct an implementation which manages a package identification model like in TCP for example (to avoid messages being mixed up).

As for now, i wanted to check out where the open port is assigned for the incoming bluetooth connection on the NXT side.
The idea was that the problem might be that the NXT is restricted to only one incoming port. Is this true and is there a hint where to get control of that?

I did not find the handling of "cmdInit(MSG_OPEN_PORT..." in the lejos.nxt.comm.Bluetooth.java class...
Is this the wrong way to think of getting control of the port assignment? Or might this lead to a solution?
guntram
New User
 
Posts: 11
Joined: Fri Dec 02, 2011 3:10 pm
Location: Cologne University of Applied Sciences, Germany

Re: Bluetooth connection NXJ - PC

Postby gloomyandy » Wed Dec 07, 2011 2:35 pm

seriously don't use two connections unless you really, really have to... The overhead on the NXt of switching between connections is huge and very complex. You would be much better off multiplexing the data on a single connection....

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4240
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Bluetooth connection NXJ - PC

Postby guntram » Wed Dec 07, 2011 3:02 pm

Andy, thanks for your advice!

I think we should rearrange our bluetooth information exchange management.

So, first of all...draw some sketches :)
guntram
New User
 
Posts: 11
Joined: Fri Dec 02, 2011 3:10 pm
Location: Cologne University of Applied Sciences, Germany

Re: Bluetooth connection NXJ - PC

Postby zatteschacht » Thu Dec 08, 2011 5:16 pm

It doesn't really matter who connects to who. I just want an stream from nxt to PC. Can someone link me to the samples folder? Can't find it..
zatteschacht
New User
 
Posts: 6
Joined: Tue Nov 29, 2011 11:13 am

Re: Bluetooth connection NXJ - PC

Postby zatteschacht » Thu Dec 08, 2011 5:28 pm

K, I've found the samples. But there is only an example of an NXT connecting to another NXT. Is there any example of a NXT and a PC communicating?
zatteschacht
New User
 
Posts: 6
Joined: Tue Nov 29, 2011 11:13 am

Re: Bluetooth connection NXJ - PC

Postby gloomyandy » Thu Dec 08, 2011 8:26 pm

The samples for the PC connecting to an NXT are in the pcsamples folder, it will have been installed on your PC as part of the standard leJOS install...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4240
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Bluetooth connection NXJ - PC

Postby aleXander » Wed Dec 14, 2011 5:49 pm

Yay, bluetooth connection topic!

I would like to know if the following is possible:
I have to simulate a production line. Meaning that I have to open a bluetooth connection between laptop-NXT and run an infinite loop. Each time the NXT receives a command (set of 2 integers) it would start producing. When it finishes the production it will stop and wait for another command (that's why I need the infinite loop). When a new command is sent from the laptop it will start producing again and so on. Is that possible?

What if I receive a command, start producing and then the computer sends another command before the NXT finishes producing the first command? Can I save the 2nd command somewhere so that the NXT will start producing it right after it finishes producing the 1st command?

Please answer someone, I have one more day to finish this. Tell me if it's not clear what I want to do.
aleXander
New User
 
Posts: 4
Joined: Wed Dec 07, 2011 6:50 pm

Re: Bluetooth connection NXJ - PC

Postby guntram » Thu Dec 15, 2011 2:45 pm

if the bot is still working while receiving a new command, it has to cache the incoming commands somewhere. e.g. there is a receiver thread on the bot running an infinite loop, and when it receives a command it saves it into some kind of list. then there is also a listener thread that checks out if there is a new command in the list and initiates the execution if the bot is not executing any command yet - and otherwise, if the bot is busy, it blocks the command and the list keeps waiting for the bot to be ready to execute a new command.

so you have a bt-receiver thread and a command dispatcher thread...
guntram
New User
 
Posts: 11
Joined: Fri Dec 02, 2011 3:10 pm
Location: Cologne University of Applied Sciences, Germany


Return to NXJ Software

Who is online

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

more stuff