Package javax.comm

Examples of javax.comm.SerialPort


    }
  }

  public void itemStateChanged(ItemEvent  ev)
  {
    SerialPort  port;
    String     sel = (String) ev.getItem();
    int    value = 0;

    if (sel.equals("None"))
    {
      value = SerialPort.PARITY_NONE;
    }

    else if (sel.equals("Odd"))
    {
      value = SerialPort.PARITY_ODD;
    }

    else if (sel.equals("Even"))
    {
      value = SerialPort.PARITY_EVEN;
    }

    else
    {
      this.showValue();
    }

    port = this.owner.port;

    if ((value > 0) && (port != null))
    {
      /*
       *  Set the parity.
       *
       *  Note: we must set all of the parameters, not just
       *  the parity, hence the use of get*
       */

      try
      {
        port.setSerialPortParams(port.getBaudRate(),
               port.getDataBits(),
               port.getStopBits(),
               value);
      }
   
      catch (UnsupportedCommOperationException e)
      {
        System.out.println("Cannot set parity to "
               + sel + " for port "
               + port.getName());
      }
    }

    this.owner.showValues();
  }
View Full Code Here


    System.exit(0);
  }

  private void cleanup()
  {
    SerialPort  p;

    while (portNum > 0)
    {
      portNum--;
      panelNum--;

      /*
       *  Close the port
       */

      p = portDisp[portNum].getPort();

      if (p != null)
      {
        System.out.println("Closing port "
               + portNum
               + " ("
               + p.getName()
               + ")");

        portDisp[portNum].closeBBPort();
      }
    }
View Full Code Here

    }
  }

  public void itemStateChanged(ItemEvent  ev)
  {
    SerialPort  port;
    String     sel = (String) ev.getItem();
    int    value = 0;

    if (sel.equals("5"))
    {
      value = SerialPort.DATABITS_5;
    }

    else if (sel.equals("6"))
    {
      value = SerialPort.DATABITS_6;
    }

    else if (sel.equals("7"))
    {
      value = SerialPort.DATABITS_7;
    }

    else if (sel.equals("8"))
    {
      value = SerialPort.DATABITS_8;
    }

    else
    {
      this.showValue();
    }

    port = this.owner.port;

    if ((value > 0) && (port != null))
    {
      /*
       *  Set the number of data bits.
       *
       *  Note: we must set all of the parameters, not just
       *  the number of data bits, hence the use of get*
       */

      try
      {
        port.setSerialPortParams(port.getBaudRate(),
               value,
               port.getStopBits(),
               port.getParity());
      }
   
      catch (UnsupportedCommOperationException e)
      {
        System.out.println("Cannot set data bit size to "
               + sel + " for port "
               + port.getName());
      }
    }

    this.owner.showValues();
  }
View Full Code Here

    this.owner = owner;
  }

  protected void showValue()
  {
    SerialPort  port = this.owner.port;

    if (this.owner.open)
    {
      /*
       *  Get the baud rate
       */
 
      this.select(new Integer(port.getBaudRate()).toString());
    }

    else
    {
      this.select("Unknown");
View Full Code Here

    }
  }

  public void itemStateChanged(ItemEvent  ev)
  {
    SerialPort  port;
    String     sel = (String) ev.getItem();
    int    value = 0;

    if (sel.equals("Unknown"))
    {
      this.showValue();
      return;
    }

    else
    {
      value = (new Integer(sel)).intValue();
    }

    port = this.owner.port;

    if ((value > 0) && (port != null))
    {
      /*
       *  Set the baud rate.
       *
       *  Note: we must set all of the parameters, not just
       *  the baud rate, hence the use of get*
       */

      try
      {
        port.setSerialPortParams(value,
               port.getDataBits(),
               port.getStopBits(),
               port.getParity());
      }
   
      catch (UnsupportedCommOperationException e)
      {
        System.out.println("Cannot set baud rate to "
               + sel + " for port "
               + port.getName());
      }
    }

    this.owner.showValues();
  }
