AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

NXT Bluetooth StartProgram Command

The forum is to discuss topics related to robotics, like building robot, controlling it, its software and hardware, etc.

NXT Bluetooth StartProgram Command

Postby havanab » Tue Jun 21, 2011 3:53 pm

Hi,
I'm currently working on a Mindstorms NXT software project where I use a bluetooth connection and direct commands to control the brick.
I got the motor commands to work properly, but now I have problems with the StartProgramm command as it is written in the Mindstorms documentation.

The format of the command should look like this:  Byte 0 - 0x00, Byte 1 - 0x00, Byte 2 to 21 - Filename (ASCIIZ String + Null Termination).

I tried quite everything, but I can't get the brick to start a programm. Maybe someone has an example that uses this command. My programming language is JavaScript, if you are intrested in, and my current approach looks like that:
 
Code: Select all
bytes[0] =   0x0D;                     // Length of the command (LSB)
   bytes[1] =   0x00;                      // Length of the Command (MSB)
   bytes[z+0] = 0x00;                      // Direct Command Mode
   bytes[z+1] = 0x00;                     // Start Program command type
   
   bytes[z+2] = 0x31;   //Filename in Little Endian Format - "Untitled-1" ---> "1-deltitnU"  + Null-Termination
   bytes[z+3] = 0x2D;
   bytes[z+4] = 0x64;
   bytes[z+5] = 0x65;
   bytes[z+6] = 0x6C;
   bytes[z+7] = 0x74;
   bytes[z+8] = 0x69;
   bytes[z+9] = 0x74;
   bytes[z+10] = 0x6E;
   bytes[z+11] = 0x55;   
   bytes[z+12] = 0x00;

Than I convert it into a string, that I send to the brick via bluetooth. I'm just wondering if I miss anything important?
Thanks in advance, bye havanab!
havanab
 
Posts: 2
Joined: Tue Jun 21, 2011 3:34 pm

Re: NXT Bluetooth StartProgram Command

Postby DaleStan » Fri Jun 24, 2011 2:04 pm

1) z is undefined in that code snippet. What is its value?
2) Little endian only applies for numbers. Strings are always first-character-at-lowest-address.
3) "Convert to string". What is the encoding on this string? 8-bit ASCII? UTF-8? UTF-9? UTF-16? If possible, capture the Bluetooth bytes off the air.
DaleStan
 
Posts: 86
Joined: Wed Jul 21, 2010 7:23 pm

Re: NXT Bluetooth StartProgram Command

Postby havanab » Mon Jul 04, 2011 4:04 pm

Thanks for your advice, so I figured it out, what the problem was with the help of a other mindstorms user.
Problem was that I need to add the file extension to the program name, which I didn't do because I thought it would be added automatically. I just post my current version which should work well and maybe it's useful for some other developers. ; )

JS-Code:
Code: Select all
function startProgram(fileName) {
var bytes = new Array();
   var fileNameBytes = new Array();
   var output;
   var commandLength = 7 + fileName.length ;
   var z = 2;
   
   bytes[0] =   commandLength.toString(16);   //0x11;   // Length of the command (LSB)
   bytes[1] =   0x00;                      // Length of the Command (MSB)
   bytes[z+0] = 0x00;                      // Direct Command Mode
   bytes[z+1] = 0x00;                     // Start Program command type
            
   //Convert the ASCII Filename Characters in an hexadecimal version
   for (i=0; i<fileName.length; i++) {
      fileNameBytes[i] = fileName.charCodeAt(i).toString(16);
      console.log(fileNameBytes[i]);
   }
         //File Ending
   fileNameBytes.push(0x2e);
   fileNameBytes.push(0x72);
   fileNameBytes.push(0x78);
   fileNameBytes.push(0x65);
   fileNameBytes.push(0x00);
   bytes = bytes.concat(fileNameBytes);
   
   return convertCommand( bytes); }

Best regards,
Havana
havanab
 
Posts: 2
Joined: Tue Jun 21, 2011 3:34 pm




Return to Robotics

cron