public void sendConfiguration(Biasgen biasgen) throws HardwareInterfaceException { if (!isOpen()) { throw new HardwareInterfaceException("not open"); } int MAX_COMMAND_LENGTH_BYTES = 256; for (Pot p : getBiasgen().getPotArray().getPots()) { UDP_VPot vp = (UDP_VPot) p; try { String s = vp.getCommandString(); byte[] b = s.getBytes(); // s.getBytes(Charset.forName("US-ASCII")); socket.send(new DatagramPacket(b, b.length, client)); DatagramPacket packet = new DatagramPacket(new byte[MAX_COMMAND_LENGTH_BYTES], MAX_COMMAND_LENGTH_BYTES); socket.receive(packet); ByteArrayInputStream bis; BufferedReader reader = new BufferedReader( new InputStreamReader( (bis = new ByteArrayInputStream(packet.getData(), 0, packet.getLength())))); String line = reader.readLine(); // .toLowerCase(); log.info("response from " + packet.getAddress() + " : " + line); // System.out.println(line); // debug } catch (SocketTimeoutException to) { log.warning("timeout on waiting for command response on datagram control socket"); } catch (Exception ex) { throw new HardwareInterfaceException( "while sending biases to " + client + " caught " + ex.toString()); } } }
/** * called when observable (masterbias) calls notifyObservers. Sets the powerDown state. If there * is not a batch edit occurring, opens device if not open and calls sendConfiguration. */ @Override public void update(Observable observable, Object object) { if (object != null && object.equals("powerDownEnabled")) { log.warning("no powerdown capability"); } else if (object instanceof UDP_VPot) { UDP_VPot vp = (UDP_VPot) object; try { if (!isBatchEditOccurring()) { if (!isOpen()) { open(); } } try { String s = vp.getCommandString(); log.info("sending " + vp + " with command " + s); sendString(s); printEchoDatagram(); printEchoDatagram(); try { Thread.sleep(10); } catch (InterruptedException e) { } } catch (SocketTimeoutException to) { throw new HardwareInterfaceException("timeout on sending datagram for " + vp); } catch (Exception ex) { throw new HardwareInterfaceException( "while sending biases to " + client + " caught " + ex.toString()); } } catch (HardwareInterfaceException e) { // connFailed=true; log.warning("error sending pot value for Pot " + object + " : " + e); } } }