LabVIEW for LEGO MINDSTORMS and LabVIEW for Education

cancel
Showing results for 
Search instead for 
Did you mean: 

Fantom SDK


@Kjeld Petersen/SDU/DK wrote:

Hi Bill

Now it works. I had a look into the help documentation, and look what I found.

...

When you send a direct command, you should not key in the first 0x00 as it is described in the "Direct commands" manual.

Regards Kjeld





Hi Kjeld,

That's awesome! I glad you got it to work!

For some reason, I'm getting a VISA error when I call the sendDirectCommand.vi

"VISA: (Hex 0xBFFF000E) The given session or object reference is invalid."

Things have been very hectic with midterm examinations, so I have not had time to track it down... =[

Did you have any similar problem?

Thanks!

-Bill =]
0 Kudos
Message 11 of 28
(6,610 Views)
Bill -

It sounds like you're not making calls into Fantom in the right order, or are not chaining things together correctly.  Which interface to Fantom are you using, the LabVIEW interface or the C/C++ interface?  Could you post some short example code that is giving you the error?
------
James Blair
NI R&D
0 Kudos
Message 12 of 28
(6,591 Views)

Hi James,

Thanks for offering to look at the code.  I have gone back to square one and dropped the BlueTooth functionality for now.  I am trying to follow the main.cpp example, step by step, in LabVIEW 8 using the NXT cabled through the USB.

The attached LabVIEW 8 vi (BTFantomTest-qswitch.vi) performs the following in LabVIEW 8:

1.  Call the createNXTIterator.vi with searchBlueTooth set to False (F).

This vi returns an NXTObject cluster and an error cluster.  I am ASSUMING this vi also performs the second step found in the main.cpp example of creating an NXT object for the first NXT that was found.  The vi runs without error.

2.  Call the destroyNXTIterator.vi with the NXTObject and error cluster returned from createNXTIterator.vi

This vi returns the NXTObject cluster and error cluster.  The vi runs without error.

3.  Call the getFirmwareVirsion.vi with the NXTObject and error cluster returned from destroyNXTIterator.vi.

This vi returns the following error: "VISA:  (Hex 0xBFFF000E) The given session or object reference is invalid."

Any ideas?

Many thanks,

-Bill  =]  

0 Kudos
Message 13 of 28
(6,573 Views)

Hi All,

I hate to answer my own question, but I dropped my assumption that createNXTIterator.vi creates an NXTObject as part of its function.

I added the createNXT.vi to the diagram, before the call to destroyNXTIterator and the LabVIEW 8 code works as described in the main.cpp.

I have attached an updated version of the LabVIEW 8 code.

Thanks! (I'm off to get it working via BlueTooth...)

-Bill  =]

Message Edited by qswitch on 10-16-2006 01:44 PM

0 Kudos
Message 14 of 28
(6,574 Views)

Hi All,

The FantomSDK is working over the BlueTooth interface.

I added the findNXT.vi, pairBluetooth.vi, and isPaired.vi vi's to pair the NXT with the computer.

I then used the createNXT.vi using the VISA Resource string returned by the findNXT.vi INSTEAD of the NXTObject returned from the createNXTIterator used in the previous example.

I have attached example code in BTFantomTest_qswitch3.vi.  The sample code connects to the first NXT found by the findNXT.vi.

Best regards,

-Bill  =]

0 Kudos
Message 15 of 28
(6,564 Views)
Hi Bill:

There are a couple of points I'd like to clarify.  In general, the iterators provided by Fantom will not create the objects they are iterating over unless you call the "get[Object]FromIterator" function.  So, in your case, you could have called:

[ createNXTIterator ] [ getNXTFromIterator ] [ destroyNXTIterator ] [ sendDirectCommand ] [ destroyNXT ]

I think this is what you intended your example code to look like.

Now you're thinking, "But my example code worked just fine.  Why?"  Since you don't pass a VISA resource string to createNXT, that VI is automatically searching for the first NXT it can find that is connected over USB.  It doesn't look at the iterator you created at all.  So, in your example, the calls to createNXTIterator and destroyNXTIterator are extraneous, and things would work just as well if you called:

[ createNXT ] [ sendDirectCommand ] [ destroyNXT ]

Your example code will not work if you unplug the USB cable and try to connect to your NXT over Bluetooth (since createNXT will not search Bluetooth).  But the first example above will work -- just replace createNXT with getNXTFromIterator in your example code, and you should be in business!
------
James Blair
NI R&D
0 Kudos
Message 16 of 28
(6,568 Views)
Hi Bill

This *.vi show how fare I have come with making a LabView Program recieve BlueTooth messages from a NXt unit.

For some reasons the connection doesn't work all the time.

Regards Kjeld
0 Kudos
Message 17 of 28
(6,524 Views)
Hi Kjeld:

Great work on your Bluetooth communication VI!  I can certainly appreciate how much effort went in to figuring out how to get everything to work just right.  I have a couple of suggestions on how to streamline things even more.

First, while it is certainly okay to pair and unpair with the NXT every time you want to communicate with it, that's not really the way Bluetooth was designed to work.  Ideally, you pair with a device once, and then that relationship is permanent.  So if you called your "SendCommand ReadMessage.vi" in a loop, you'd waste lots of time pairing and unpairing with the NXT.  Consider removing the call to unpairBluetooth.vi from the end of your program.

Second, you should carefully examine what happens in the case that the NXT is already paired when your VI is run.  isPaired.vi will return true, and the resource string that you end up passing to createNXT.vi does not contain a communication identifier.  That identifier (on Windows) tells Fantom which virtual serial port to open and without it, Fantom won't be able to communicate with your NXT over Bluetooth.  Instead, consider removing the call to isPaired.vi and calling pairBluetooth.vi regardless of whether the NXT is already paired.  In the case that the NXT isn't paired, it does what you expect: pair with the NXT, then add the communication identifier to the resource string.  In the case that the NXT is already paired, pairBluetooth.vi won't pair again, but it will still fix up your resource string with the proper communication identifier.  This will ensure your VI will work even when the NXT was paired with your computer outside the scope of your program (for example, using the Microsoft Bluetooth Devices dialog).

Once again, it is great to see the progress you and Bill have made.  Keep it up!
------
James Blair
NI R&D
0 Kudos
Message 18 of 28
(6,511 Views)
Hi James B

Can you explain why I do not recieve all the packages from the NXT unit in my program?
The small LEGO Mindstorm NXT program sends a message over BT everytime I push a button.
But for some reasons is my LabView program not recieving all of the packages. It skips over some of them.

I have look into the manual and I'm avare of the limitation of the mailboxes. (max 5)
I can understand the part of LabView not recieving packages that are overwritten by another one.
But if I pause with sending messages, and then just send 1, it is not sure that LabView will get it.

Regard Kjeld
0 Kudos
Message 19 of 28
(6,499 Views)
I have a couple of ideas.

First, the "best practice" when writing for-loops in LabVIEW code is to include a "Wait Until Next ms Multiple" block to introduce a small delay.  You can choose how many milliseconds to wait; I usually pick 100 or 200.  Why is this wait important?  Otherwise, LabVIEW runs that for-loop very tightly and you'll see your processor usage jump to near 100%.  I'm not sure the little NXT can keep up with sending and receiving messages as quickly as LabVIEW and your PC can!

Second, the LEGO Direct Commands document in the BT SDK states that responses to the MESSAGEREAD command will be padded to always be 64 bytes long.  I notice your VI is only expecting to read a response of 30 bytes, which is too short.  Since Fantom will strip off the first byte of the response package (0x02), your buffer should read 63 bytes back.
------
James Blair
NI R&D
0 Kudos
Message 20 of 28
(6,487 Views)