当前位置: 首页>>代码示例>>Java>>正文


Java SerialPort.getInputStream方法代码示例

本文整理汇总了Java中gnu.io.SerialPort.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java SerialPort.getInputStream方法的具体用法?Java SerialPort.getInputStream怎么用?Java SerialPort.getInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gnu.io.SerialPort的用法示例。


在下文中一共展示了SerialPort.getInputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import gnu.io.SerialPort; //导入方法依赖的package包/类
public void initialize() {
        System.setProperty("gnu.io.rxtx.SerialPorts", getComPortName());        
        CommPortIdentifier portId = null;        
        Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
        
        while (portEnum.hasMoreElements()) {
            CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
            if(currPortId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                if (currPortId.getName().equals(txtComPortName.getText())) {
                    System.out.println(txtComPortName.getText());
                    portId = currPortId;
                    break;
                }
            }
        }
        if (portId == null) {
            
            JOptionPane.showMessageDialog(null," Portuna bağlı cihaz yok!","Hata",JOptionPane.ERROR_MESSAGE);
            System.out.println("Porta bağlı cihaz yok!");
            return;
        }
System.out.println(portId);
        try {
            serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT);

            serialPort.setSerialPortParams(DATA_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);

            input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
            output = serialPort.getOutputStream();

            serialPort.addEventListener((SerialPortEventListener) this);
           serialPort.notifyOnDataAvailable(true);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
 
开发者ID:altnokburcu,项目名称:uyariSistemi,代码行数:38,代码来源:UI_uyari.java

示例2: SerialComm

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * Constructor
 * 
 * @param portName
 *            The name of the serial port
 * @param listeners
 *            The listeners for incoming telegrams
 * @throws Exception
 */
public SerialComm(String portName, ArrayList<EnoceanListener> listeners)
		throws Exception {
	this.listeners = listeners;
	CommPortIdentifier portIdentifier = CommPortIdentifier
			.getPortIdentifier(portName);
	if (portIdentifier.isCurrentlyOwned()) {
		throw new Exception("Port is currently in use");
	}

	CommPort commPort = portIdentifier
			.open(this.getClass().getName(), 2000); // timeout 2 s.
	if (!(commPort instanceof SerialPort)) {
		throw new Exception("Only serial port is supported");
	}
	port = commPort;

	SerialPort serialPort = (SerialPort) commPort;

	// 57600 bit/s, 8 bits, stop bit length 1, no parity bit
	serialPort.setSerialPortParams(57600, SerialPort.DATABITS_8,
			SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
	input = serialPort.getInputStream();
	output = serialPort.getOutputStream();
}
 
开发者ID:heia-fr,项目名称:wot_gateways,代码行数:34,代码来源:SerialComm.java

示例3: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public void connect() throws EpsonProjectorException {

	try {
		logger.debug("Open connection to serial port '{}'", serialPortName);
		CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);

		CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);

		serialPort = (SerialPort) commPort;
		serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
				SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
		serialPort.enableReceiveThreshold(1);
		serialPort.disableReceiveTimeout();

		in = serialPort.getInputStream();
		out = serialPort.getOutputStream();

		out.flush();
		if (in.markSupported()) {
			in.reset();
		}
		
		// RXTX serial port library causes high CPU load
		// Start event listener, which will just sleep and slow down event loop
		serialPort.addEventListener(this);
		serialPort.notifyOnDataAvailable(true);
	} catch (Exception e) {
		throw new EpsonProjectorException(e);
	}

}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:35,代码来源:EpsonProjectorSerialConnector.java

