LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

NXT Bluetooth connection C# <-> LabVIEW

Hello,
I'm writing an application, and part of it requieres to send data to NXT via Bluetooth. On NXT I'm using LabVIEW, on the computer - C#/.NET.

It connects normally to the NXT, but when I try to read something from Mailbox from LabVIEW using NXT toolkit, it returns "0".

Where can be a problem? Or maybe there are other ways to make to connect NXT and .NET code?

 

  byte[] NxtMessage = { 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00 };
            NxtMessage[2] = (byte)(this.numericUpDownMailBoxNbr.Value - 1);
            int tmp = (int)this.numericUpDownInt.Value;
            for (int ByteCtr = 0; ByteCtr <= 3; ByteCtr++)
            {
                NxtMessage[4+ByteCtr] = (byte) tmp;
                tmp>>=8;
            }
            NXTSendCommand(NxtMessage);

 

private void NXTSendCommand(byte[] Command)
        {

            Byte[] MessageLength= {0x00, 0x00};
           
            MessageLength[0]=(byte)Command.Length;

            BluetoothConnection.Write(MessageLength, 0, MessageLength.Length);
            BluetoothConnection.Write(Command, 0, Command.Length);
           ...
            }

 

0 Kudos
Message 1 of 5
(3,066 Views)

Hello,

 

Have you normally been able to communicate with the NXT controller using your C# program? Have you been able to use functions that do not interact with the NXT Mailbox? Are you running a LabVIEW VI on the NXT controller with which you are trying to interface?

 

Looking at the LabVIEW NXT Module Programming Guide (http://www.ni.com/pdf/manuals/372574c.pdf), it appears that there are specific functions for writing and reading messages- NXTMessageWrite, NXTMessageRead.  What API or library are you using in your C# code?

 

The NXT controller has ten different mailboxes, which one are you attempting to access?

Cameron
0 Kudos
Message 2 of 5
(3,016 Views)

Hello Cameron,

I can normally communicate with NXT. I ran a code to play a sound, and it worked exactly as it should.

 byte[] NxtMessage = { 6, 11, 0, 3, 11, 2, 244, 1 };
 BluetoothConnection.Write(NxtMessage, 0, NxtMessage.Length);

 

shot_131126_001955.pngOn NXT I'm running this block to read data from 5th mailbox.

 

When I try to write something like this

byte[] MyMessage = {5, 0, 9, 4, 2, 1, 0};

 it writes me zero instead of 1 to the mailbox. Same problem if I try to send Int.

 

The other thing, if I for example send some string to mailbox via LabVIEW, on NXT, it returns me what I've sent with blank line before it.

shot_131126_003713.png

Thanks for help in advance.

Vadim

0 Kudos
Message 3 of 5
(3,004 Views)

Hello Vadim,

 

Thank you for the additional information about your particular situation. I am glad to hear that you are able to use the NXT Mailbox successfully when using LabVIEW on the controller and on your development PC. What version of LabVIEW are you using?

 

I would like to help you with your C# programming, but I am not sure what API you are using to communicate with the NXT controller. Could you please comment on the C# libraries and functions you are using?

 

Regards,

 

Cameron
0 Kudos
Message 4 of 5
(2,968 Views)

Hello Cameron,

Thanks for your reply. I am using LabVIEW 2012 for NXT.

If I try to communicate via Bluetooth I use system.io.ports.serialport. If I send data to NXT I use the protocol, I've found on their Web Site: It looks like this:

  • 1,2 byte: length
  • 3: 9
  • 4: mailbox number - 1
  • 5: length of the command
  • 6: byte to write (0 || 1)
  • 7: 0 terminator


For the command above I send {1,0,9,0 (for first mailbox), 2,1,0}. I send it with a command BluetoothConnection.Write (byte_array, 0, byte_array.Length). And Instead of 1, it writes 0 to mailbox. If I try to send some int using the same protocol, it changes nothing.

 

Thanks,

Vadim

0 Kudos
Message 5 of 5
(2,958 Views)