Effacer les filtres
Effacer les filtres

Can I record the time during serial port communication?

3 vues (au cours des 30 derniers jours)
Maheen Siddiqui
Maheen Siddiqui le 21 Mar 2016
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

Réponses (1)

Walter Roberson
Walter Roberson le 21 Mar 2016
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.

Catégories

En savoir plus sur Instrument Control Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by