Can I record the time during serial port communication?
2 次查看(过去 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 中查找有关 Instrument Control Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!