Can I record the time during serial port communication?
조회 수: 1 (최근 30일)
이전 댓글 표시
I am using Matlab commands fopen, fwrite and fscanf to open a line of serial port communication between two laptops using the following code:
On laptop #1:
portID='/dev/tty.USA28Z145P2.2'
s=serial(portID)
fopen(s)
fwrite(s,'67')
On laptop #2:
s=serial('COM3')
fopen(s)
out=fscanf(s)
From the script I am running, sometimes the fwrite writes 67 and sometimes 83 to the serial port. 'Out' is able to record all of these.
I am trying to find a way to record the exact time at which each fscanf occurs, is this possible? I am collecting data and these commands run while the data acquisition is taking place and I need to find a way to record the time when each fscanf occurs so that I can sync it with my other data. For e.g. if the COM3 port scans '67' I need to know at which time exactly this is because for my data collection '67' signifies the beginning of a 12 second period.
Does anybody know how to do this? Any suggestions would be greatly appreciated!
Thanks,
Maheen
댓글 수: 0
답변 (1개)
Walter Roberson
2016년 3월 21일
No, to do this you need the Data Acquisition Toolbox, or possibly the Instrument Control Toolbox.
However, you might find that for your purposes it is enough to use serial BytesAvailableFcn callback and have that callback record the time. The callback will not be triggered until the data is available.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Time Series Events에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!