lejos.hardware.device.SensorMux for which device

This is where you talk about the EV3 hardware related topics such as the brick, sensors, LEGO pieces, etc.

Moderators: roger, gloomyandy, skoehler

lejos.hardware.device.SensorMux for which device

Postby hyperion » Sat May 10, 2014 9:24 am

Hello,

I have seen the class SensorMux in the lejos.hardware.device package. Which device can I use with that class? I only found the HiTechnic Multiplexer.

HiTechnic: -http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NSX2020 <- Does this one only support NXT ultrasonic sensor or alsoEV3 ultrasonic sensor?

Regards,
hyperion
hyperion
New User
 
Posts: 19
Joined: Thu Apr 10, 2014 8:43 am

Re: lejos.hardware.device.SensorMux for which device

Postby gloomyandy » Sat May 10, 2014 10:24 pm

That class was supplied by a leJOS user not by any of the leJOS team members. It has not been tested with the EV3. My understanding is that it is for the HiTechnics device. It will not support the EV3 sensors.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4239
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: lejos.hardware.device.SensorMux for which device

Postby hyperion » Fri May 23, 2014 7:41 pm

Hi,

I tested the class without success. In my view, I only have to call the constructor, configurate() and getDistance(). The method getDistance() always returns 0. I tried to search for the reason and copied the class so I can change the code.

I added a method getRegister() which makes me able to see the values of the registers. My plan was to find out which registers contain the values provided by the sensors connected to the multiplexer. Those registers should change if I move the sensor was my thought. But actually none of the registers do change.

Code: Select all
public void getRegister(){
      byte[] buf = new byte[16];
      byte register;
      register = 0x00;
      getData(register,buf,16);
  }


I added my method to the configurate method to see if some registers change in this phase. I expected that at least register 0x20 would change. But again, nothing changed.

Code: Select all
/**
    * This method is necessary to execute to connect sensors on it
    */
   public void configurate(){
        getRegister();         
        //Set the SMUX in halted mode: 0x10 0x20 0x00
        sendData(0x20, (byte)0x00);
        // Wait 50 ms for SMUX to clean up
        try{Thread.sleep(50);}catch(Exception e){}
        getRegister();
        //# Send auto-scan command: 0x10 0x20 0x01
        sendData(0x20, (byte)0x01);
        //# wait 500ms for auto-scan to complete
        try{Thread.sleep(600);}catch(Exception e){}        
        getRegister();
        //# Set the SMUX in normal mode: 0x10 0x20 0x02
        sendData(0x20, (byte)0x02);        
        getRegister();
   }


Do you have any idea why the registers will not update?

Following documents might help:

Registers:
http://www.hitechnic.com/cgi-bin/commer ... ey=NSX2020

Programmer guide
http://www.breigh.com/xander/HTSMUX-Tutorial-LATEST.pdf

Regards,
hyperion
hyperion
New User
 
Posts: 19
Joined: Thu Apr 10, 2014 8:43 am

Re: lejos.hardware.device.SensorMux for which device

Postby gloomyandy » Fri May 23, 2014 7:50 pm

Can you even read anything from it? Like the sensor name etc?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4239
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: lejos.hardware.device.SensorMux for which device

Postby gloomyandy » Fri May 23, 2014 9:09 pm

Also do not assume that reading 10 bytes from register 0x0 is the same as reading registers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. Not all devices support auto increment mode and not always on all of the registers. Oh and your code does not even read register 0x20 it only attempts to read registers 0-0x0f. Also register 0x20 may be write only, so you may not be able to read anything of use from it.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4239
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: lejos.hardware.device.SensorMux for which device

Postby hyperion » Fri May 23, 2014 9:59 pm

Hi,

oh thanks for your advice. Maybe it is a bit late to program:) I corrected the error and I now receive correct values.

If somebody is interested: example of reading registers(there might be a more elegant way to do this):
Code: Select all
public void getRegister(){
      char[] sensorVersionNumber = new char[8];
      char[] manufacturer  = new char[8];
      char[] sensorType = new char[8];
      byte[] command = new byte[1];
      byte[] status = new byte[1];
      byte[] ch1Mode = new byte[1];
      byte[] ch1Type = new byte[1];
      byte[] ch10t7 = new byte[1];
      byte[] ch18tF = new byte[1];
      
      byte[] buf = new byte[16];      
            
      buf = new byte[8];
      getData(0x00,buf,8);
      sensorVersionNumber = toChar(buf);
      
      buf = new byte[8];
      getData(0x08,buf,8);
      manufacturer = toChar(buf);
      
      buf = new byte[8];
      getData(0x10,buf,8);
      sensorType = toChar(buf);
      
      buf = new byte[1];
      getData(0x20,buf,1);
      command = buf;
      
      buf = new byte[1];
      getData(0x20,buf,1);
      status = buf;
      
      buf = new byte[1];
      getData(0x22,buf,1);
      ch1Mode = buf;
      
      buf = new byte[1];
      getData(0x23,buf,1);
      ch1Type = buf;
      
      buf = new byte[1];
      getData(0x36,buf,1);
      ch10t7 = buf;
      
      buf = new byte[1];
      getData(0x37,buf,1);
      ch18tF = buf;      
   }


Regards,
hyperion
hyperion
New User
 
Posts: 19
Joined: Thu Apr 10, 2014 8:43 am


Return to EV3 Hardware

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff