Package purejavacomm

Examples of purejavacomm.SerialPort


          8 - requiredExtraBits);
      System.exit(1);
      return;
    }

    SerialPort p = (SerialPort) CommPortIdentifier.getPortIdentifier(
        args[0]).open(TwoPortSerialTest.class.getName(), 0);

    p.setSerialPortParams(baudRate, dataBits, stopBits, parity);

    OutputStream out = p.getOutputStream();

    final int N = (1 << dataBits);

    for (int n = 0; n < N; n++) {
      out.write(n);
View Full Code Here


          8 - requiredExtraBits);
      System.exit(1);
      return;
    }

    SerialPort p = (SerialPort) CommPortIdentifier.getPortIdentifier(
        args[0]).open(TwoPortSerialTest.class.getName(), 0);

    p.setSerialPortParams(baudRate, dataBits + requiredExtraBits,
        SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    p.enableReceiveTimeout(10000);

    InputStream in = p.getInputStream();
    while (in.available() != 0) {
      in.read();
    }

    System.out.println("Waiting for A...");
View Full Code Here

  {
    String portName = String.valueOf( this.portSelect.getSelectedItem() );

    CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier( portName );

    SerialPort result = ( SerialPort )portId.open( "Serial console tool", 1000 );

    int baudrate = NumberUtils.smartParseInt( String.valueOf( this.portRateSelect.getSelectedItem() ) );

    String db = ( String )this.dataBitsSelect.getSelectedItem();
    int databits;
    if ( "5".equals( db ) )
    {
      databits = SerialPort.DATABITS_5;
    }
    else if ( "6".equals( db ) )
    {
      databits = SerialPort.DATABITS_6;
    }
    else if ( "7".equals( db ) )
    {
      databits = SerialPort.DATABITS_7;
    }
    else
    {
      databits = SerialPort.DATABITS_8;
    }

    String sb = ( String )this.stopBitsSelect.getSelectedItem();
    int stopbits;
    if ( "2".equals( sb ) )
    {
      stopbits = SerialPort.STOPBITS_2;
    }
    else if ( "1.5".equals( sb ) )
    {
      stopbits = SerialPort.STOPBITS_1_5;
    }
    else
    {
      stopbits = SerialPort.STOPBITS_1;
    }

    final String par = String.valueOf( this.paritySelect.getSelectedItem() );
    int parity;
    if ( "Odd".equalsIgnoreCase( par ) )
    {
      parity = SerialPort.PARITY_NONE;
    }
    else if ( "Even".equalsIgnoreCase( par ) )
    {
      parity = SerialPort.PARITY_EVEN;
    }
    else
    {
      parity = SerialPort.PARITY_NONE;
    }

    String fc = String.valueOf( this.flowControlSelect.getSelectedItem() );
    int flowControl;
    if ( fc.startsWith( "XON" ) )
    {
      flowControl = SerialPort.FLOWCONTROL_XONXOFF_IN | SerialPort.FLOWCONTROL_XONXOFF_OUT;
    }
    else if ( fc.startsWith( "RTS" ) )
    {
      flowControl = SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT;
    }
    else
    {
      flowControl = SerialPort.FLOWCONTROL_NONE;
    }

    result.setSerialPortParams( baudrate, databits, stopbits, parity );
    result.setFlowControlMode( flowControl );
    result.enableReceiveTimeout( 100 );
    result.enableReceiveThreshold( 0 );

    result.notifyOnDataAvailable( true );
    result.addEventListener( new SerialPortEventListener()
    {
      @Override
      public void serialEvent( SerialPortEvent event )
      {
        if ( ( event.getEventType() & SerialPortEvent.DATA_AVAILABLE ) != 0 )
        {
          SerialPort port = ( SerialPort )event.getSource();

          try
          {
            InputStream is = port.getInputStream();

            Integer[] buf = new Integer[is.available()];
            for ( int i = 0; i < buf.length; i++ )
            {
              buf[i] = Integer.valueOf( is.read() );
View Full Code Here

TOP

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