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


Java SerialPort.setFlowControlMode方法代码示例

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


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

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

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

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

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

示例5: updatePortParameters

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * Initialize all port parameters DIALOG -> PORT
 */
public void updatePortParameters(SerialPort port)
{
	if (initialized && port != null)
	{
		try
		{
			port.setSerialPortParams(Integer.valueOf(cbBaudrate.getSelectedItem().toString()).intValue(),
				cbDataBits.getSelectedIndex() + 5,
				cbStopBits.getSelectedIndex() + 1,
				cbParity.getSelectedIndex());
			// flow control parameters
			int mode = 0;
			mode |= (cbProtocolRx.getSelectedIndex() == 1) ? SerialPort.FLOWCONTROL_RTSCTS_IN : (cbProtocolRx.getSelectedIndex() == 2) ? SerialPort.FLOWCONTROL_XONXOFF_IN : 0;
			mode |= (cbProtocolTx.getSelectedIndex() == 1) ? SerialPort.FLOWCONTROL_RTSCTS_OUT : (cbProtocolTx.getSelectedIndex() == 2) ? SerialPort.FLOWCONTROL_XONXOFF_OUT : 0;
			port.setFlowControlMode(mode);
		} catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
 
开发者ID:fr3ts0n,项目名称:AndrOBD,代码行数:25,代码来源:SerialConfigPanel.java

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

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

示例8: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
public void connect(String portname, int baudrate, char flowControl) throws Exception {
	Log.debug(this.getClass(), "connecting device "+portname+", "+baudrate+" baud");
       boolean isCommonPortname = portname.contains("ttyS") || portname.contains("COM");
	if ( ! isCommonPortname ) {
           System.setProperty("gnu.io.rxtx.SerialPorts", portname);
       }
	System.setProperty("gnu.io.rxtx.NoVersionOutput", "true");
	CommPortIdentifier commPortIdentifier = CommPortIdentifier.getPortIdentifier(portname);
	CommPort commPort = commPortIdentifier.open("tc65sh", 2000);
	serialPort = (SerialPort) commPort;
	serialPort.setSerialPortParams(baudrate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
	serialPort.enableReceiveTimeout(2000);
	if ( flowControl == FLOWCONTROL_NONE ) {
		serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
	} else if ( flowControl == FLOWCONTROL_RTSCTS) {
		serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_OUT | SerialPort.FLOWCONTROL_RTSCTS_IN);
	} else if ( flowControl == FLOWCONTROL_XONXOFF) {
		serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_XONXOFF_OUT | SerialPort.FLOWCONTROL_XONXOFF_IN);
	} else {
		throw new RuntimeException("invalid flowControl "+flowControl);
	}
	serialIn = serialPort.getInputStream();
	serialOut = serialPort.getOutputStream();
}
 
开发者ID:zhuravskiy,项目名称:tc65sh,代码行数:25,代码来源:Device.java

示例9: SerialTransport

import gnu.io.SerialPort; //导入方法依赖的package包/类
public SerialTransport(String serialPortName) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException
{
	CommPortIdentifier usablePort = CommPortIdentifier.getPortIdentifier(serialPortName);
	commPort = (SerialPort)usablePort.open("SerialTransport", 0);
	commPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
	commPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
	commPort.setDTR(true);
	commPort.setRTS(true);
	commPort.setEndOfInputChar((byte)0x0D);
}
 
开发者ID:cicavey,项目名称:jzwave,代码行数:11,代码来源:SerialTransport.java

示例10: SerialPortRTSPulseGenerator

import gnu.io.SerialPort; //导入方法依赖的package包/类
public SerialPortRTSPulseGenerator(String port)
{
   if ((System.getProperty("os.name").toLowerCase().indexOf("linux") != -1))
   {
      System.setProperty("gnu.io.rxtx.SerialPorts", port);
   }
   try
   {
      this.identifier = CommPortIdentifier.getPortIdentifier(port);
      CommPort commPort = identifier.open(getClass().getSimpleName(), OPEN_TIMEOUT); 
      if(commPort instanceof SerialPort)
      {
         serial = (SerialPort) commPort;
         serial.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
      }
      else
      {
         throw new IOException("Port is not a serial port");
      }
   }
   catch (NoSuchPortException | PortInUseException | IOException | UnsupportedCommOperationException e)
   {
      throw new RuntimeException(e);
   }
}
 
开发者ID:ihmcrobotics,项目名称:ihmc-ethercat-master,代码行数:26,代码来源:SerialPortRTSPulseGenerator.java

示例11: startRS232Com

import gnu.io.SerialPort; //导入方法依赖的package包/类
private void startRS232Com() throws NoSuchPortException,
        PortInUseException,
        UnsupportedCommOperationException,
        IOException,
        TooManyListenersException {
    // get the port identifer
    String portName = comListStr[comList.getSelectedIndex()];
    portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
    if (portIdentifier.isCurrentlyOwned()) {
        System.out.println("Error: Port is currently in use");
    } else {
        // Wait for 2ms when the COM is Busy
        String baudrate = baudrateListStr[baudrateList.getSelectedIndex()];
        CommPort comPort = portIdentifier.open(this.getClass().getName(), 2000);

        if (comPort instanceof SerialPort) {
            serialPort = (SerialPort) comPort;
            // set the notify on data available
            
            // serialPort.addEventListener(this);
            
            // use state machine here
            // so do not use the interrupt now
            // first time must open this notify
            
            //serialPort.notifyOnDataAvailable(true); 
            
            // set params
            serialPort.setSerialPortParams(
                    Integer.parseInt(baudrate),
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);
            // Do not use flow control
            serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);

            // set the out/in stream
            serialIn = serialPort.getInputStream();
            serialOut = serialPort.getOutputStream();
            
            // initialize the read thread here
            // do not need initialize the thread here
            // first time do not initialize this thread
            if(null == serialReadThread){
                serialReadThread = new Thread(new SerialReader(serialIn));
                // start the thread
                serialReadThread.start();
            }
            
        } else {
            System.out.println(
                    "Error: Only serial ports are handled by this example.");
        }
    }
}
 
