本文整理匯總了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.");
}
}
}