Read Interval Timeouts for Serial Communication
조회 수: 16 (최근 30일)
이전 댓글 표시
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))
댓글 수: 0
답변 (1개)
Vinod
2015년 8월 12일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Instrument Control Toolbox Supported Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!