I've written a program for some serial communication (RS232) in Matlab that's supposed to communicate with an microprocessor. It works fine receiving data from it, but when sending data it takes between 0.2-0.5 seconds for 2 bytes of data. Is there a known way to speed up serial communications in Matlab or will I have to live with this? Here is the code I'm using for writing:% confa serieporten com_port = '/dev/tty.FireFly-16CB-SPP'; ser = serial(com_port, 'BaudRate', 115200); ser.BytesAvailableFcnCount = 1; ser.BytesAvailableFcnMode = 'byte'; ser.Timeout = 5; i = 1; while i. 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). Python Windows Xp 32 Bit.
Serial communication in Matlab is really slow. Here is the code I'm using for writing. Recording the time during serial port communication in matlab.
Matlab Code to Transmit Data Through Serial Port Serial communication is the simplest way to communicate between two devices. Communication using the serial port. Without detailed knowledge of how the serial port works. Communication is established. Aia A401. Object to MATLAB code.
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.' My question back to you is, 'Do you have to attempt to send every byte immediately?' The communication should be much more efficient if you use a larger value for BytesAvailableFcnCount. Unless your hardware has very particular constraints, I recommend choosing a larger buffer size. (This may 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). 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. EDIT: Another thought; I don't have a MATLAB to test this with right now, but what happens if you don't write the data in a for loop - instead, leave the BytesAvailableFcnCount set to 1, and fwrite the entire buffer in one shot? The way that I read the, BytesAvailableFcnCount only specifies the 'trigger' for how large the buffer can get before its flushed, not how large the buffer can be.