Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ExecutorService executor = Executors.newSingleThreadExecutor();
- ...
- public synchronized void write(byte[] content, int timeout) throws InterruptedException, SerialPortException{
- long starttime = System.currentTimeMillis();
- Future<Boolean> future = executor.submit(new Callable<Boolean>() {
- public Boolean call() throws Exception {
- serialPort.writeBytes(content);
- return new Boolean(true);
- }
- });
- try {
- future.get(timeout, TimeUnit.MILLISECONDS);
- log.debug("Duration: {}",DurationFormatUtils.formatDuration(System.currentTimeMillis() - starttime, "mm:ss.SS"));
- } catch (ExecutionException e) {
- throw new HardwareException(e.getMessage());
- } catch (TimeoutException e) {
- throw new HardwareException("Impossibile scrivere nella porta seriale (timeout)");
- }
- }
- public synchronized void write(byte[] content, int timeout) throws InterruptedException, SerialPortException{
- try {
- long starttime = System.currentTimeMillis();
- serialPort.writeBytes(content);
- log.debug("Duration: {}",DurationFormatUtils.formatDuration(System.currentTimeMillis() - starttime, "mm:ss.SS"));
- } catch (SerialPortException e) {
- throw new HardwareException(e.getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement