gnu.io.UnsupportedCommOperationException Java Examples
The following examples show how to use
gnu.io.UnsupportedCommOperationException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SerialSketchUploader.java From arduino-remote-uploader with GNU General Public License v2.0 | 8 votes |
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); }
Example #2
Source File: RFXComSerialConnector.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
@Override public void connect(String device) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException { CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(device); CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000); serialPort = (SerialPort) commPort; serialPort.setSerialPortParams(38400, 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(); } readerThread = new SerialReader(in); readerThread.start(); }
Example #3
Source File: RFXComConnection.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
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); // Clear received buffers connector.clearReceiveBuffer(); 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); } }
Example #4
Source File: SerialRXTXComm.java From meshnet with GNU General Public License v3.0 | 5 votes |
public SerialRXTXComm(CommPortIdentifier portIdentifier, Layer3Base layer3) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException, TooManyListenersException{ if (portIdentifier.isCurrentlyOwned()) { throw new IOException("Port is currently in use"); } else { CommPort commPort = portIdentifier.open(this.getClass().getName(), TIME_OUT); if (commPort instanceof SerialPort) { SerialPort serialPort = (SerialPort) commPort; serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); inStream = serialPort.getInputStream(); outStream = serialPort.getOutputStream(); new SerialReceiver().start(); /*serialPort.addEventListener(this); serialPort.notifyOnDataAvailable(true);*/ } else { throw new IOException("This is not a serial port!."); } } this.layer2 = new Layer2Serial(this, layer3); }
Example #5
Source File: SerialConnector.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * {@inheritDoc} **/ public void open() { try { CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName); CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000); serialPort = (SerialPort) commPort; serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.enableReceiveThreshold(1); serialPort.disableReceiveTimeout(); serialOutput = new OutputStreamWriter(serialPort.getOutputStream(), "US-ASCII"); serialInput = new BufferedReader(new InputStreamReader(serialPort.getInputStream())); setSerialEventHandler(this); connected = true; } catch (NoSuchPortException noSuchPortException) { logger.error("open(): No Such Port Exception: ", noSuchPortException); connected = false; } catch (PortInUseException portInUseException) { logger.error("open(): Port in Use Exception: ", portInUseException); connected = false; } catch (UnsupportedCommOperationException unsupportedCommOperationException) { logger.error("open(): Unsupported Comm Operation Exception: ", unsupportedCommOperationException); connected = false; } catch (UnsupportedEncodingException unsupportedEncodingException) { logger.error("open(): Unsupported Encoding Exception: ", unsupportedEncodingException); connected = false; } catch (IOException ioException) { logger.error("open(): IO Exception: ", ioException); connected = false; } }
Example #6
Source File: ModbusSerialTransport.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * 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()); } }
Example #7
Source File: ModbusSerialTransport.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * 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()); } }
Example #8
Source File: SerialConnection.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
public void setReceiveTimeout(int ms) { // Set receive timeout to allow breaking out of polling loop during // input handling. try { m_SerialPort.enableReceiveTimeout(ms); } catch (UnsupportedCommOperationException e) { logger.error("Failed to set receive timeout: {}", e.getMessage()); } }
Example #9
Source File: SerialFatekConnectionFactory.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
@Override public FatekConnection getConnection(FatekConfig fatekConfig) throws IOException { try { return new Connection(fatekConfig); } catch (PortInUseException | UnsupportedCommOperationException e) { throw new IOException(e); } }
Example #10
Source File: SerialFatekConnectionFactory.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
Connection(FatekConfig fatekConfig) throws IOException, PortInUseException, UnsupportedCommOperationException { super(fatekConfig); final CommPortIdentifier commPortIdentifier = findComPort(); serialPort = commPortIdentifier.open("openHAB-FatekPLC", 2000); serialPort.setSerialPortParams(getBaud(), getDataBits(), getStopBits(), getParity()); serialPort.enableReceiveTimeout(getTimeout()); logger.info("New connection to: {} opened", serialPort.getName()); }
Example #11
Source File: SerialPortManager.java From SerialPortDemo with Apache License 2.0 | 5 votes |
/** * 打开串口 * * @param portName * 端口名称 * @param baudrate * 波特率 * @return 串口对象 * @throws PortInUseException * 串口已被占用 */ public static final SerialPort openPort(String portName, int baudrate) throws PortInUseException { try { // 通过端口名识别端口 CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName); // 打开端口,并给端口名字和一个timeout(打开操作的超时时间) CommPort commPort = portIdentifier.open(portName, 2000); // 判断是不是串口 if (commPort instanceof SerialPort) { SerialPort serialPort = (SerialPort) commPort; try { // 设置一下串口的波特率等参数 // 数据位:8 // 停止位:1 // 校验位:None serialPort.setSerialPortParams(baudrate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); } catch (UnsupportedCommOperationException e) { e.printStackTrace(); } return serialPort; } } catch (NoSuchPortException e1) { e1.printStackTrace(); } return null; }
Example #12
Source File: SerialPortConnector.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Sets the serial port parameters to xxxxbps-8N1 * * @param baudrate * used to initialize the serial connection */ protected void setSerialPortParameters(int baudrate) throws IOException { try { // Set serial port to xxxbps-8N1 serialPort.setSerialPortParams(baudrate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); } catch (UnsupportedCommOperationException ex) { throw new IOException("Unsupported serial port parameter for serial port"); } }
Example #13
Source File: SerialPortRxTx.java From xbee-java with Mozilla Public License 2.0 | 5 votes |
@Override public void setPortParameters(int baudRate, int dataBits, int stopBits, int parity, int flowControl) throws InvalidConfigurationException, ConnectionException { parameters = new SerialPortParameters(baudRate, dataBits, stopBits, parity, flowControl); if (serialPort != null) { try { serialPort.setSerialPortParams(baudRate, dataBits, stopBits, parity); serialPort.setFlowControlMode(flowControl); } catch (UnsupportedCommOperationException e) { throw new InvalidConfigurationException(e.getMessage(), e); } } }
Example #14
Source File: NordicSketchUploader.java From arduino-remote-uploader with GNU General Public License v2.0 | 5 votes |
private void runFromCmdLine(String[] args) throws org.apache.commons.cli.ParseException, IOException, PortInUseException, UnsupportedCommOperationException, TooManyListenersException, StartOverException { CliOptions cliOptions = getCliOptions(); cliOptions.addOption( OptionBuilder .withLongOpt(serialPort) .hasArg() .isRequired(true) .withDescription("Serial port of of Arduino running NordicSPI2Serial sketch (e.g. /dev/tty.usbserial-A6005uRz). Required") .create("p")); cliOptions.addOption( OptionBuilder .withLongOpt(baudRate) .hasArg() .isRequired(true) .withType(Number.class) .withDescription("Baud rate of Arduino. Required") .create("b")); cliOptions.build(); CommandLine commandLine = cliOptions.parse(args); if (commandLine != null) { new NordicSketchUploader().flash( commandLine.getOptionValue(CliOptions.sketch), commandLine.getOptionValue(serialPort), cliOptions.getIntegerOption(baudRate), commandLine.hasOption(CliOptions.verboseArg), cliOptions.getIntegerOption(CliOptions.ackTimeoutMillisArg), cliOptions.getIntegerOption(CliOptions.arduinoTimeoutArg), cliOptions.getIntegerOption(CliOptions.retriesPerPacketArg), cliOptions.getIntegerOption(CliOptions.delayBetweenRetriesMillisArg)); } }
Example #15
Source File: NordicSketchUploader.java From arduino-remote-uploader with GNU General Public License v2.0 | 5 votes |
public void flash(String file, String device, int speed, boolean verbose, int ackTimeout, int arduinoTimeout, int retriesPerPacket, int delayBetweenRetriesMillis) throws IOException, PortInUseException, UnsupportedCommOperationException, TooManyListenersException, StartOverException { Map<String,Object> context = Maps.newHashMap(); context.put("device", device); context.put("speed", speed); // determine max data we can send with each programming packet int pageSize = NORDIC_PACKET_SIZE - getProgramPageHeader(0, 0).length; super.process(file, pageSize, ackTimeout, arduinoTimeout, retriesPerPacket, delayBetweenRetriesMillis, verbose, context); }
Example #16
Source File: SendingGenericSerialPort.java From IrScrutinizer with GNU General Public License v3.0 | 5 votes |
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); }
Example #17
Source File: SerialLinkFactory.java From Ardulink-2 with Apache License 2.0 | 5 votes |
@Override public LinkDelegate newLink(SerialLinkConfig config) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException { CommPortIdentifier portIdentifier = CommPortIdentifier .getPortIdentifier(config.getPort()); checkState(!portIdentifier.isCurrentlyOwned(), "Port %s is currently in use", config.getPort()); final SerialPort serialPort = serialPort(config, portIdentifier); StreamConnection connection = new StreamConnection( serialPort.getInputStream(), serialPort.getOutputStream(), config.getProto()); ConnectionBasedLink connectionBasedLink = new ConnectionBasedLink( connection, config.getProto()); Link link = config.isQos() ? new QosLink(connectionBasedLink) : connectionBasedLink; waitForArdulink(config, connectionBasedLink); return new LinkDelegate(link) { @Override public void close() throws IOException { super.close(); serialPort.close(); } }; }
Example #18
Source File: DSMRPort.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * Opens the Operation System Serial Port * <p> * This method opens the port and set Serial Port parameters according to * the DSMR specification. Since the specification is clear about these * parameters there are not configurable. * <p> * If there are problem while opening the port, it is the responsibility of * the calling method to handle this situation (and for example close the * port again). * <p> * Opening an already open port is harmless. The method will return * immediately * * @return true if opening was successful (or port was already open), false * otherwise */ private boolean open() { synchronized (portLock) { // Sanity check if (portState != PortState.CLOSED) { return true; } try { // GNU.io autodetects standard serial port names // Add non standard port names if not exists (fixes part of #4175) if (!portExists(portName)) { logger.warn("Port {} does not exists according to the system, we will still try to open it", portName); } // Opening Operating System Serial Port logger.debug("Creating CommPortIdentifier"); CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName); logger.debug("Opening CommPortIdentifier"); CommPort commPort = portIdentifier.open("org.openhab.binding.dsmr", readTimeoutMSec); logger.debug("Configure serial port"); serialPort = (SerialPort) commPort; serialPort.enableReceiveThreshold(1); serialPort.enableReceiveTimeout(readTimeoutMSec); // Configure Serial Port based on specified port speed logger.debug("Configure serial port parameters: {}", portSettings); if (portSettings != null) { serialPort.setSerialPortParams(portSettings.getBaudrate(), portSettings.getDataBits(), portSettings.getStopbits(), portSettings.getParity()); /* special settings for low speed port (checking reference here) */ if (portSettings == DSMRPortSettings.LOW_SPEED_SETTINGS) { serialPort.setDTR(false); serialPort.setRTS(true); } } else { logger.error("Invalid port parameters, closing port:{}", portSettings); return false; } } catch (NoSuchPortException nspe) { logger.error("Could not open port: {}", portName, nspe); return false; } catch (PortInUseException piue) { logger.error("Port already in use: {}", portName, piue); return false; } catch (UnsupportedCommOperationException ucoe) { logger.error( "Port does not support requested port settings " + "(invalid dsmr:portsettings parameter?): {}", portName, ucoe); return false; } // SerialPort is ready, open the reader logger.info("SerialPort opened successful"); try { bis = new BufferedInputStream(serialPort.getInputStream()); } catch (IOException ioe) { logger.error("Failed to get inputstream for serialPort. Closing port", ioe); return false; } logger.info("DSMR Port opened successful"); return true; } }
Example #19
Source File: PrimareSerialConnector.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
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; } }
Example #20
Source File: PowerMaxSerialConnector.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * {@inheritDoc} **/ @Override public void open() { logger.debug("open(): Opening Serial Connection"); try { CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName); CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000); serialPort = (SerialPort) commPort; serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.enableReceiveThreshold(1); serialPort.disableReceiveTimeout(); setInput(serialPort.getInputStream()); setOutput(serialPort.getOutputStream()); getOutput().flush(); if (getInput().markSupported()) { getInput().reset(); } setReaderThread(new SerialReaderThread(getInput(), this)); getReaderThread().start(); setConnected(true); } catch (NoSuchPortException noSuchPortException) { logger.debug("open(): No Such Port Exception: {}", noSuchPortException.getMessage()); setConnected(false); } catch (PortInUseException portInUseException) { logger.debug("open(): Port in Use Exception: {}", portInUseException.getMessage()); setConnected(false); } catch (UnsupportedCommOperationException unsupportedCommOperationException) { logger.debug("open(): Unsupported Comm Operation Exception: {}", unsupportedCommOperationException.getMessage()); setConnected(false); } catch (UnsupportedEncodingException unsupportedEncodingException) { logger.debug("open(): Unsupported Encoding Exception: {}", unsupportedEncodingException.getMessage()); setConnected(false); } catch (IOException ioException) { logger.debug("open(): IO Exception: ", ioException.getMessage()); setConnected(false); } }
Example #21
Source File: NordicSketchUploader.java From arduino-remote-uploader with GNU General Public License v2.0 | 2 votes |
/** * ex ceylon:arduino-remote-uploader-1.0-SNAPSHOT andrew$ ./nordic-uploader.sh --sketch /Users/andrew/Documents/dev/arduino-remote-uploader/resources/BlinkSlow.cpp.hex --serial-port /dev/tty.usbmodemfa131 --baud-rate 19200 arduino-timeout 0 --ack-timeout-ms 5000 --retries 50 Experimental: JNI_OnLoad called. Stable Library ========================================= Native lib Version = RXTX-2.1-7 Java lib Version = RXTX-2.1-7 Sending sketch to nRF24L01 radio, size 1102 bytes, md5 8e7a58576bdc732d3f9708dab9aea5b9, number of packets 43, and 26 bytes per packet, header ef,ac,10,a,4,4e,0,2b,1a,3c ........................................... Successfully flashed remote Arduino in 3s, with 0 retries * @param args * @throws NumberFormatException * @throws IOException * @throws ParseException * @throws org.apache.commons.cli.ParseException * @throws PortInUseException * @throws UnsupportedCommOperationException * @throws TooManyListenersException * @throws StartOverException */ public static void main(String[] args) throws NumberFormatException, IOException, ParseException, org.apache.commons.cli.ParseException, PortInUseException, UnsupportedCommOperationException, TooManyListenersException, StartOverException { initLog4j(); new NordicSketchUploader().runFromCmdLine(args); // new NordicSketchUploader().processNordic("/Users/andrew/Documents/dev/arduino-remote-uploader/resources/RAU-328-13k.hex", "/dev/tty.usbmodemfa131", Integer.parseInt("19200"), false, 5, 0, 50, 250); }