vitroblue 0 Newbie Poster

hello

i'm supposed to configure a microcontroller connected by serial port all the way from another machine but i'm having troubles fusing my codes


this is my rmi stuff

import java.rmi.*;
import java.rmi.server.*;
import java.net.*;

public class SerialServant extends UnicastRemoteObject implements Communication {  
  
  public SerialServant () throws RemoteException {
    super();
  }

  public String RxRx(){
	//do something
  }

   void TxTx(String blaf)  throws java.rmi.RemoteException{
	//do something
   }  
} 


import java.rmi.*;

public interface Communication extends Remote 
{
   String RxRx () throws java.rmi.RemoteException;
   void TxTx(String blaf)  throws java.rmi.RemoteException;
} 


import java.rmi.*;
import java.rmi.server.*;
import java.net.*;
import java.util.*;  
  
public class SerialServer {  
   public static void main(String args[]) {  
      try {
      SerialServant blaffness =   
            new SerialServant();  
      Naming.rebind("yo", blaffness);

         System.out.println("server started....");  
        
      } catch(Exception e) {  
         System.err.println("ERROR: " + e);  
         e.printStackTrace(System.out);  
      }    
   }  
}

and my servlet

import java.io.*;
import java.sql.*;
import java.rmi.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class recibirysubir extends HttpServlet {
//interface
 Communication blaffness =null;
//console buffer
 private PrintWriter out;
//jdbc
 private Connection connection = null;
 private Statement stmt = null;
 private String URL = "jdbc:odbc:proyecto";		//nombre del archivo de la bd
 private ResultSet resultSet;
 private ResultSetMetaData rsMetaData;

 public void init( ServletConfig config ) throws ServletException{
  super.init( config );

   //jdbc stuff

  System.out.println("RMI");
  try {
   blaffness = (Communication) Naming.lookup("yo");
  } catch(Exception e) {  
   System.out.println("ERROR : " + e);  
   e.printStackTrace(System.out);  
  }
 }

 public void doGet(HttpServletRequest req,
                   HttpServletResponse res)
                   throws ServletException, IOException {
  //weird heck of stuff that gets all parameters from a form, process them and readies the results to upload them to a database and to transmit them by rmi

   int x,y;
   for(int i=0;i<secu.length;i++){
    x=i+1;
    //print to web page
    out.println("UPDATE secuencias SET Asignacion="+secu[i]+" WHERE ID="+x+"<br/>");
    //print to console
    System.out.println("UPDATE secuencias SET Asignacion="+secu[i]+" WHERE ID="+x);
    //uploading to database
    y= stmt.executeUpdate("UPDATE secuencias SET Asignacion="+secu[i]+" WHERE ID="+x);

   }

//sending by rmi 
   out.println("sending commands RMI<br/>");
   try {  
    blaffness.RxRx(comands);  
   } catch (Exception e) {
    e.printStackTrace();
   }  
  }catch ( SQLException sqlex ) {
   out.println("Unable to connect<br/>");
   System.err.println( "Unable to connect");
   sqlex.printStackTrace();
  }catch ( Exception e ) {
   e.printStackTrace();
   connection = null;
  }

  out.println("</body>");
  out.println("");
  out.println("</html>");
 }
}

this way i'm supposed to connect to any computer, and reconfigure remotely the microcontroller
am i vaguely right or should i start over?
also, where in all this mess should i put all my serial port code? in the serialServant file?

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.