NXT serial number

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXT serial number

Post by mattallen37 »

I already know that the function requires a byte array, as the buffer.
The array length is defined by the function, and seems to always be 7.
I tried flattening the array into a string, but the string would'n display, so that must not be how to do it.

Code: Select all

byte ID[];
string SID;
task main()
{
  GetBrickDataAddress(ID);
  SID = FlattenVar(ID);
  NumOut(0,LCD_LINE1,ID[0]);
  NumOut(0,LCD_LINE2,ID[1]);
  NumOut(0,LCD_LINE3,ID[2]);
  NumOut(0,LCD_LINE4,ID[3]);
  NumOut(0,LCD_LINE5,ID[4]);
  NumOut(0,LCD_LINE6,ID[5]);
  NumOut(0,LCD_LINE7,ID[6]);
  TextOut(0,LCD_LINE8,SID);
  Wait(100000);
}
Please try the code for yourself to see exactly what it does.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXT serial number

Post by mattallen37 »

To some extent, it appears that the 7 bytes written, contain all 12 "numbers" of the ID. It seems only the first 6 are relevant. The numbers (0-F) are contained in bits 1-4 and 5-8 FOR THE FIRST THREE (0-2)! after the first three, it seems to NOT be true. So, I can read and display half of the ID (as in, I can display them combined, but I need to learn to do bitwise operations to really do what I want).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXT serial number

Post by afanofosc »

The NBC compiler on my machine has a defect with the GetBrickDataAddress function which causes a compiler error due to it generating nested asm blocks which are not valid syntax. A while back I added some low level IOMap routines to NXCDefs.h which broke that function along with a few others. What version of the compiler are you running?

In any case, I figured out what was going wrong and fixed the header file. I thought for a while it was a parsing bug caused by recent changes I made in the compiler itself but as far as I can tell it was just a problem in the NXCDefs.h header.

Here's a sample program (which I have checked in as a replacement for the ex_GetBrickDataAddress.nxc stub that is in the currently released help file):

Code: Select all

task main()
{
  byte data[];
  GetBrickDataAddress(data);
  // 6 bytes plus null
  TextOut(0, LCD_LINE1, StrCat(
    FormatNum("%2.2x", data[0]),
    FormatNum("%2.2x", data[1]),
    FormatNum("%2.2x", data[2]),
    FormatNum("%2.2x", data[3]),
    FormatNum("%2.2x", data[4]),
    FormatNum("%2.2x", data[5])));
  while (true);
}
The 7 bytes written to the array passed into GetBrickDataAddress include 6 bytes of Bluetooth ID and a null. The 12 digits are those 6 byte values (2 hex digits == 1 byte). The above code writes out a 12 hex digit string which is the NXT's ID. You could, of course, store that ID in a string rather than writing it to the LCD. The FormatNum function requires the enhanced NBC/NXC firmware. You could write a hex formatting function of your own that would work with the standard firmware if you need to support it.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXT serial number

Post by mattallen37 »

Thanks, that is the theory I came up with, but there is still a problem. When I go to view the NXT ID in the menu, I get a different result. In the menu I get "00165306A048" your program displays "00165309f346", which is what my program displays (actually, not exactly, but the same info). Why the inconsistency? Again, as you can see, the first three bytes (6 chars) are correct, but the last half is not right.

Edit: I accidental switched NXT's mid project, oops. Sorry. Thanks for the help.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXT serial number

Post by mattallen37 »

Now that I have that all working, how do you read the given name of the NXT (by default, it is "NXT")?
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: NXT serial number

Post by gloomyandy »

mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXT serial number

Post by mattallen37 »

No I hadn't. I only JUST got the search to work. Thanks for posting. Now, I need to look up how to change the name, from within the program.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXT serial number

Post by mattallen37 »

I searched for a while in the NXC guide, and tried quite a number of things, but I still haven't figured out how to change an NXT name (from within an NXC program). Could someone please tell me how to do it?
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXT serial number

Post by afanofosc »

The NXT firmware does not provide a way to set the name from within a running program. I'm not sure why you would want to do that. Can you share your thoughts regarding why that would be desirable?

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXT serial number

Post by mattallen37 »

I don't want to say too specifically, but it has to do with the encryption programs I built/am building. I don't NEED it, but it would be cool if there was a way to do it.

Probably the most desirable thing to do with it, would be to have a returned value from a program displayed throughout nearly all the menu.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests