Can I record the time during serial port communication?

1 visualización (últimos 30 días)
Maheen Siddiqui
Maheen Siddiqui el 21 de Mzo. de 2016
Respondida: Walter Roberson el 21 de Mzo. de 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

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Mzo. de 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.

Categorías

Más información sobre Instrument Control Toolbox Supported Hardware en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by