Problems to create and instantiate a NXTColorsensor in a ev3 Brick

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

Moderators: roger, gloomyandy, skoehler

Codername
New User
Posts: 4
Joined: Sun Mar 20, 2016 6:23 pm
Location: Brazil

Problems to create and instantiate a NXTColorsensor in a ev3 Brick

Postby Codername » Sun Mar 20, 2016 6:27 pm

My program freezes when instantiate the NXTColorsensor in a BRICK EV3:

private static NXTColorSensor sCor = new NXTColorSensor(BrickFinder.getDefault().getPort("S4"));
…..
sCor. setFloodlight(Color.GREEN);


... The program freezes and the LED turns white

Lejos use the version 0.9.1 beta, it is also important to inform the control center EV3 application(LEJOS program) does not recognize also my NXT 2.0 color sensor, but the legacy software (Lego Mindstorms) brick recognizes normally.

There are some compatibility problem with this version NXTColorSensor ?

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Problems to create and instantiate a NXTColorsensor in a ev3 Brick

Postby gloomyandy » Sun Mar 20, 2016 6:36 pm

Firstly please do not post questions like this in the development forum, that section is intended for discussions about developing leJOS.

Please post a short test program that demonstrates the problem that you are seeing along with a description of how you are compiling and running the program, what you expect to happen and what actually happens.
leJOS news https://lejosnews.wordpress.com/

Codername
New User
Posts: 4
Joined: Sun Mar 20, 2016 6:23 pm
Location: Brazil

Re: Problems to create and instantiate a NXTColorsensor in a ev3 Brick

Postby Codername » Sun Mar 20, 2016 7:24 pm

Moderator please move this topic to the appropriate place

Just like the sensor LED to turn green. But in addition to the LED turns white, it crashes my program.

The code is super simple but is not running, it is freezing while running without generating any exception.
I'm using a NXT 2.0 Color Sensor in a brick EV3 on the port S4.


I'm using JRE/JDK 1.8 and compiling for JSE1.7

Code: Select all

.
.

public class ServerLAG extends Thread{

   public static final int  port = 1020;
   private Socket client;
   private ObjectInputStream input;
   private InputStream in;
   private OutputStream out;
   private static boolean looping = true;
   private static ServerSocket server;
   private static EV3LargeRegulatedMotor A = new EV3LargeRegulatedMotor(MotorPort.A);
   private static EV3LargeRegulatedMotor B = new EV3LargeRegulatedMotor(MotorPort.B);
   private static EV3ColorSensor sCor = new EV3ColorSensor(BrickFinder.getDefault().getPort("S1"));
   private static NXTColorSensor sCor2 = new NXTColorSensor(BrickFinder.getDefault().getPort("S4")); // Crashing

   
   
 public static void main(String[] args) throws IOException  {

     sCor.setFloodlight(Color.BLUE);  // Execute normaly

    sCor2.setFloodlight(Color.GREEN); // Crashing
   
      System.out.println("Server Started.");
      
      
      server = new ServerSocket(port);
      
         while (looping){
            
            System.out.println("Awaiting Client..");
          
            new ServerLAG(server.accept()).start();
            
         } //while
            
   }// Main        
   
    public ServerLAG(Socket client)
   {
      this.client = client;
      Button.ESCAPE.addKeyListener(new EscapeListener() );
   }
   
    public void run(){
   
    try{
            in = client.getInputStream();
            DataInputStream dataIn = new DataInputStream(in);
//              input =new ObjectInputStream(in);
//           System.out.println("Created");
          String resp = (String) dataIn.readLine();
           if (resp.equals("handshake")  )
   
                 .
                 .
                 .
                 .
                 initiate code on  comm network



I found it interesting to mention that the Eclipse menu STARTEV3CONTROL "LEJOS EV3" does not recognize the connected sensorColor.
Last edited by Codername on Sun Mar 20, 2016 8:39 pm, edited 2 times in total.

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Problems to create and instantiate a NXTColorsensor in a ev3 Brick

Postby gloomyandy » Sun Mar 20, 2016 7:42 pm

I've already moved your thread.

What do you mean by "it crashes your program"? You say you do not get an exception, but what does happen? Can you abort the program by pressing ENTER+DOWN at the same time? Do you ever see the message "server started"?

As I said before please provide a complete program that demonstrates the problem (with as little as possible extra code in it), that way we can try the same program and be sure we are testing the same conditions as you. So for instance what happens if your program uses only the NXT color sensor, no motors, no other sensors, no network code. If you don't write that code we will have to!
leJOS news https://lejosnews.wordpress.com/

Codername
New User
Posts: 4
Joined: Sun Mar 20, 2016 6:23 pm
Location: Brazil

Re: Problems to create and instantiate a NXTColorsensor in a ev3 Brick

Postby Codername » Sun Mar 20, 2016 8:19 pm

I can not see the message "server started", the LCD screen is blank. I leave the program by pressing ENTER + DOWN, and also the port 1 sensor does not change color to blue.

I believe there must be some problem with the STATIC NXTColorSensor constructor method, is not associated methods, because when suppress it, my application runs normally. Including changing color sensor in port 1

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Problems to create and instantiate a NXTColorsensor in a ev3 Brick

Postby gloomyandy » Mon Mar 21, 2016 2:50 am

As I said before, simplify your program. Remove all of the extra sensors, motors etc. If it still crashes try the same code but instead of using statics, use local variables in your main method. If that still crashes try the same code but use a different sensor port. Post the simplest code you can here along with the results that you have found.
leJOS news https://lejosnews.wordpress.com/

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Problems to create and instantiate a NXTColorsensor in a ev3 Brick

Postby gloomyandy » Mon Mar 21, 2016 2:27 pm

Hi,
I managed to get some time to look at this and there is indeed a bug with opening this sensor. I have a fix for it that requires a new version of the ev3classes.jar file. You can download a test version of this here:
https://drive.google.com/file/d/0BwTg7x ... sp=sharing

To use this you will need to replace the existing ev3classes.jar on your EV3. This is located at:
/home/root/lejos/lib/ev3classes.jar
There are a number of ways you can update this file. Probably the easiest is to use scp see this thread for details on a Windows program that uses scp:
viewtopic.php?f=18&t=8084&p=29529&hilit=scp#p29529
note that if you are using WiFi to connect to your EV3 then you will need to specify the IP address of your EV3 not 10.0.1.1

Please let me know if this fixes your problem (or if you are not able to test it).
leJOS news https://lejosnews.wordpress.com/

Codername
New User
Posts: 4
Joined: Sun Mar 20, 2016 6:23 pm
Location: Brazil

Re: Problems to create and instantiate a NXTColorsensor in a ev3 Brick

Postby Codername » Tue Mar 22, 2016 2:49 am

It´s running.... thanks ! :D :D :D :D :D :D :D :D :D

... this library is a new release/version of Lejos ?

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Problems to create and instantiate a NXTColorsensor in a ev3 Brick

Postby gloomyandy » Tue Mar 22, 2016 7:41 am

This code is in the developer build of leJOS it has not yet been released. It will be part of the next release.
leJOS news https://lejosnews.wordpress.com/


Return to “EV3 Software”

Who is online

Users browsing this forum: jippiee and 1 guest