How to create a Device List

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

How to create a Device List

Postby esmetaman » Sun Sep 16, 2007 3:19 pm

Using as baseLine the brian bagnall's work with StartUpText Class, I have created a example to search NXT Bricks:

Code: Select all
import lejos.nxt.comm.*;
import lejos.nxt.*;
import java.util.Vector;

public class BTDeviceList {


   public static void getDeviceList(){
      byte[] cod = {0,0,8,4}; // Toy, Robot
      LCD.clear();
      LCD.drawString("Searching ...", 0, 0);
      LCD.refresh();
      Vector devList = Bluetooth.inquire(5, 10,cod);
      
      if (devList.size() > 0) {
         String[] names = new String[devList.size()];
         
         LCD.clear();
         LCD.drawString("Device List:",0,0);
         for (int i = 0; i < devList.size(); i++) {
            BTRemoteDevice btrd = ((BTRemoteDevice) devList.elementAt(i));
            names[i] = btrd.getFriendlyName();
            LCD.drawString(names[i],0,i+1);
         }
         LCD.refresh();
      } else {
         LCD.clear();
         LCD.drawString("no devices", 0, 0);
         LCD.refresh();
         try {
            Thread.sleep(2000);
         } catch (InterruptedException e) {}
      }   
   }
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      getDeviceList();
   }

}

Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.iloveneutrinos.com/
User avatar
esmetaman
Advanced Member
 
Posts: 290
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 4 guests

more stuff