Package gnu.io

Examples of gnu.io.SerialPort


    return portFound;
  }

  public void liberalizaPuertosNoUsados() {
    for (int i = 0; i < puertos.size(); i++) {
      SerialPort serialAux = (SerialPort) puertos.get(i);
      if (serialPort != serialAux) {
        System.out
            .println(Messages
                .getString("io.SerialCommunication.10") + serialAux.getName()); //$NON-NLS-1$
        serialAux.close();
        puertos.remove(serialAux);
        i--;
      }
    }
  }
View Full Code Here


                            log
                                    .debug("Serial port found : "
                                            + portId.getName());
                        }

                        SerialPort serialPort = initializePort("Apache MINA",
                                portId, portAddress);

                        ConnectFuture future = new DefaultConnectFuture();
                        SerialSessionImpl session = new SerialSessionImpl(
                                this, getListeners(), portAddress, serialPort);
View Full Code Here

        long connectTimeout = getConnectTimeoutMillis();
        if (connectTimeout > Integer.MAX_VALUE) {
            connectTimeout = Integer.MAX_VALUE;
        }

        SerialPort serialPort = (SerialPort) portId.open(
                user, (int) connectTimeout);

        serialPort.setSerialPortParams(portAddress.getBauds(), portAddress
                .getDataBitsForRXTX(), portAddress.getStopBitsForRXTX(),
                portAddress.getParityForRXTX());

        serialPort.setFlowControlMode(portAddress.getFLowControlForRXTX());

        serialPort.notifyOnDataAvailable(true);

        if (config.isLowLatency()) {
            serialPort.setLowLatency();
        }

        serialPort.setInputBufferSize(config.getInputBufferSize());
        serialPort.setOutputBufferSize(config.getOutputBufferSize());

        if (config.getReceiveThreshold() >= 0) {
            serialPort.enableReceiveThreshold(config.getReceiveThreshold());
        } else {
            serialPort.disableReceiveThreshold();
        }

        return serialPort;
    }
View Full Code Here

                    try {
                        if (log.isDebugEnabled()) {
                            log.debug("Serial port found : " + portId.getName());
                        }

                        SerialPort serialPort = initializePort("Apache MINA", portId, portAddress);

                        ConnectFuture future = new DefaultConnectFuture();
                        SerialSessionImpl session = new SerialSessionImpl(this, getListeners(), portAddress, serialPort);
                        initSession(session, future, sessionInitializer);
                        session.start();
View Full Code Here

        long connectTimeout = getConnectTimeoutMillis();
        if (connectTimeout > Integer.MAX_VALUE) {
            connectTimeout = Integer.MAX_VALUE;
        }

        SerialPort serialPort = (SerialPort) portId.open(user, (int) connectTimeout);

        serialPort.setSerialPortParams(portAddress.getBauds(), portAddress.getDataBitsForRXTX(),
                portAddress.getStopBitsForRXTX(), portAddress.getParityForRXTX());

        serialPort.setFlowControlMode(portAddress.getFLowControlForRXTX());

        serialPort.notifyOnDataAvailable(true);

        if (config.isLowLatency()) {
            serialPort.setLowLatency();
        }

        serialPort.setInputBufferSize(config.getInputBufferSize());
        serialPort.setOutputBufferSize(config.getOutputBufferSize());

        if (config.getReceiveThreshold() >= 0) {
            serialPort.enableReceiveThreshold(config.getReceiveThreshold());
        } else {
            serialPort.disableReceiveThreshold();
        }

        return serialPort;
    }
