How can I remote control EV3 by PC with WiFi?

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

Moderators: roger, gloomyandy, skoehler

How can I remote control EV3 by PC with WiFi?

Postby oo7680485 » Sat Jul 05, 2014 11:35 am

Hello everyone:

I have seen this viewtopic.php?f=18&t=5434

But I still don't know how to remote control EV3 by PC with Wifi

Could some help me~~~THX.

Code:
Code: Select all
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import javax.swing.JButton;
import javax.swing.JFrame;

import lejos.hardware.BrickFinder;
import lejos.remote.ev3.RMIRegulatedMotor;
import lejos.remote.ev3.RemoteEV3;

public class WiFiConnect extends JFrame{
   public WiFiConnect() {
         super("My Controller");
         RemoteEV3 ev3;
      try {
         ev3 = new RemoteEV3("192.168.137.47");
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         JButton rotate = new JButton("Rotate");
         this.getContentPane().add(rotate);
         final RMIRegulatedMotor left = ev3.createRegulatedMotor("A",'N');
         final RMIRegulatedMotor right = ev3.createRegulatedMotor("B",'N');

         rotate.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
               try {
                  left.rotate(500,true);
                  right.rotate(-500);
               } catch (RemoteException e) {
                  e.printStackTrace();
               }
            }         
         });
        
          addWindowListener(new WindowAdapter() {
              @Override
              public void windowClosing(WindowEvent e) {
                 try {
                  left.close();
                  right.close();
               } catch (RemoteException e1) {
                  e1.printStackTrace();
               }
              }
          });

      } catch (RemoteException e2) {
         // TODO Auto-generated catch block
         e2.printStackTrace();
      } catch (MalformedURLException e2) {
         // TODO Auto-generated catch block
         e2.printStackTrace();
      } catch (NotBoundException e2) {
         // TODO Auto-generated catch block
         e2.printStackTrace();
      }
      }
      
      public static void main(String[] args) {
         WiFiConnect control = new WiFiConnect();
           control.pack();
           control.setVisible(true);
      }
}


error message:
Code: Select all
Exception in thread "main" lejos.hardware.DeviceException: unable to open port
   at lejos.internal.ev3.EV3Port.open(Unknown Source)
   at lejos.hardware.motor.BaseRegulatedMotor.<init>(Unknown Source)
   at lejos.hardware.motor.NXTRegulatedMotor.<init>(Unknown Source)
   at lejos.remote.ev3.RMIRemoteRegulatedMotor.<init>(Unknown Source)
   at lejos.remote.ev3.RMIRemoteEV3.createRegulatedMotor(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.$Proxy0.createRegulatedMotor(Unknown Source)
   at lejos.remote.ev3.RemoteEV3.createRegulatedMotor(Unknown Source)
   at WiFiConnect.<init>(WiFiConnect.java:25)
   at WiFiConnect.main(WiFiConnect.java:64)
oo7680485
New User
 
Posts: 3
Joined: Sat Jul 05, 2014 11:18 am

Re: How can I remote control EV3 by PC with WiFi?

Postby lawrie » Wed Jul 09, 2014 2:03 pm

If the motors are failing to open, then either you have the motors attached to the wrong port, or they are already open and have not been closed. Restart the EV3 and check that the motors are in the right ports and then see if the program works.
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff