public boolean disconnect() { try { serialPort.closePort(); connected = false; } catch (SerialPortException e) { e.printStackTrace(); } return !connected; }
@Override public boolean sendCommand(String string) { try { return serialPort.writeString(string); } catch (SerialPortException e) { e.printStackTrace(); } return false; }
public void forwardMessage(int[]message) { String messageString = ""; for (int i = 0; i < message.length-1; i++) messageString+=Integer.toHexString(Math.max(0,Math.min(message[i],255))) + " "; messageString+=Integer.toHexString(Math.max(0,Math.min(message[message.length-1],255))) + "\n"; try { System.out.println("messageString:" + messageString); serialPort.purgePort(SerialPort.PURGE_TXCLEAR | SerialPort.PURGE_RXCLEAR); serialPort.writeString(messageString); } catch (SerialPortException e) { e.printStackTrace(); } }
@Override public int shutDown() { if (serialPort.isOpened()) { try { serialPort.removeEventListener(); serialPort.closePort(); return 1; } catch (SerialPortException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } return -1; }
/** * * @param payload * The complete XBee frame generated by the FrameFactory. */ public synchronized void sendData(byte[] payload) { try { byte[] frame = payload; boolean success = serialPort.writeBytes(frame); if (Configuration.DEBUG && logger.isTraceEnabled()) { logger.trace("Successful sent: " + success); logger.trace("sendFromFifo:\n " + Constants.bytesToHex(frame)); } } catch (SerialPortException e) { e.printStackTrace(); } } }
public void close() { try { closeSerialConnection(); } catch (SerialPortException e) { e.printStackTrace(); } deviceHandler.stop(); messageHandler.stop(); }
@Descriptor("Add a new Connection to the driver via port name.") public void addConnectionViaPort(@Descriptor("The port name.") String interfaceId) { Connection con; try { con = new Connection(interfaceId, driver); driver.addConnection(con); } catch (SerialPortException e) { e.printStackTrace(); } }
tempArray = serialPort.readBytes(); } catch (SerialPortException e) { e.printStackTrace();
serialPort.closePort(); } catch (SerialPortException e) { e.printStackTrace(); e1.printStackTrace();
@Descriptor("Add a new Connection to the driver via hardware ID.") public void addConnection(@Descriptor("The hardware ID of the XBee.") String identifier) { Connection con; try { con = new Connection(getPortName(identifier), driver); driver.addConnection(con); } catch (SerialPortException e) { e.printStackTrace(); } }
@Override public void hardwareAdded(HardwareDescriptor descriptor) { logger.debug("hardware added: " + descriptor.getIdentifier()); String portName = null; if (descriptor.getHardwareType() == HardwareType.USB) { portName = ((UsbHardwareDescriptor) descriptor).getPortName(); } else if (descriptor.getHardwareType() == HardwareType.SERIAL) { portName = ((SerialHardwareDescriptor) descriptor).getPortName(); } else { logger.debug("error, descriptor has unsupported hardware type: " + descriptor.getHardwareType().toString()); } if (null == portName) { logger.error("Add device with port name null."); return; } Connection con = null; try { con = new Connection(portName, this); addConnection(con); } catch (SerialPortException e) { e.printStackTrace(); } }
@Override public void channelAdded(ChannelLocator channelLocator) { DeviceLocator deviceLocator = channelLocator.getDeviceLocator(); String iface = deviceLocator.getInterfaceName(); Connection con; Device device; Channel channel; // Connection handling con = findConnection(iface); if (con == null) { try { con = new Connection(iface, this); addConnection(con); } catch (SerialPortException e) { e.printStackTrace(); } } // Device handling device = con.findDevice(deviceLocator); if (device == null) { device = new Device(deviceLocator, con); con.addDevice(device); } // Channel handling channel = device.findChannel(channelLocator); if (channel == null) { channel = Channel.createChannel(channelLocator, device); device.addChannel(channel); } }