All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gnu.io.factory.RxTxPortCreator Maven / Gradle / Ivy

Go to download

A fork of the RXTX library with a focus on ease of use and embeddability in other libraries.

There is a newer version: 5.2.1
Show newest version
package gnu.io.factory;

import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import gnu.io.RXTXPort;
import gnu.io.UnsupportedCommOperationException;

public class RxTxPortCreator implements SerialPortCreator {

	@Override
	public boolean isApplicable(String portName, Class expectedClass) {
		return expectedClass.isAssignableFrom(RXTXPort.class);
	}

	@Override
	public RXTXPort createPort(String port) throws NoSuchPortException, UnsupportedCommOperationException, PortInUseException {
        RXTXPort comm = null;
        CommPortIdentifier ident = null;
        if ((System.getProperty("os.name").toLowerCase().indexOf("linux") != -1))
        {
            // if ( port.toLowerCase().contains("rfcomm".toLowerCase())||
            // port.toLowerCase().contains("ttyUSB".toLowerCase()) ||
            // port.toLowerCase().contains("ttyS".toLowerCase())||
            // port.toLowerCase().contains("ACM".toLowerCase()) ||
            // port.toLowerCase().contains("Neuron_Robotics".toLowerCase())||
            // port.toLowerCase().contains("DyIO".toLowerCase())||
            // port.toLowerCase().contains("NR".toLowerCase())||
            // port.toLowerCase().contains("FTDI".toLowerCase())||
            // port.toLowerCase().contains("ftdi".toLowerCase())
            // ){
            System.setProperty("gnu.io.rxtx.SerialPorts", port);
            // }
        }
        ident = CommPortIdentifier.getPortIdentifier(port);

        comm = ident.open("NRSerialPort", 2000);

        if (!(comm instanceof RXTXPort))
        {
            throw new UnsupportedCommOperationException("Non-serial connections are unsupported.");
        }
        comm.enableReceiveTimeout(100);
        return comm;

	}

	@Override
	public String getProtocol() {
		return LOCAL;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy