Processing.net help [NEEDED]

edited January 2016 in Library Questions

Hello all, I am having some trouble using processing.net.

First example: (This is how i should be initializing new client)

       import processing.net.*; 
        import procontroll.*;
        import java.io.*;

        Client myClient; 

        ControllIO controll;
        ControllDevice device;

        ControllStick leftStick;
        ControllStick rightStick;
        ControllSlider zTrigger;

        ControllButton button;
        float leftStickXval = 0;
        void setup(){
         size(400,400);

          myClient = new Client(this, "192.168.1.66", 1000); 

          controll = ControllIO.getInstance(this);
          controll.printDevices();

          ControllDevice device = controll.getDevice(2);

          println(device.getName()+" has:");

          controll = ControllIO.getInstance(this);

          device = controll.getDevice("Controller (Joytech 360 pad)");
          device.setTolerance(0.05f);


          ControllSlider leftX = device.getSlider(1);
          ControllSlider leftY = device.getSlider(0);

          ControllSlider rightX = device.getSlider(3);
          ControllSlider rightY = device.getSlider(2);

          zTrigger = device.getSlider(4);


          leftStick = new ControllStick(leftX,leftY);
          rightStick = new ControllStick(rightX,rightY);


          button = device.getButton(1);

        }

        float totalX = width;
        float totalY = height;
        void sendData(){
          myClient.write(leftStickXval*100 + "\r\n");
        }
        void draw(){
          background(255);
          fill(0);


          textSize(16);
          text("LeftX:" + leftStick.getX(), 25,25);
          text("LeftY:" + leftStick.getY()*-1, 25,50);

          text("rightX:" + rightStick.getX(), 25,100);
          text("rightY:" + rightStick.getY()*-1, 25,125);

          text("Z Trigger:" + zTrigger.getValue()*-1, 25,175);

          if(leftStickXval != leftStick.getX()){
            leftStickXval = leftStick.getX();
            sendData();
          }
        }

I initialize myClient and then i call sendData from void draw. The first time myClient.write is executed the code works HOWEVER any time after that I get the following error:

java.lang.NullPointerException
    at processing.net.Client.write(Unknown Source)
    at processing.net.Client.write(Unknown Source)
    at Quad_Controll_001.sendData(Quad_Controll_001.java:74)
    at Quad_Controll_001.draw(Quad_Controll_001.java:92)
    at processing.core.PApplet.handleDraw(PApplet.java:2270)
    at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
    at processing.core.PApplet.run(PApplet.java:2141)
    at java.lang.Thread.run(Thread.java:662)

More info (probably irrelevant?) I am using an arduino with a WiFi shield. when i get the error mentioned above I can restart the processing sketch and the arduino will update a value once untill this error occurs. As long as i restart the processing sketch the arduino will update every time without re-set so this suggests that it is problems on the processing side and not the arduino.

Answers

  • By the way, when I move the myClient = new client(...) into the sendData() method above the myClient.write The code with work except the processing sketch runs VERY slow when executing sendData();

    Example:

    import processing.net.*; 
    import procontroll.*;
    import java.io.*;
    
    Client myClient; 
    
    ControllIO controll;
    ControllDevice device;
    
    ControllStick leftStick;
    ControllStick rightStick;
    ControllSlider zTrigger;
    
    ControllButton button;
    float leftStickXval = 0;
    void setup(){
      size(400,400);
    
    
    
      controll = ControllIO.getInstance(this);
      controll.printDevices();
    
      ControllDevice device = controll.getDevice(2);
    
      println(device.getName()+" has:");
    
      controll = ControllIO.getInstance(this);
    
      device = controll.getDevice("Controller (Joytech 360 pad)");
      device.setTolerance(0.05f);
    
    
      ControllSlider leftX = device.getSlider(1);
      ControllSlider leftY = device.getSlider(0);
    
      ControllSlider rightX = device.getSlider(3);
      ControllSlider rightY = device.getSlider(2);
    
      zTrigger = device.getSlider(4);
    
    
      leftStick = new ControllStick(leftX,leftY);
      rightStick = new ControllStick(rightX,rightY);
    
    
      button = device.getButton(1);
    
    }
    
    float totalX = width;
    float totalY = height;
    void sendData(){
      myClient = new Client(this, "192.168.1.66", 1000); 
      myClient.write(leftStickXval*100 + "\r\n");
    }
    void draw(){
      background(255);
      fill(0);
    
    
      textSize(16);
      text("LeftX:" + leftStick.getX(), 25,25);
      text("LeftY:" + leftStick.getY()*-1, 25,50);
    
      text("rightX:" + rightStick.getX(), 25,100);
      text("rightY:" + rightStick.getY()*-1, 25,125);
    
      text("Z Trigger:" + zTrigger.getValue()*-1, 25,175);
    
      if(leftStickXval != leftStick.getX()){
        leftStickXval = leftStick.getX();
        sendData();
      }
    }
    
Sign In or Register to comment.