Robbert, The NXT cannot tell what sensors are attached to it.
The values that you get back for sensor type will either be the values that you set via iCommand, or the ones which a program running on the NXT sets. If you know that an I2C sensor (such as the Ultrasonic sensor) is attached to a port, you can send it commands to get the type, product ID and version, but this does not work for Analog/Digital sensors like the light sensor, sound sensor or touch sensor. Lawrie ----- Original Message ----- From: "Robbert de Vries" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Wednesday, March 21, 2007 10:49 PM Subject: [Lejos-discussion] [Sensor ports] how to obtain the type of Sensorconnected > Hi all, > > I'm trying to create some generic SensorManager class that at > initialisation will look for attached sensors and make them available via > a little HashTable with the type as key. (so other code can lookup what is > actually attached and if needed say: gimme the mike, please) > I got the whole idea because I just want to plug a sensor cable in a > random socket, without needing to think about were it "should" go. > > Now, I found out that the documentation on iCommand is still very > rudimentary. > So I was wondering, since it's not really documented, what the int in > InputValues.sensorType would give me? I thought it was the key to my whole > plan, but... Is it me, or is it not functioning yet? > A little look in the source of iCommand didn't get my any further... it > looks like the returned ints (that should represent the type of sensor) > come pretty straight from the NXT brick. > > While having 3 different sensors connected, the following code > > InputValues iv; > Sensor sensor; > > for (int portno = 0; portno < NUMBEROFPORTS; portno++) { > iv = NXTCommand.getInputValues(portno); > if (iv != null) { > int type = iv.sensorType; > log.out(Logger.DEBUG, "[EMAIL PROTECTED]" + portno + " is type '" + type + > "'."); > } > } > > gives as output in my logging: > > SensorManager: [EMAIL PROTECTED] is type '0'. > SensorManager: [EMAIL PROTECTED] is type '0'. > SensorManager: [EMAIL PROTECTED] is type '0'. > SensorManager: [EMAIL PROTECTED] is type '0'. > > > Damn. > > -- > > cheers, > Robbert > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Lejos-discussion mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/lejos-discussion > > > -- > Internal Virus Database is out-of-date. > Checked by AVG Free Edition. > Version: 7.5.446 / Virus Database: 268.18.7/711 - Release Date: 05/03/2007 > 09:41 > > ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Lejos-discussion mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/lejos-discussion
