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);
}
}
java类gnu.io.UnsupportedCommOperationException的实例源码
SerialPortRTSPulseGenerator.java 文件源码
项目:ihmc-ethercat-master
阅读 21
收藏 0
点赞 0
评论 0
WirelessLCDSystem.java 文件源码
项目:EmbeddedMonitor
阅读 20
收藏 0
点赞 0
评论 0
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.");
}
}
}
Com.java 文件源码
项目:Gomoku
阅读 17
收藏 0
点赞 0
评论 0
public Com(String str, App a) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, TooManyListenersException{
this.app=a;
this.name=str;
CommPortIdentifier id=CommPortIdentifier.getPortIdentifier(str);
this.port = (SerialPort) id.open("Gomoku", timeout);
// this.port.setSerialPortParams(baudrate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
this.port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
this.listen();
}
App.java 文件源码
项目:Gomoku
阅读 61
收藏 0
点赞 0
评论 0
private void preparePort() throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, TooManyListenersException{
this.comPort=new Com(selectedCom, this);
this.status=AppStatus.READY;
this.menu.setVisible(false);
this.startGame.setVisible(true);
this.displayMessage("Procure um jogo clicando no botao abaixo ou aguarde um convite");
}
SerialPortConnection.java 文件源码
项目:xbee-api
阅读 22
收藏 0
点赞 0
评论 0
@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());
}
RFXComConnection.java 文件源码
项目:openhab-hdl
阅读 20
收藏 0
点赞 0
评论 0
private void connect() throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException, InterruptedException, ConfigurationException {
logger.info("Connecting to RFXCOM [serialPort='{}' ].",
new Object[] { serialPort });
connector.addEventListener(eventLister);
connector.connect(serialPort);
logger.debug("Reset controller");
connector.sendMessage(RFXComMessageFactory.CMD_RESET);
// controller does not response immediately after reset,
// so wait a while
Thread.sleep(1000);
if (setMode != null) {
try {
logger.debug("Set mode: {}",
DatatypeConverter.printHexBinary(setMode));
} catch (IllegalArgumentException e) {
throw new ConfigurationException("setMode", e.getMessage());
}
connector.sendMessage(setMode);
} else {
connector.sendMessage(RFXComMessageFactory.CMD_STATUS);
}
}
ModbusSerialTransport.java 文件源码
项目:openhab-hdl
阅读 17
收藏 0
点赞 0
评论 0
/**
* Describe <code>setReceiveThreshold</code> method here.
*
* @param th an <code>int</code> value
*/
public void setReceiveThreshold(int th) {
try {
m_CommPort.enableReceiveThreshold(th); /* chars */
} catch (UnsupportedCommOperationException e) {
logger.error("Failed to setReceiveThreshold: {}", e.getMessage());
}
}
ModbusSerialTransport.java 文件源码
项目:openhab-hdl
阅读 18
收藏 0
点赞 0
评论 0
/**
* Describe <code>setReceiveTimeout</code> method here.
*
* @param ms an <code>int</code> value
*/
public void setReceiveTimeout(int ms) {
try {
m_CommPort.enableReceiveTimeout(ms); /* milliseconds */
} catch (UnsupportedCommOperationException e) {
logger.error("Failed to setReceiveTimeout: {}", e.getMessage());
}
}
PrimareSerialConnector.java 文件源码
项目:openhab-hdl
阅读 16
收藏 0
点赞 0
评论 0
private void connectSerial() throws Exception {
logger.debug("Initializing serial port {}", serialPortName);
try {
CommPortIdentifier portIdentifier = CommPortIdentifier
.getPortIdentifier(serialPortName);
CommPort commPort = portIdentifier
.open(this.getClass().getName(), 2000);
serialPort = (SerialPort) commPort;
try {
serialPort.setSerialPortParams(4800, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.enableReceiveThreshold(1);
serialPort.disableReceiveTimeout();
} catch (UnsupportedCommOperationException unimportant) {
// We might have a perfectly usable PTY even if above operations are unsupported
};
inStream = new DataInputStream(serialPort.getInputStream());
outStream = serialPort.getOutputStream();
outStream.flush();
if (inStream.markSupported()) {
inStream.reset();
}
logger.debug("Starting DataListener for {}", PrimareSerialConnector.this.toString());
dataListener = new DataListener();
dataListener.start();
logger.debug("Starting DataListener for {}", PrimareSerialConnector.this.toString());
sendInitMessages();
} catch (NoSuchPortException e) {
logger.error("No such port: {}",serialPortName);
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
if (portList.hasMoreElements()) {
StringBuilder sb = new StringBuilder();
while(portList.hasMoreElements()){
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
sb.append(String.format("%s ",portId.getName()));
}
logger.error("The following communications ports are available: {}",
sb.toString().trim());
} else {
logger.error("There are no communications ports available");
}
logger.error("You may consider OpenHAB startup parameter [ -Dgnu.io.rxtx.SerialPorts={} ]",
serialPortName);
throw e;
}
}
SendingGenericSerialPort.java 文件源码
项目:harctoolboxbundle
阅读 22
收藏 0
点赞 0
评论 0
private void setupGenericSerialPort() throws IOException {
String newPort = this.genericSerialSenderBean.getPortName();
if (rawIrSender != null && (newPort == null || newPort.equals(portName)))
return;
if (rawIrSender != null)
rawIrSender.close();
rawIrSender = null;
//genericSerialSenderBean.setVerbose(properties.getVerbose());
close();
try {
rawIrSender = new IrGenericSerial(genericSerialSenderBean.getPortName(), genericSerialSenderBean.getBaud(),
genericSerialSenderBean.getDataSize(), genericSerialSenderBean.getStopBits(), genericSerialSenderBean.getParity(),
genericSerialSenderBean.getFlowControl(), properties.getSendingTimeout(), properties.getVerbose());
rawIrSender.setCommand(genericSerialSenderBean.getCommand());
rawIrSender.setRaw(genericSerialSenderBean.getRaw());
rawIrSender.setSeparator(genericSerialSenderBean.getSeparator());
rawIrSender.setUseSigns(genericSerialSenderBean.getUseSigns());
rawIrSender.setLineEnding(genericSerialSenderBean.getLineEnding());
} catch (NoSuchPortException | PortInUseException | UnsupportedCommOperationException | IOException ex) {
// Should not happen
guiUtils.error(ex);
}
portName = genericSerialSenderBean.getPortName();
genericSerialSenderBean.setHardware(rawIrSender);
}