View Full Code Here

    }
  }

  public void itemStateChanged(ItemEvent  ev)
  {
    SerialPort  port;
    String     sel = (String) ev.getItem();
    int    value = 0;

    if (sel.equals("1"))
    {
      value = SerialPort.STOPBITS_1;
    }

    else if (sel.equals("2"))
    {
      value = SerialPort.STOPBITS_2;
    }

    else if (sel.equals("1.5"))
    {
      value = SerialPort.STOPBITS_1_5;
    }

    else
    {
      this.showValue();
    }

    port = this.owner.port;

    if ((value > 0) && (port != null))
    {
      /*
       *  Set the number of stop bits.
       *
       *  Note: we must set all of the parameters, not just
       *  the number of stop bits, hence the use of get*
       */

      try
      {
        port.setSerialPortParams(port.getBaudRate(),
               port.getDataBits(),
               value,
               port.getParity());
      }
   
      catch (UnsupportedCommOperationException e)
      {
        System.out.println("Cannot set stop bit size to "
               + sel + " for port "
               + port.getName());
      }
    }

    this.owner.showValues();
  }
View Full Code Here

    }
  }

  public void itemStateChanged(ItemEvent  ev)
  {
    SerialPort  port;
    String     sel = (String) ev.getItem();
    int    value = 0;

    if (sel.equals("5"))
    {
      value = SerialPort.DATABITS_5;
    }

    else if (sel.equals("6"))
    {
      value = SerialPort.DATABITS_6;
    }

    else if (sel.equals("7"))
    {
      value = SerialPort.DATABITS_7;
    }

    else if (sel.equals("8"))
    {
      value = SerialPort.DATABITS_8;
    }

    else
    {
      this.showValue();
    }

    port = this.owner.port;

    if ((value > 0) && (port != null))
    {
      /*
       *  Set the number of data bits.
       *
       *  Note: we must set all of the parameters, not just
       *  the number of data bits, hence the use of get*
       */

      try
      {
        port.setSerialPortParams(port.getBaudRate(),
               value,
               port.getStopBits(),
               port.getParity());
      }
   
      catch (UnsupportedCommOperationException e)
      {
        System.out.println("Cannot set data bit size to "
               + sel + " for port "
               + port.getName());
      }
    }

    this.owner.showValues();
  }
View Full Code Here

    this.owner = owner;
  }

  protected void showValue()
  {
    SerialPort  port = this.owner.port;

    if (this.owner.open)
    {
      /*
       *  Get the baud rate
       */
 
      this.select(new Integer(port.getBaudRate()).toString());
    }

    else
    {
      this.select("Unknown");
View Full Code Here

    }
  }

  public void itemStateChanged(ItemEvent  ev)
  {
    SerialPort  port;
    String     sel = (String) ev.getItem();
    int    value = 0;

    if (sel.equals("Unknown"))
    {
      this.showValue();
      return;
    }

    else
    {
      value = (new Integer(sel)).intValue();
    }

    port = this.owner.port;

    if ((value > 0) && (port != null))
    {
      /*
       *  Set the baud rate.
       *
       *  Note: we must set all of the parameters, not just
       *  the baud rate, hence the use of get*
       */

      try
      {
        port.setSerialPortParams(value,
               port.getDataBits(),
               port.getStopBits(),
               port.getParity());
      }
   
      catch (UnsupportedCommOperationException e)
      {
        System.out.println("Cannot set baud rate to "
               + sel + " for port "
               + port.getName());
      }
    }

    this.owner.showValues();
  }
View Full Code Here

    }
  }

  public void itemStateChanged(ItemEvent  ev)
  {
    SerialPort  port;
    String     sel = (String) ev.getItem();
    int    value = 0;

    if (sel.equals("1"))
    {
      value = SerialPort.STOPBITS_1;
    }

    else if (sel.equals("2"))
    {
      value = SerialPort.STOPBITS_2;
    }

    else if (sel.equals("1.5"))
    {
      value = SerialPort.STOPBITS_1_5;
    }

    else
    {
      this.showValue();
    }

    port = this.owner.port;

    if ((value > 0) && (port != null))
    {
      /*
       *  Set the number of stop bits.
       *
       *  Note: we must set all of the parameters, not just
       *  the number of stop bits, hence the use of get*
       */

      try
      {
        port.setSerialPortParams(port.getBaudRate(),
               port.getDataBits(),
               value,
               port.getParity());
      }
   
      catch (UnsupportedCommOperationException e)
      {
        System.out.println("Cannot set stop bit size to "
               + sel + " for port "
               + port.getName());
      }
    }

    this.owner.showValues();
  }
View Full Code Here

TOP

Related Classes of javax.comm.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.