开发者ID:smileboywtu,项目名称:EmbeddedMonitor,代码行数:56,代码来源:WirelessLCDSystem.java

示例12: open

import gnu.io.SerialPort; //导入方法依赖的package包/类
@Override
	public void open() {
		log.info("opening serial transport");
		String wantedPortName = "/dev/ttyUSB0";
//		String wantedPortName = "/dev/rfcomm1";
		System.setProperty("gnu.io.rxtx.SerialPorts", wantedPortName);
		Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();

		CommPortIdentifier portId = null;

		while (portIdentifiers.hasMoreElements()) {
			CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();
			log.info("pid {}", pid);
			if (pid.getPortType() == CommPortIdentifier.PORT_SERIAL &&
					pid.getName().equals(wantedPortName)) {
				portId = pid;
				break;
			}
		}

		if (portId == null) {
			return;
		}

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

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

			serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_XONXOFF_IN);
			serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_XONXOFF_OUT);

			// open the streams
			is = serialPort.getInputStream();
			os = serialPort.getOutputStream();

			// add event listeners
			serialPort.addEventListener(this);
			serialPort.notifyOnDataAvailable(false);
			log.info("serial transport opened");
		} catch (Exception e) {
			log.error("cannot connect to serial port", e);
		}
	}
 
开发者ID:devesion,项目名称:java-obd-adapter,代码行数:50,代码来源:SerialDiagnosticTransport.java

示例13: openSerialPort

import gnu.io.SerialPort; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void openSerialPort(String port, String appName, int timeout, int baudRate, int dataBits, int stopBits, int parity, int flowControl) throws PortInUseException, UnsupportedCommOperationException, TooManyListenersException, IOException, XBeeException {
	// Apparently you can't query for a specific port, but instead must iterate
	Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
	
	CommPortIdentifier portId = null;

	boolean found = false;
	
	while (portList.hasMoreElements()) {

		portId = portList.nextElement();

		if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {

			//log.debug("Found port: " + portId.getName());

			if (portId.getName().equals(port)) {
				//log.debug("Using Port: " + portId.getName());
				found = true;
				break;
			}
		}
	}

	if (!found) {
		throw new XBeeException("Could not find port: " + port);
	}
	
	serialPort = (SerialPort) portId.open(appName, timeout);
	
	serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
	serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);

	// activate the DATA_AVAILABLE notifier
	serialPort.notifyOnDataAvailable(true);
	
	// activate the OUTPUT_BUFFER_EMPTY notifier
	//serialPort.notifyOnOutputEmpty(true);
	
	serialPort.addEventListener(this);
	
	inputStream = serialPort.getInputStream();
	outputStream = new BufferedOutputStream(serialPort.getOutputStream());
}
 
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:46,代码来源:SerialPortConnection.java

示例14: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
void connect(String portName) throws NoSuchPortException, PortInUseException,
	UnsupportedCommOperationException, IOException{
	CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
	if (portIdentifier.isCurrentlyOwned()) {
		logger.warn("Error: Port is currently in use");
	} else {
		CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
		if (commPort instanceof SerialPort) {
			SerialPort serialPort = (SerialPort) commPort;
			serialPort.setSerialPortParams(1200, SerialPort.DATABITS_7, SerialPort.STOPBITS_2,
				SerialPort.PARITY_EVEN);
			serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN
				| SerialPort.FLOWCONTROL_RTSCTS_OUT);
			serialPort.setDTR(true);
			
			logger.debug("Opening connection to " + portName);
			logger.debug("BaudRate: " + serialPort.getBaudRate());
			logger.debug("STPB/DTB/PAR: " + serialPort.getStopBits() + " "
				+ serialPort.getDataBits() + " " + serialPort.getParity());
			logger.debug("FCM: " + serialPort.getFlowControlMode() + " should be: "
				+ (SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT));
			logger.debug("CTS/CD/DTR/DSR/RTS: " + serialPort.isCTS() + " " + serialPort.isCD()
				+ " " + serialPort.isDTR() + " " + serialPort.isDSR() + " "
				+ serialPort.isRTS());
			
			InputStream in = serialPort.getInputStream();
			//OutputStream out = serialPort.getOutputStream();
			
			reader = new CobasMiraSerialReader(in, serialPort);
			cobasMiraReader = new Thread(reader);
			cobasMiraReader.start();
			logger.debug("Reader Thread ID: " + cobasMiraReader.getId() + " Priority: "
				+ cobasMiraReader.getPriority() + " Name: " + cobasMiraReader.getName());
			
			//serialPort.setDTR(true);
			//(new Thread(new SerialWriter(out))).start();
		} else {
			logger.warn("Error: Only serial ports are handled by this example.");
		}
	}
}
 
开发者ID:elexis,项目名称:elexis-3-base,代码行数:42,代码来源:CobasMiraConnection.java

示例15: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
public void connect() throws Exception {
    System.out.println("\rConnecting to serial port...");
    System.out.print("#:");
    CommPortIdentifier mCommPortIdentifier = CommPortIdentifier.getPortIdentifier(mDeviceUri);
    if (mCommPortIdentifier.isCurrentlyOwned()) {
        System.err.println("\rError: Port currently in use");
        System.out.print("#:");
    } else {
        CommPort mCommPort = mCommPortIdentifier.open(this.getClass().getName(), 2000);
        if(mCommPort instanceof SerialPort) {
            mSerialPort = (SerialPort) mCommPort;
            mSerialPort.setSerialPortParams(mBaudRate,
                                            SerialPort.DATABITS_8,
                                            SerialPort.STOPBITS_1,
                                            SerialPort.PARITY_NONE);
            mSerialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);

            mOutputStream = mSerialPort.getOutputStream();
            mInputStream  = mSerialPort.getInputStream();
            mReaderTask = new SerialReader(mInputStream, mListener);
            (new Thread(mReaderTask)).start();

            Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        disconnect();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }));
            System.out.println("\rSerial port connected");
            System.out.print("#:");
        } else {
            System.err.println("\rError: Only serial ports are handled");
            System.out.print("#:");
        }
    }
}
 
开发者ID:BOSSoNe0013,项目名称:NeoJava,代码行数:41,代码来源:Serial.java


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