Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm pretty certain that the SERIAL object is using the Java APIs (at least, it used to; the implementation may have changed since I've worked with it). The overhead of using the MATLAB object system, as opposed to talking to the Java objects "directly" in MATLAB, is trivial. Therefore, I wouldn't bother to try skipping the SERIAL object and going to "straight to Java."</p> <p>My question back to you is, "Do you <strong>have</strong> to attempt to send every byte <strong>immediately</strong>?" The communication should be much more efficient if you use a larger value for <code>BytesAvailableFcnCount</code>.</p> <p>Unless your hardware has very particular constraints, I recommend choosing a larger buffer size. (This <em>may</em> require you to forcibly flush when the data stream ends, since you can't count on very byte being written automatically. But presumably, you're already closing and deleting the object at the appropriate time, so it shouldn't be hard to additionally flush the buffer simultaneously).</p> <p>If you don't specify a value, MATLAB uses a default value of 48 bytes. I don't recall how that exact value was chosen, but writing several values at once will be much more efficient than writing to the buffers and flushing them a byte at a time.</p> <p>EDIT: Another thought; I don't have a MATLAB to test this with right now, but what happens if you <em>don't</em> write the data in a <code>for</code> loop - instead, leave the <code>BytesAvailableFcnCount</code> set to 1, and fwrite the entire buffer in one shot?</p> <p>The way that I read the <a href="http://www.mathworks.com/help/techdoc/matlab_external/bytesavailablefcncount.html" rel="nofollow">documentation</a>, <code>BytesAvailableFcnCount</code> only specifies the "trigger" for how large the buffer can get before its flushed, <em>not</em> how large the buffer can be. So having a <code>BytesAvailableFcnCount</code> of 1 and writing to a buffer of size (say) 128 in one shot <em>might</em> flush to the device only once, instead of 128 times, which your existing code does.</p>
 

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