Hi,
i'm trying t create a java application that send a message from my computer to the NXT brick. I'm using the bluecove library and writing in nxc the NXT program to read this message. There's no problem sending messages from the brick to the computer, but i can't read anything in the brick. I'm not sure why. Any help?
Thanks!!
[nxc] bluetooth java app to nxt
Re: [nxc] bluetooth java app to nxt
I can help but I need a lot more information. What is the NXC code that you are currently using? What do you mean by "I can't read anything in the brick"? When you send messages from the PC to the brick are you strictly following the published specifications for the direct command protocol over bluetooth? What sort of message are you sending to the brick? If it is the MessageWrite direct command then what is the mailbox number you are using? Is your message null terminated?
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: [nxc] bluetooth java app to nxt
Ok, thanks for all.
i think the problem is i'm not using the protocol in the right way. I'm not sure what i have to send to the NXT.
I'm using this NXC code to receive messages:
i've tried to use diferent mailbox, 1, 0x01, also use this function insede a for to read all the mailboxes.
In the Java side the code is simple i use an outputStrem and write directly the byte sequence. This is the last sequence I tried:
0x80, 0x09, 0x01, 0x05, 0xEA, 0x01, 0x00
Any advice?
i think the problem is i'm not using the protocol in the right way. I'm not sure what i have to send to the NXT.
I'm using this NXC code to receive messages:
Code: Select all
string BTReceiveMessage(byte connection, byte mailbox, byte flush){ //receive a BT message
string msg;
BTWait(connection);
int a= ReceiveMessage(mailbox,flush,msg);
NumOut( 0 , LCD_LINE4, a);
BTWait(connection);
return msg;
}
In the Java side the code is simple i use an outputStrem and write directly the byte sequence. This is the last sequence I tried:
0x80, 0x09, 0x01, 0x05, 0xEA, 0x01, 0x00
Any advice?
Re: [nxc] bluetooth java app to nxt
So with Bluetooth you need 2 bytes at the start that are the full size of the message. This is documented in the LEGO BT SDK. Please read that. Mailbox 1 is actually number 0 so make sure you are reading/writing the same mailbox. If you use MAILBOX1 in your NXC code then you need to write to mailbox 0 in your Java code. Then if you say that you are writing 5 bytes you really need to write 5 more bytes in your message (i.e., 2 more than you have in your example). The docs say the length bytes are lsb/msb so it would be 0x09, 0x00 followed by MessageWrite direct command bytes.In the Java side the code is simple i use an outputStrem and write directly the byte sequence. This is the last sequence I tried:
0x80, 0x09, 0x01, 0x05, 0xEA, 0x01, 0x00
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: [nxc] bluetooth java app to nxt
Ok I see. I read how the protocol works and with some example I found on the net I make it works The java application send a message and the NXT print it on the screen.
But something strange happens. The first message received with the instruction ReceiveMessage is empty. However, with the strLen instruction it seems to have 64 characters. It's not a big issue but i would like to know why it's happening. I'm still testing and improving the code. Any idea is welcome.
And thanks for all!!
But something strange happens. The first message received with the instruction ReceiveMessage is empty. However, with the strLen instruction it seems to have 64 characters. It's not a big issue but i would like to know why it's happening. I'm still testing and improving the code. Any idea is welcome.
And thanks for all!!
Re: [nxc] bluetooth java app to nxt
From c_cmd.h:
And in c_cmd.c where it handles the MessageWrite direct command:
If you were checking the response for the direct command you would see
returned for the status.
So the maximum strlen value is 58 since 59 includes the null at the end and strlen does not count the null in the string length.
John Hansen
Code: Select all
//MAX_MESSAGE_SIZE including null-terminator
//!!! Capped at 59 unless USB protocol assumptions are changed!
//
#define MAX_MESSAGE_SIZE 59
Code: Select all
//If Count is illegal or MsgData is not null-terminated,
// we can't accept it as a valid string
if (Count == 0 || Count > MAX_MESSAGE_SIZE || pData[Count - 1] != 0x00)
{
RCStatus = ERR_RC_ILLEGAL_VAL;
break;
}
Code: Select all
#define ERR_RC_ILLEGAL_VAL -64 //0xC0 Data contains out-of-range values
So the maximum strlen value is 58 since 59 includes the null at the end and strlen does not count the null in the string length.
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: [nxc] bluetooth java app to nxt
Yes, i thougth it has to be something like that, i will ensure the length is not out of range and try it again.
Thanks for all, you are a true Master!!
Thanks for all, you are a true Master!!
Who is online
Users browsing this forum: No registered users and 2 guests