View Full Code Here

  static RobotCamColorTrack prueba;
  static OutputStream out;
  public static void main(String[] args) throws Exception {

    CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier( "COM3d" );
    SerialPort sp = (SerialPort)portId.open("SerialCommunicationChannel", 2000);

    sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    out  = sp.getOutputStream();
   
    DataInputStream i=new DataInputStream(System.in);

    while(true) {     
      int direccion;
View Full Code Here

//    sc.open("banana, COM5");

//    sc.send("advance");

    CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier( "COM6" );
    SerialPort sp = (SerialPort)portId.open("SerialCommunicationChannel", 2000);

    sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    out  = sp.getOutputStream();
//    sc = new SerialComm("6",3);*/

    prueba = new RobotCamColorTrack("5");
    if (!prueba.setupCamera())
    {
      out.close();
      sp.close();
      return;
    }

    boolean continuar = true;

    int maxX=0,maxY=0,minX = 5000, minY = 5000;
   
    int remainingMovements = 200;
   
    int direccion = RobotCamColorTrack.NO_MOVE;
    int modo;
   
    int[] rgbMinRail = {43,52,120};
    int[] rgbMaxRail = {93,102,170};
    int[] rgbMinRed = {120,0,0};
    int[] rgbMaxRed = {180,51,46};
    int[] rgbMinViolet = {16,5,54};
    int[] rgbMaxViolet= {66,55,104};

    int areamax = 0;
    int antmove = RobotCamColorTrack.MOVER_ADELANTE;
    int meanxcolor = 0;
    TrackingInformation tiRail;
    TrackingInformation tiRed;
    TrackingInformation tiViolet;

    boolean redPlace = false;

    modo = 1;

    while(remainingMovements > 0 && !redPlace) {
   
      //TrackingInformation tiRail = prueba.addTrackingInformation(RobotCamColorTrack.TRACK_RAIL, rgbMinRail, rgbMaxRail);     
      //TrackingInformation tiRed = prueba.addTrackingInformation(RobotCamColorTrack.TRACK_RED, rgbMinRed, rgbMaxRed);
      int samples = 1;

      prueba.grabFrame();
      tiRail = prueba.addTrackingSamples(RobotCamColorTrack.TRACK_RAIL, rgbMinRail, rgbMaxRail, samples);
      tiViolet = prueba.addTrackingSamples(RobotCamColorTrack.TRACK_RED, rgbMinRed, rgbMaxRed, samples);
      tiRed = prueba.addTrackingSamples(RobotCamColorTrack.TRACK_RED, rgbMinRed, rgbMaxRed, samples);
     

      //boolean colisionRail = prueba.isCollision(RobotCamColorTrack.TRACK_RAIL,400,80);
      //boolean colisionRed = prueba.isCollision(RobotCamColorTrack.TRACK_RED,30,20);
     
      System.out.println("Movimiento: "+(200-remainingMovements));

      System.out.println("===========================");
      System.out.println("RAIL");
      System.out.println(tiRail);

      System.out.println("===========================");
      System.out.println("RED");
      System.out.println(tiRed);
     
      //redPlace = (prueba.isInPlace(RobotCamColorTrack.TRACK_RED, 4500, 255,5,1) && tiRail.isCollision());

      int railMass = tiRail.getColorMass();
      int colorMass = tiRed.getColorMass();
     
      if (modo==1)
      {
        direccion = prueba.getTurningDirection(tiRail.getMeanX(),railMass,15,antmove);
        antmove = direccion;

/*        if (tiRail.getColorMass()<MINIMO_MASA)
        {
          if (tiRed.getColorMass()>MINIMO_MASA_CAMBIO_MODO_COLOR)
          {
            System.out.println("CAMBIO MODO 2");
            areamax=tiRed.getArea();
            modo = 2;
          }
        }*/
/*        if (tiRed.getColorMass()<MINIMO_MASA)
        {
          if (direccion==RobotCamColorTrack.MOVER_ADELANTE)
          {
            direccion = prueba.getTurningDirection(meanxcolor);         
          }
        }
        else
        {
          meanxcolor = tiRed.getMeanX();
        }*/
      }
      if (modo==2)
      {
        direccion = prueba.getTurningDirection(tiRed.getMeanX(),colorMass,15,antmove);
        antmove = direccion;

        if (((tiRed.getArea()<MINIMO_AREA_FIN) && (areamax>MAXIMO_AREA_FIN)) || (areamax>MAXIMO_SUPER_AREA_FIN))// || (tiRed.getColorMass()<MINIMO_MASA_FIN))
        {
          System.out.println("LLEGUE!! AREA MAX "+areamax);
          modo=3;
          remainingMovements=0;
        }
        if (areamax<tiRed.getArea())
          areamax=tiRed.getArea();
      }
      if (modo==3)
      {
        direccion = RobotCamColorTrack.MOVER_DERECHA;
        int massviolet = tiViolet.getColorMass();
        int massred = tiRed.getColorMass();
       
      }
      if (remainingMovements>0)
        moverRobot(direccion,(direccion != RobotCamColorTrack.MOVER_ADELANTE) ? '2' : '5');

      remainingMovements--;
    }
   
    out.close();
    sp.close();
  }
View Full Code Here

      System.out.println("Es necesario especificar por par�metro el puerto COM a utilizar - Ej: 'java -jar SimpleBot.jar COM4'");
      return;
    }
   
    CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier( args[0] );
    SerialPort sp = (SerialPort)portId.open("SerialCommunicationChannel", 2000);

    sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    out  = sp.getOutputStream();

    prueba = new RobotCamColorTrack("3");
    if (!prueba.setupCamera()) {
      out.close();
      sp.close();
      return;
    }
   
    int remainingMovements = 200;
   
    int direccion = RobotCamColorTrack.NO_MOVE;
    int antmove = RobotCamColorTrack.MOVER_ADELANTE;

    boolean redPlace = false;

    loadProperties();
    buildRailArray();
    buildColorArray();
    
    int i=0;
    while(remainingMovements > 0 && !redPlace) {
   
      int samples = 1;

      prueba.grabFrame();
      ArrayList<TrackingInformation> tiRails = getRailTrackingInformation(railArray, samples);
      ArrayList<TrackingInformation> tiColors = getRailTrackingInformation(colorArray, samples);
     
      TrackingInformation currentRail = calculateBestColor(tiRails);
      VectorValues currentVector = calculateBestVector(tiColors);
 
      System.out.println("Movimiento: "+(200-remainingMovements));

      System.out.println("===========================");
      System.out.println(currentRail.getDescription());
      System.out.println(currentRail.toString());

      System.out.println("===========================");
      System.out.println(currentVector.getDescription());
      System.out.println(currentVector.toString());
     
      int railMass = currentRail.getColorMass();
      int colorMass = 0;//XtiGray.getColorMass();
     
      direccion = prueba.getTurningDirection(currentRail.getMeanX(),railMass,15,antmove);
      antmove = direccion;
     
      System.out.println("IS IN PLACE = "+ isInPlace(currentVector,bestVectorDistance,direccion));
      //direccion=RobotCamColorTrack.MOVER_IZQUIERDA;
      if (remainingMovements>0)
        moverRobot(direccion,(direccion != RobotCamColorTrack.MOVER_ADELANTE) ? '3' : '7');
//     
      remainingMovements--;
     
      if(colorMass > 255*0.9) {
        System.out.println("\n\nLLEGO AL GRIS\n\n");
        break;
      }
    }
   
    out.close();
    sp.close();
  }
View Full Code Here

           
            commPort = portIdentifier.open("jStation",2000);
           
            if ( commPort instanceof SerialPort )
            {
                SerialPort serialPort = (SerialPort) commPort;
               
                serialPort.setSerialPortParams(Integer.parseInt(baudRate),SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
               
                InputStream in = serialPort.getInputStream();
                OutputStream out = serialPort.getOutputStream();
               
                (new Thread(new SerialReader(in))).start();
                (new Thread(new SerialWriter(out))).start();

            }
View Full Code Here

                            log
                                    .debug("Serial port found : "
                                            + portId.getName());
                        }

                        SerialPort serialPort = initializePort("Apache MINA",
                                portId, portAddress);

                        ConnectFuture future = new DefaultConnectFuture();
                        SerialSessionImpl session = new SerialSessionImpl(
                                this, getListeners(), portAddress, serialPort);
View Full Code Here

TOP

Related Classes of gnu.io.SerialPort

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.