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


Java SerialPort.notifyOnDataAvailable方法代码示例

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


在下文中一共展示了SerialPort.notifyOnDataAvailable方法的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: 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

示例3: removeListener

import gnu.io.SerialPort; //导入方法依赖的package包/类
private void removeListener(SerialPort port) {
	
	port.notifyOnRingIndicator( false );
	port.notifyOnParityError( false );
	port.notifyOnOverrunError( false );
	port.notifyOnOutputEmpty( false );
	port.notifyOnFramingError( false );
	port.notifyOnDSR( false );
	port.notifyOnDataAvailable( false );
	port.notifyOnCTS( false );
	port.notifyOnCarrierDetect( false );
	port.notifyOnBreakInterrupt( false );
	
	port.removeEventListener();

}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:17,代码来源:RxtxCommands.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: 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

示例9: getPort

import gnu.io.SerialPort; //导入方法依赖的package包/类
public static FMilaSerialPort getPort(int speed, String port) throws IOException {
  SerialPort serialPort;

  try {

    CommPortIdentifier comm = CommPortIdentifier.getPortIdentifier(port);
    if (comm.isCurrentlyOwned()) {
      throw new IOException("StationInUseError");
    }
    serialPort = comm.open("4mila", 2000);

    serialPort.setSerialPortParams(speed, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
    serialPort.disableReceiveTimeout();
    serialPort.disableReceiveFraming();
    serialPort.disableReceiveThreshold();
    serialPort.notifyOnDataAvailable(true);
    serialPort.notifyOnOutputEmpty(true);
  }
  catch (PortInUseException | UnsupportedCommOperationException | NoSuchPortException e) {
    throw new IOException(e.getMessage(), e);
  }

  return new RXTXSerialPort(serialPort);
}
 
开发者ID:innovad,项目名称:4mila-1.0,代码行数:26,代码来源:RXTXUtility.java

示例10: 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

示例11: openSerial

import gnu.io.SerialPort; //导入方法依赖的package包/类
public void openSerial(String serialPortName, int speed) throws PortInUseException, IOException, UnsupportedCommOperationException, TooManyListenersException {
	
	CommPortIdentifier commPortIdentifier = findPort(serialPortName);
	
	// initalize serial port
	serialPort = (SerialPort) commPortIdentifier.open("Arduino", 2000);
	inputStream = serialPort.getInputStream();
	serialPort.addEventListener(this);

	// activate the DATA_AVAILABLE notifier
	serialPort.notifyOnDataAvailable(true);

	serialPort.setSerialPortParams(speed, SerialPort.DATABITS_8, 
			SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
	serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
}
 
开发者ID:andrewrapp,项目名称:arduino-remote-uploader,代码行数:17,代码来源:SerialSketchUploader.java

示例12: oeffneSerialPort

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * Versucht den seriellen Port zu �ffnen. Klappt nur, wenn er noch nicht von einer anderen Anwendung benutzt wird. Der jeweilige
 * Port wird mit �bergeben. UNter Windows ist die Schreibweise "COM8" zum Beispeil unter Linux "dev/tts0"
 * @param portName
 * @return
 * @throws PortInUseException
 * @throws IOException
 * @throws UnsupportedCommOperationException
 */
public boolean oeffneSerialPort(String portName) throws PortInUseException, IOException, UnsupportedCommOperationException
{
	Boolean foundPort = false;
	if (serialPortGeoeffnet != false) {
		System.out.println("Serialport bereits ge�ffnet");
		schliesseSerialPort();
		return false;
	}
	System.out.println("�ffne Serialport");
	enumComm = CommPortIdentifier.getPortIdentifiers();
	while(enumComm.hasMoreElements()) {
		serialPortId = (CommPortIdentifier) enumComm.nextElement();
		System.out.println("SerialportIDs:" + serialPortId.getName());
		if (portName.contentEquals(serialPortId.getName())) {
			foundPort = true;
			break;
		}
	}
	if (foundPort != true) {
		System.out.println("Serialport nicht gefunden: " + portName);
		return false;
	}
	    serialPort = (SerialPort) serialPortId.open("�ffnen und Senden", 500);
		outputStream = serialPort.getOutputStream();
		inputStream = serialPort.getInputStream();
	
	serialPort.notifyOnDataAvailable(true);
		serialPort.setSerialPortParams(baudrate, dataBits, stopBits, parity);
	
	
	serialPortGeoeffnet = true;
	return true;
}
 
开发者ID:SecUSo,项目名称:EasyVote,代码行数:43,代码来源:VCDSerialPort.java

示例13: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
public void connect(CommPortIdentifier portId) throws Exception {
    serialPort = (SerialPort) portId.open(getClass().getName(), TIME_OUT);

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

    output = serialPort.getOutputStream();
    input = serialPort.getInputStream();

    serialPort.notifyOnDataAvailable(false);
}
 
开发者ID:Chatanga,项目名称:Girinoscope,代码行数:12,代码来源:Serial.java

示例14: initialize

import gnu.io.SerialPort; //导入方法依赖的package包/类
public void initialize(testEngine tee) {
	te=tee;
    CommPortIdentifier portId = null;
    Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
    // iterate through, looking for the port
    while (portEnum.hasMoreElements()) {
        CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
        for (String portName : PORT_NAMES) {
            if (currPortId.getName().equals(portName)) {
                portId = currPortId;
                break;
            }
        }
    }
    if (portId == null) {
        te.log("Could not find COM port.");
        return;
    }else{
        te.log("Found your Port");
    }
    try {
        // open serial port, and use class name for the appName.
        serialPort = (SerialPort) portId.open(this.getClass().getName(),TIME_OUT);
        // set port parameters
        serialPort.setSerialPortParams(DATA_RATE,
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
        // open the streams
        input = serialPort.getInputStream();
        output = serialPort.getOutputStream();
        // add event listeners
        serialPort.addEventListener(this);
        serialPort.notifyOnDataAvailable(true);
    } catch (Exception e) {
        System.err.println(e.toString());
    }
}
 
开发者ID:agbishara,项目名称:V2R,代码行数:39,代码来源:comm.java

示例15: initialize

import gnu.io.SerialPort; //导入方法依赖的package包/类
public void initialize(ISerialListener inListener) {
	_listener = inListener;
	
	mapCommPorts();
	
	CommPortIdentifier portId = null;
	if(_commPorts.containsKey(PORT_NAMES[0]))
	{
		portId = _commPorts.get(PORT_NAMES[0]);
		System.out.println("found port: " + PORT_NAMES[0]);
	}
	if (portId == null) {
		System.out.println("Could not find selected COM port: " + PORT_NAMES[0]);
		return;
	}

	try {
		// open serial port, and use class name for the appName.
		serialPort = (SerialPort) portId.open(this.getClass().getName(),
				TIME_OUT);

		// set port parameters
		serialPort.setSerialPortParams(DATA_RATE, SerialPort.DATABITS_8,
				SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

		// open the streams
		input = new BufferedReader(new InputStreamReader(
				serialPort.getInputStream()));
		output = serialPort.getOutputStream();
		char ch = 1;
		output.write(ch);

		// add event listeners
		serialPort.addEventListener(this);
		serialPort.notifyOnDataAvailable(true);
	} catch (Exception e) {
		System.err.println(e.toString());
	}
}
 
开发者ID:ValleyForgeTech,项目名称:2014-03-26_GardenMonitorStation,代码行数:40,代码来源:SerialUtility.java


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