I am sure that the SERIAL object uses the Java API (at least it was used, the implementation may have changed since I worked with it). The overhead of using the MATLAB object system, unlike talking to Java objects โdirectlyโ in MATLAB, is trivial. Therefore, I would not try to skip the SERIAL object and switch to "directly in Java".
My question to you is: "Do you have an attempt to send every byte at once ?" The message should be much more efficient if you use a larger value for BytesAvailableFcnCount .
If your equipment does not have special restrictions, I recommend choosing the size of a larger buffer. (This may require you to force a reset at the end of the data stream, since you cannot expect the byte to be written automatically. But presumably you are already closing and deleting the object at the appropriate time, so it should not be difficult to clear the buffer at the same time).
If you do not specify a value, MATLAB uses the default value of 48 bytes. I donโt remember how the exact value was chosen, but writing several values โโat once will be much more efficient than writing to buffers and washing them with a byte at the same time.
EDIT: Another thought; I don't have MATLAB to test this right now, but what happens if you don't write data in a for loop - instead, leave BytesAvailableFcnCount to 1, and fwrite the entire buffer in one shot?
The way I read the documentation , BytesAvailableFcnCount only indicates a โtriggerโ for how big the buffer can get before it is flushed, and not how big the buffer can be. Therefore, having BytesAvailableFcnCount of 1 and writing 128 (say) 128 to a buffer in one shot, it can be flushed to the device only once, and not 128 times, which your existing code does.
source share