本文整理汇总了Java中gnu.io.SerialPort.enableReceiveTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java SerialPort.enableReceiveTimeout方法的具体用法?Java SerialPort.enableReceiveTimeout怎么用?Java SerialPort.enableReceiveTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.io.SerialPort
的用法示例。
在下文中一共展示了SerialPort.enableReceiveTimeout方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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;
}
示例3: 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();
}
示例4: connect
import gnu.io.SerialPort; //导入方法依赖的package包/类
private void connect (String portName, int threshold) throws Exception
{
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if ( portIdentifier.isCurrentlyOwned() )
{
appender.append("Error: Port is currently in use");
}
else
{
//from RXTX examples
CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);
if (commPort instanceof SerialPort)
{
//set up serial port
serialPort = (SerialPort) commPort;
serialPort.enableReceiveTimeout(threshold);
serialPort.setSerialPortParams(115200,SerialPort.DATABITS_8,SerialPort.STOPBITS_2,SerialPort.PARITY_NONE);
//start async reader
sr = new SerialReader(serialPort, server);
serailThread = new Thread(sr);
serailThread.start();
}
else
{
appender.append("Error: Only serial ports are handled by this example.");
}
}
}
示例5: connect
import gnu.io.SerialPort; //导入方法依赖的package包/类
public void connect ( String portName, int threshold, int newLineAfter) throws Exception
{
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if ( portIdentifier.isCurrentlyOwned() )
{
System.out.println("Error: Port is currently in use");
}
else
{
CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);
if ( commPort instanceof SerialPort )
{
serialPort = (SerialPort) commPort;
serialPort.enableReceiveTimeout(threshold);
serialPort.setSerialPortParams(115200,SerialPort.DATABITS_8,SerialPort.STOPBITS_2,SerialPort.PARITY_NONE);
sr = new SerialReader(serialPort, newLineAfter, System.currentTimeMillis());
serialThread = new Thread(sr);
serialThread.start();
}
else
{
// arrayco
System.out.println("Error: Only serial ports are handled by this example.");
}
}
}