示例4: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
void connect(String destination) throws Exception {
    CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(destination);
    if (portIdentifier.isCurrentlyOwned()) {
        log.warning("Error: Port for Dynamixel-Communication is currently in use");
    } else {
        CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
        if (commPort instanceof SerialPort) {
            SerialPort serialPort = (SerialPort) commPort;
            serialPort.setSerialPortParams(57600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
            in = serialPort.getInputStream();
            out = serialPort.getOutputStream();
            serialReader = new SerialReader(in);
            serialPort.addEventListener(serialReader);
            serialPort.notifyOnDataAvailable(true);
            connected = true;
            log.info("Connected to Dynamixel!");
        } else {
            log.warning("Error: Cannot connect to Dynamixel!");
        }

    }
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:23,代码来源:PanTiltControlDynamixel.java

示例5: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
void connect(String destination) throws Exception {
    CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(destination);
    if (portIdentifier.isCurrentlyOwned()) {
        log.warning("Error: Port for Pan-Tilt-Communication is currently in use");
    } else {
        CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
        if (commPort instanceof SerialPort) {
            SerialPort serialPort = (SerialPort) commPort;
            serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
            in = serialPort.getInputStream();
            out = serialPort.getOutputStream();
            serialPort.addEventListener(new SerialReader(in));
            serialPort.notifyOnDataAvailable(true);
            connected = true;
            log.info("Connected to Pan-Tilt-Unit!");
        } else {
            log.warning("Error: Cannot connect to Pan-Tilt-Unit!");
        }
    }
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:21,代码来源:PanTiltControlPTU.java

示例6: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
void connect(String destination) throws Exception {
    CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(destination);
    if (portIdentifier.isCurrentlyOwned()) {
        log.warning("Error: Port for Dynamixel-Communication is currently in use");
    } else {
        CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
        if (commPort instanceof SerialPort) {
            SerialPort serialPort = (SerialPort) commPort;
            serialPort.setSerialPortParams(57142, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
            in = serialPort.getInputStream();
            out = serialPort.getOutputStream();
            serialPort.addEventListener(new SerialReader(in));
            serialPort.notifyOnDataAvailable(true);
            log.info("Connected to Dynamixel!");
        } else {
            log.warning("Error: Cannot connect to Dynamixel!");
        }
    }
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:20,代码来源:DynamixelControl.java

示例7: openPort

import gnu.io.SerialPort; //导入方法依赖的package包/类
private void openPort() {
        appendString("opening " + portName + "...");
        try {

            CommPortIdentifier cpi = CommPortIdentifier.getPortIdentifier(portName);
            port = (SerialPort) cpi.open(portName, 1000);

            port.setSerialPortParams(
                    Integer.parseInt(baudText.getText()),
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);
//            port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
            port.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN
                    | SerialPort.FLOWCONTROL_RTSCTS_OUT);
            port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
            port.addEventListener(this);
            port.notifyOnDataAvailable(true);
            port.notifyOnCTS(true);

            isr = new InputStreamReader(port.getInputStream());
            os = port.getOutputStream();

        } catch (Exception e) {
            log.warning(e.toString());
            appendString(e.toString());
        } finally {

            updateFlags();
            appendString("done.\n");
        }
    }
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:33,代码来源:HyperTerminal.java

示例8: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
/** Method to connect to an available port */
@SuppressWarnings("static-access")
private void connect(String portName) throws Exception {
	CommPortIdentifier commPortIdentifier = CommPortIdentifier.getPortIdentifier(portName);

	if (commPortIdentifier.isCurrentlyOwned()) {
		System.out.println("Error: Port is currently in use");
	} else {
		CommPort commPort = commPortIdentifier.open(this.getClass().getName(), 2000);

		if (commPort instanceof SerialPort) {
			SerialPort serialPort = (SerialPort) commPort;
			serialPort.setSerialPortParams(References.BAUDRATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
					SerialPort.PARITY_NONE);

			this.inputStream = serialPort.getInputStream();
			this.outputStream = serialPort.getOutputStream();

			References.SERIAL_READER = new SerialReader(this.inputStream);
			readThread = new Thread(References.SERIAL_READER);
			readThread.start();
		} else {
			System.out.println("Error: Only serial ports allowed");
		}
	}
}
 
开发者ID:AitorB,项目名称:POPBL_V,代码行数:27,代码来源:SerialManagement.java

示例9: open

import gnu.io.SerialPort; //导入方法依赖的package包/类
@Override
public void open() {
	try{
		CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
        if (portIdentifier.isCurrentlyOwned())
            System.out.println("Error: Port is currently in use");
        else {
            CommPort port = portIdentifier.open(this.getClass().getName(), getTimeout());//for now class name
            
            if (port instanceof SerialPort){
            	serial = (SerialPort) port;
            	serial.setSerialPortParams(baudrate, SerialPort.DATABITS_8 
                		, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                
            	serial.enableReceiveTimeout(timeout);
            	
                this.in = serial.getInputStream();
                this.out = serial.getOutputStream();
                isOpened = true;
            }
            else
                System.out.println("Error: Only serial ports are handled");
        }   
	}
	catch (PortInUseException | UnsupportedCommOperationException | NoSuchPortException | IOException e) {
		if(serial != null)
			serial.close();
		serial = null;
		e.printStackTrace();
	}
}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:32,代码来源:RXTXCommInterface.java

示例10: RpLidarLowLevelDriver

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * Initializes serial connection
 *
 * @param portName Path to serial port
 * @param listener Listener for in comming packets
 * @throws Exception
 */
public RpLidarLowLevelDriver(final String portName, final RpLidarListener listener) throws Exception {

	log.info("Opening port " + portName);

	this.listener = listener;

	//Configuration for Serial port operations
	final CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
	final CommPort commPort = portIdentifier.open("FOO", 2000);
	serialPort = (SerialPort) commPort;
	serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
	serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
	serialPort.setDTR(false); // lovely undocumented feature where if true the motor stops spinning

	in = serialPort.getInputStream();
	out = serialPort.getOutputStream();

	readThread = new ReadSerialThread();
	new Thread(readThread).start();
}
 
开发者ID:ev3dev-lang-java,项目名称:RPLidar4J,代码行数:28,代码来源:RpLidarLowLevelDriver.java

示例11: open

import gnu.io.SerialPort; //导入方法依赖的package包/类
public void open() throws PortInUseException, UnsupportedCommOperationException, TooManyListenersException, IOException
{
	if (open)
	{
		log.info(commId.getName() + " already open, skipping");
		return;
	}

	log.info("Opening port " + commId.getName());
	buffer = new ByteBuffer();

	port = (SerialPort)commId.open("TimerInterface-"+commId.getName(), 30000);
	port.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
	port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);

	port.addEventListener(this);
	port.notifyOnDataAvailable(true);
	port.enableReceiveTimeout(30);

	os = port.getOutputStream();
	is = port.getInputStream();
	open = true;
   }
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:24,代码来源:SerialDataInterface.java

示例12: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
public void connect(String portName) throws Exception {
	CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
	LOG.info("Found the " + portName + " port.");
	if (portIdentifier.isCurrentlyOwned()) {
		LOG.error("Port is currently in use");
	} else {
		CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
		LOG.info("Opened port " + portName);

		if (commPort instanceof SerialPort) {
			SerialPort serialPort = (SerialPort) commPort;
			serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.PARITY_EVEN, SerialPort.FLOWCONTROL_NONE);

			printWriter = new PrintWriter(serialPort.getOutputStream());
			bufferedReader = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));

               // For skipping AnA string
               skipInput();

		} else {
			LOG.error("Only serial ports are handled by this example.");
		}
	}
}
 
开发者ID:AoLab,项目名称:JLamp,代码行数:25,代码来源:Serial.java

示例13: newLink

import gnu.io.SerialPort; //导入方法依赖的package包/类
@Override
public LinkDelegate newLink(SerialLinkConfig config)
		throws NoSuchPortException, PortInUseException,
		UnsupportedCommOperationException, IOException {
	CommPortIdentifier portIdentifier = CommPortIdentifier
			.getPortIdentifier(config.getPort());
	checkState(!portIdentifier.isCurrentlyOwned(),
			"Port %s is currently in use", config.getPort());
	final SerialPort serialPort = serialPort(config, portIdentifier);

	StreamConnection connection = new StreamConnection(
			serialPort.getInputStream(), serialPort.getOutputStream(),
			config.getProto());

	ConnectionBasedLink connectionBasedLink = new ConnectionBasedLink(
			connection, config.getProto());
	@SuppressWarnings("resource")
	Link link = config.isQos() ? new QosLink(connectionBasedLink)
			: connectionBasedLink;

	waitForArdulink(config, connectionBasedLink);
	return new LinkDelegate(link) {
		@Override
		public void close() throws IOException {
			super.close();
			serialPort.close();
		}
	};
}
 
开发者ID:Ardulink,项目名称:Ardulink-2,代码行数:30,代码来源:SerialLinkFactory.java

示例14: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
private void connect(String portName) throws Exception {
    CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
    if (portIdentifier.isCurrentlyOwned())
        throw new PortInUseException();

    CommPort commPort = portIdentifier.open(this.getClass().getName(), COMPORT_PORT);

    if (commPort instanceof SerialPort) {
        SerialPort serialPort = (SerialPort) commPort;
        serialPort.setSerialPortParams(BAUD_RATE, 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();

    } else {
        throw new PortUnreachableException("ERROR - Only serial ports are handled by this class");
    }

}
 
开发者ID:BenjiTrapp,项目名称:GPSSimulator,代码行数:23,代码来源:TwoWaySerialComm.java

示例15: handleEvent

import gnu.io.SerialPort; //导入方法依赖的package包/类
public void handleEvent() {
	try {
		CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(SerialConf.WINDOWS_PORT);
		
		if (portId.isCurrentlyOwned()) {
			System.out.println("Port busy!");
		} else {
			CommPort commPort = portId.open("whatever it's name", SerialConf.TIME_OUT);
			if (commPort instanceof SerialPort) {
				serialPort = (SerialPort) commPort;
				serialPort.setSerialPortParams(SerialConf.BAUD, 
												SerialPort.DATABITS_8, 
												SerialPort.STOPBITS_1, 
												SerialPort.PARITY_EVEN);
				in = serialPort.getInputStream();
				serialPort.notifyOnDataAvailable(true);
				serialPort.addEventListener(this);
			} else {
				commPort.close();
				System.out.println("the port is not serial!");
			}
		}
	} catch (Exception e) {
		serialPort.close();
		System.out.println("Error: SerialOpen!!!");
		e.printStackTrace();
	}
}
 
开发者ID:lishiyun19,项目名称:Serial,代码行数:29,代码来源:SerialEvent.java


注:本文中的gnu.io.SerialPort.getInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。