Read Interval Timeouts for Serial Communication

6 views (last 30 days)
hate
hate on 12 Aug 2015
Answered: Vinod on 12 Aug 2015
I need to communicate with a device via serial port. The device continously sends some binary data packages which are seperated by a certain (i.e. 100ms) duration. Therefore, in order to read these packages sequentially, I have to set timeout property of the serial port. In "C", this can be easly done by setting "commtimeouts.ReadIntervalTimeout" (in windows) or termios.vtime (in posix) to 100ms.
Is there anyway to set the same serial port parameter in matlab? I checked all the properties of serial port object in matlab, but I could not find any property for this purpose. (The timeout property of serial object in matlab is not relevant for this purpose.)
Would it at least be possible to set the serial port parameter via a mex file after I create (and open) it matlab? (in other words, can I somehow pass the handle to the serial port to a mex file so that I can natively set the serial port parameter in "C" using "setcommtimeout" (in windows) or tcsetattr (in posix))

Answers (1)

Vinod
Vinod on 12 Aug 2015
I suspect you are better off by using a BytesAvailableFcn callback to read back the specified number of bytes from the device when there are bytes on the serial port. In the BytesAvailableFcn, use Fread to read back the data in the packet.

Categories

Find more on Instrument Control Toolbox Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!