Filter löschen
Filter löschen

Can I record the time during serial port communication?

3 Ansichten (letzte 30 Tage)
Maheen Siddiqui
Maheen Siddiqui am 21 Mär. 2016
Beantwortet: Walter Roberson am 21 Mär. 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

Antworten (1)

Walter Roberson
Walter Roberson am 21 Mär. 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.

Kategorien

Mehr zu Instrument Control Toolbox Supported Hardware finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by