Note that there are some explanatory texts on larger screens.

plurals
  1. POJSSC serial connection set write timeout
    primarykey
    data
    text
    <p>I need to write some byte to the serial connection. However I can not find something in <a href="http://code.google.com/p/java-simple-serial-connector/" rel="nofollow">JSSC</a> library to set a write timeout. I need this timeout because if I set the hardware flowcontrol and I remove the cable my application is stuck waiting the CTS signal.</p> <p><strong>UPDATE</strong></p> <p>I tried this workaround with Future object:</p> <pre><code> ExecutorService executor = Executors.newSingleThreadExecutor(); ... public synchronized void write(byte[] content, int timeout) throws InterruptedException, SerialPortException{ long starttime = System.currentTimeMillis(); Future&lt;Boolean&gt; future = executor.submit(new Callable&lt;Boolean&gt;() { 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)"); } } </code></pre> <p>But it doesn't work very well, it take 4s to write 550byte via COM port 256000 baud...</p> <p>Trying a direct write:</p> <pre><code> 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()); } } </code></pre> <p>It took 0.5s as expected!</p> <p>The problem seems to be the "syncronized" keyword in the main method, why?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload