【发布时间】:2015-02-12 08:14:25
【问题描述】:
我正在尝试找到一种方法来对从 USB 端口接收到的字符串值进行时间戳记(每 0.5 秒)并将其保存到文件中。
到目前为止,我正在使用“记录”函数来保存字符串值,但我无法为其添加时间戳。通读这些问题,发现有人使用了“现在”功能,但他们没有描述如何做到这一点。我用作示例来生成代码的字符串值如下:
1 于 2015 年 2 月 12 日 15:57:13.940 录制。小端格式的二进制数据。
2
3
4
到目前为止我开发的代码如下:
%// start code
delete(instrfind);
s = serial('COM5');
set(s,'BaudRate',57600);
set(s,'terminator','CR');
%// Open Serial COM Port
fopen(s);
%// start save file
s.RecordDetail = 'verbose';
s.RecordName = datestr(now,30)
record(s,'on')
%// start time
tic;
hold on;
count = 1;
t = 0;
keepLooping = true;
while keepLooping
time(count)=toc;
count = count +1;
out = fscanf(s);
fprintf(s,'%s','RS232?')
out1 = strsplit(out,',');
s.UserData = count;
p(count) = str2double(out1(2));
k(count) = str2double(out1(3));
g(count) = str2double(out1(4));
h(count) = str2double(out1(5));
%// plotting of the variables continues from this point.
【问题讨论】:
标签: matlab timestamp real-time