From: Jose on
Let me add that data is arriving from the USB every 32ms and we intended to just read it when its available, and plot it. After that we want to compare this value to the same value but coming from a NI DAQ board which can be read every 1ms in real-time. With this we intend to calculate the delay of communication between USB and MATLAB for the amount of data that we have.

Best regards,
Jose




"Jose " <jose.araujo(a)fe.up.pt> wrote in message <i3j1qd$6md$1(a)fred.mathworks.com>...
> Dear all,
>
> I am having a problem using the packet input function on real-time. I am able to read the 17 bytes of data I am sending through the serial port in a good way BUT sometimes I end up having an extra byte in the frame which is making my buffer shifting one position every time this happens.
>
> E.g.
>
> byte 1 ... byte 17 = 17 bytes
> byte 1 ... Garbage = 17 bytes
> byte 17 (old) byte 1 ... byte 16 = 17 bytes
>
> So basically after some time I start only seeing the last bytes in the next frame, which is really bad. What I can do to fix this, in MATLAB code (http://www.mathworks.com/support/solutions/en/data/1-30N8YX/index.html?product=ML&solution=1-30N8YX) and in Labview is to Flush and Discard the Buffer (Purgecomm function in C). The thing is that I needed to use real-time simulink for this but Packet output doesnt do this automatically.
>
> Do you have any suggestions on how to do this?
>
> We have tried to do a C function S function to read the serial port in real-time, but first we used the windows.h to do this and it doesnt work as it is explained in the matlab help, and after that we built a C function based on the conio.h function which also doesnt work since it is made for pure RS232 serial communications (PORT1 to PORT4) and we are using USB (PORT5 to PORT9).
>
> Thank you!
> Jose