About Remote sensor read value

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

Moderators: roger, gloomyandy, skoehler

About Remote sensor read value

Postby oo7680485 » Wed Jul 09, 2014 7:19 am

I want to remotely control sensor and read it value
it is my code
Code: Select all
                RemoteEV3 ev3 = new RemoteEV3("192.168.137.38");

      //RMISampleProvider sp = ev3.createSampleProvider("S1", "lejos.hardware.sensor.NXTTouchSensor", "Touch");

      RMISampleProvider sp = ev3.createSampleProvider("S4", "lejos.hardware.sensor.NXTUltrasonicSensor", "Distance");
      
      float[] sample = sp.fetchSample();
      
      System.out.println("Sample");
      for(float data: sample) {
         System.out.println("  " + data);
      }
      
      sp.close();


I don't know why NXTTouchSensor can work but NXTUltrasonicSensor can't work.

NXTTouchSensor can return 1.0 or 0.0

if i use NXTUltrasonicSensor, it will error.
it is my error msg.

Code: Select all
Exception in thread "main" java.lang.NullPointerException
   at lejos.remote.ev3.RMIRemoteSampleProvider.fetchSample(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
   at sun.rmi.transport.Transport$1.run(Transport.java:177)
   at sun.rmi.transport.Transport$1.run(Transport.java:174)
   at java.security.AccessController.doPrivileged(Native Method)
   at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
   at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
   at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
   at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:745)
   at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
   at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
   at sun.rmi.server.UnicastRef.invoke(Unknown Source)
   at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
   at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
   at com.sun.proxy.$Proxy2.fetchSample(Unknown Source)
   at helloWorld.main(helloWorld.java:20)
oo7680485
New User
 
Posts: 3
Joined: Sat Jul 05, 2014 11:18 am

Re: About Remote sensor read value

Postby lawrie » Sat Jul 12, 2014 10:24 am

I just ran your code and it worked fine. What version of leJOS are you using?

The error checking in createSampleProvider is poor, and it you don't get the name of the sensor and the mode exactly right, you get the null pointer exception. Before the 0,8.1 release, I don't think the mode parameter was supported.
lawrie
leJOS Team Member
 
Posts: 921
Joined: Mon Feb 05, 2007 1:27 pm

Re: About Remote sensor read value

Postby oo7680485 » Tue Jul 15, 2014 7:59 am

I use Lejos0.8.1-beta

the error is version problem ?
oo7680485
New User
 
Posts: 3
Joined: Sat Jul 05, 2014 11:18 am

Re: About Remote sensor read value

Postby pipedream » Sat Aug 02, 2014 7:57 pm

I have the same issue and I'm using the same version. I also tried using RemoveEV3 instead of a local one via editing the TestSensors.java, getSensor(.) will throw similar error when initializing the sensor. However, the local version worked fine.
pipedream
New User
 
Posts: 9
Joined: Sat Aug 02, 2014 7:46 pm

Re: About Remote sensor read value

Postby ruperty » Tue Aug 05, 2014 8:59 pm

I have the same error when trying the Graph.java sample, for the gyro sensor

I have changed the properties to include class=lejos.hardware.sensor.EV3GyroSensor.

I have also added the mode "Rate" as the third parameter to

Code: Select all
sp = ev3.createSampleProvider(portName, sensorClass, mode);


Was a resolution found for this issue?
Regards,
Rupert
www.perceptualrobots.com
ruperty
Active User
 
Posts: 114
Joined: Sun Oct 14, 2007 11:21 am

Re: About Remote sensor read value

Postby pipedream » Thu Aug 07, 2014 7:59 pm

So those RMI methods and createSampleProvider cannot be applied to all kinds of sensors? I really need to get this work remotely with the IMUs. Is there any way we can code to make this work? Or this is just a hopeless waiting?
pipedream
New User
 
Posts: 9
Joined: Sat Aug 02, 2014 7:46 pm

Re: About Remote sensor read value

Postby gloomyandy » Thu Aug 07, 2014 8:55 pm

I'm sure the developer that works on this will take a look at it when he gets chance (please remember all of leJOS is created by people doing this stuff in their own time), but if you need a fix then you have the source, you could always look at that and try and fix the problem.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: About Remote sensor read value

Postby pipedream » Thu Aug 07, 2014 11:48 pm

Totally understandable. I was thinking of writing my own fix for this, but I think I need some pointers to start with.
pipedream
New User
 
Posts: 9
Joined: Sat Aug 02, 2014 7:46 pm

Re: About Remote sensor read value

Postby pipedream » Mon Aug 11, 2014 2:43 am

I got this fixed.

In i2cTransaction of lejos/remote/ev3/RemoteI2CPort.java

line 4x: System.arraycopy(res, 0, readBuf, readOffset, readLen);

add
if ( res.length > 0 )

YAY!
pipedream
New User
 
Posts: 9
Joined: Sat Aug 02, 2014 7:46 pm

Re: About Remote sensor read value

Postby pipedream » Mon Aug 11, 2014 8:26 pm

As as side note, this fix works when you are using a RemoteEV3 and driving the sensor instead of using RMISampleProvider. The RMISampleProvider method seems to be able to create the sample provider fine but it will give you null pointer exception if you try to fetchSample or close it.

Exception in thread "main" java.lang.NullPointerException
at lejos.remote.ev3.RMIRemoteSampleProvider.fetchSample(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at com.sun.proxy.$Proxy4.fetchSample(Unknown Source)
at swing_bar.TestSensors.main(TestSensors.java:192)
pipedream
New User
 
Posts: 9
Joined: Sat Aug 02, 2014 7:46 pm


Return to EV3 Software

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

more stuff