源代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons;
type //A/D板读取的数据存储成内存文件格式记录,用于实时显示
TOrig_TimeSignal=record
Channel_Count:word; //通道数
Point_Count:integer; //每通道的点数
sampleRate:double; //采样频率
R_Time:TDateTime; //当前时间
R_Revolution:word; //转速
O_Arr:array[0..8192*2-1] of Single;
end;
type
TForm1 = class(TForm)
Timer1: TTimer;
BitBtn1: TBitBtn;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
var
i:word;
Orig_FileName:string;
SaveFilePf:file of TOrig_TimeSignal;
hisdir:string;
save_orig:TOrig_TimeSignal;
begin
save_orig.Channel_Count:=8;
save_orig.Point_Count:=2048;
save_orig.R_Time:=Now;
save_orig.sampleRate:=2000;
save_orig.R_Revolution:=round(4000);
randomize;
for i:=0 to 8*2048-1 do begin
Save_orig.O_Arr:=6*Sin(127.5*I*2*pi/5120+pi/0.69)+random(2)*Sin(I*1000*2*pi/5120+pi/2.3);
end;
hisdir:='D:/VibraHisData/'+FormatDateTime('yy-mm-dd',now);
if not DirectoryExists(hisdir) then
ForceDirectories(hisdir);
Orig_FileName:='D:/VibraHisData/'+FormatDateTime('yy-mm-dd',now)+'/'+FormatDateTime('hhmmss',now)+'.dat';
Assignfile(SaveFilePf,Orig_FileName);
Rewrite(SaveFilePf);
seek(SaveFilePf,fileSize(SaveFilePf));
try
Try
write(SaveFilePf,save_orig);
except
messagedlg('error of too long',mterror,[mbok],0);
end;
finally
Closefile(SaveFilePf);
end;
end;
end.