📄 main.pas
字号:
memo1.lines.add('波次'+inttostr(i)+' '+inttostr(k1[i]));
memo1.lines.add('幅值'+inttostr(i)+' '+inttostr(l1[i]));
memo1.lines.add('相角'+inttostr(i)+' '+inttostr(p1[i]));
end;
memo1.lines.add('总数'+' '+inttostr(m1));
//通道二
memo4.Lines.Clear;
for i:=0 to m2-1 do
begin
memo4.lines.add('波次'+inttostr(i)+' '+inttostr(k2[i]));
memo4.lines.add('幅值'+inttostr(i)+' '+inttostr(l2[i]));
memo4.lines.add('相角'+inttostr(i)+' '+inttostr(p2[i]));
end;
memo4.lines.add('总数'+' '+inttostr(m2));
//通道三
memo5.Lines.Clear;
for i:=0 to m3-1 do
begin
memo5.lines.add('波次'+inttostr(i)+' '+inttostr(k3[i]));
memo5.lines.add('幅值'+inttostr(i)+' '+inttostr(l3[i]));
memo5.lines.add('相角'+inttostr(i)+' '+inttostr(p3[i]));
end;
memo5.lines.add('总数'+' '+inttostr(m3));
//通道四
memo6.Lines.Clear;
for i:=0 to m4-1 do
begin
memo6.lines.add('波次'+inttostr(i)+' '+inttostr(k4[i]));
memo6.lines.add('幅值'+inttostr(i)+' '+inttostr(l4[i]));
memo6.lines.add('相角'+inttostr(i)+' '+inttostr(p4[i]));
end;
memo6.lines.add('总数'+' '+inttostr(m4));
//通道五
memo7.Lines.Clear;
for i:=0 to m5-1 do
begin
memo7.lines.add('波次'+inttostr(i)+' '+inttostr(k5[i]));
memo7.lines.add('幅值'+inttostr(i)+' '+inttostr(l5[i]));
memo7.lines.add('相角'+inttostr(i)+' '+inttostr(p5[i]));
end;
memo7.lines.add('总数'+' '+inttostr(m5));
//通道六
memo8.Lines.Clear;
for i:=0 to m6-1 do
begin
memo8.lines.add('波次'+inttostr(i)+' '+inttostr(k6[i]));
memo8.lines.add('幅值'+inttostr(i)+' '+inttostr(l6[i]));
memo8.lines.add('相角'+inttostr(i)+' '+inttostr(p6[i]));
end;
memo8.lines.add('总数'+' '+inttostr(m6));
//################################
//一通道计算数据
//清除原数据
for i:=0 to 94 do
begin
dataout_1[i]:=0;
dataout1[i]:=0;
end;
//波形数据计算
for i:=0 to 94 do
begin
for v:=0 to m1-1 do
begin
dataout_1[i]:=dataout_1[i]+l1[v]*sin(PI*k1[v]*i/47+p1[v]*PI/180);
end;
end;
//求最大值
g:=GetMaxInArray(dataout_1); //数值处理成0-255
memo1.lines.add('g'+#9+floattostr(g)); //显示g值
//求最后结果
for i:=0 to 94 do
begin
if(m1=0) then
begin
dataout1[i]:=0;
end
else
begin
dataout1[i]:=round(dataout_1[i]*127/g+128);
end;
end;
//################################
//二通道计算数据
//清除原数据
for i:=0 to 94 do
begin
dataout_1[i]:=0;
dataout2[i]:=0;
end;
//波形数据计算
for i:=0 to 94 do
begin
for v:=0 to m2-1 do
begin
dataout_1[i]:=dataout_1[i]+l2[v]*sin(PI*k2[v]*i/47+p2[v]*PI/180);
end;
end;
//求最大值
g:=GetMaxInArray(dataout_1); //数值处理成0-255
memo4.lines.add('g'+#9+floattostr(g)); //显示g值
//求最后结果
for i:=0 to 94 do
begin
if(m2=0) then
begin
dataout2[i]:=0;
end
else
begin
dataout2[i]:=round(dataout_1[i]*127/g+128);
end;
end;
//################################
//三通道计算数据
//清除原数据
for i:=0 to 94 do
begin
dataout_1[i]:=0;
dataout3[i]:=0;
end;
//波形数据计算
for i:=0 to 94 do
begin
for v:=0 to m3-1 do
begin
dataout_1[i]:=dataout_1[i]+l3[v]*sin(PI*k3[v]*i/47+p3[v]*PI/180);
end;
end;
//求最大值
g:=GetMaxInArray(dataout_1); //数值处理成0-255
memo5.lines.add('g'+#9+floattostr(g)); //显示g值
//求最后结果
for i:=0 to 94 do
begin
if(m3=0) then
begin
dataout3[i]:=0;
end
else
begin
dataout3[i]:=round(dataout_1[i]*127/g+128);
end;
end;
//################################
//四通道计算数据
//清除原数据
for i:=0 to 94 do
begin
dataout_1[i]:=0;
dataout4[i]:=0;
end;
//波形数据计算
for i:=0 to 94 do
begin
for v:=0 to m4-1 do
begin
dataout_1[i]:=dataout_1[i]+l4[v]*sin(PI*k4[v]*i/47+p4[v]*PI/180);
end;
end;
//求最大值
g:=GetMaxInArray(dataout_1); //数值处理成0-255
memo6.lines.add('g'+#9+floattostr(g)); //显示g值
//求最后结果
for i:=0 to 94 do
begin
if(m4=0) then
begin
dataout4[i]:=0;
end
else
begin
dataout4[i]:=round(dataout_1[i]*127/g+128);
end;
end;
//################################
//五通道计算数据
//清除原数据
for i:=0 to 94 do
begin
dataout_1[i]:=0;
dataout5[i]:=0;
end;
//波形数据计算
for i:=0 to 94 do
begin
for v:=0 to m5-1 do
begin
dataout_1[i]:=dataout_1[i]+l5[v]*sin(PI*k5[v]*i/47+p5[v]*PI/180);
end;
end;
//求最大值
g:=GetMaxInArray(dataout_1); //数值处理成0-255
memo7.lines.add('g'+#9+floattostr(g)); //显示g值
//求最后结果
for i:=0 to 94 do
begin
if(m5=0) then
begin
dataout5[i]:=0;
end
else
begin
dataout5[i]:=round(dataout_1[i]*127/g+128);
end;
end;
//################################
//六通道计算数据
//清除原数据
for i:=0 to 94 do
begin
dataout_1[i]:=0;
// dataout6[i]:=0;
end;
//波形数据计算
for i:=0 to 94 do
begin
for v:=0 to m6-1 do
begin
dataout_1[i]:=dataout_1[i]+l6[v]*sin(PI*k6[v]*i/47+p6[v]*PI/180);
end;
end;
//求最大值
g:=GetMaxInArray(dataout_1); //数值处理成0-255
memo8.lines.add('g'+#9+floattostr(g)); //显示g值
//求最后结果
for i:=0 to 94 do
begin
if(m6=0) then
begin
dataout6[i]:=0;
end
else
begin
dataout6[i]:=round(dataout_1[i]*127/g+128);
end;
end;
////////////////////////////////////////
//数据转化,为的是让硬件识别,仿真无需要变换类型输出
//一通道发送数据
memo3.lines.Clear;
for i:=0 to 94 do
str:=str+inttoHEX(dataout1[i],2);
osenddata:=vararraycreate([0,(length(str) div 2) -1],varbyte);
for i:=1 to (length(str) div 2) do
begin
osenddata[i-1]:=strtoint('$'+(str[2*i-1]+str[2*i]));
memo3.lines.add(inttostr(osenddata[i-1])); //显示发送的数据
end;
osendstr:=osenddata;
try
mscomm1.output:=osendstr;
except
end;
//flag_1:=true;
//数据转化,为的是让硬件识别,仿真无需要变换类型输出
//二通道发送数据
{
if(flag_1=true) then
begin
memo9.lines.Clear;
for i:=0 to 94 do
str:=str+inttoHEX(dataout2[i],2);
osenddata:=vararraycreate([0,(length(str) div 2) -1],varbyte);
for i:=1 to (length(str) div 2) do
begin
osenddata[i-1]:=strtoint('$'+(str[2*i-1]+str[2*i]));
memo9.lines.add(inttostr(osenddata[i-1])); //显示发送的数据
end;
osendstr:=osenddata;
try
mscomm1.output:=osendstr;
except
end;
flag_2:=true;
end;
}
//数据转化,为的是让硬件识别,仿真无需要变换类型输出
//三通道发送数据
{
if(flag_2=true) then
begin
memo10.lines.Clear;
for i:=0 to 94 do
str:=str+inttoHEX(dataout3[i],2);
osenddata:=vararraycreate([0,(length(str) div 2) -1],varbyte);
for i:=1 to (length(str) div 2) do
begin
osenddata[i-1]:=strtoint('$'+(str[2*i-1]+str[2*i]));
memo10.lines.add(inttostr(osenddata[i-1])); //显示发送的数据
end;
osendstr:=osenddata;
try
mscomm1.output:=osendstr;
except
end;
flag_3:=true;
end;
}
//数据转化,为的是让硬件识别,仿真无需要变换类型输出
//四通道发送数据
{
if(flag_3=true) then
begin
memo11.lines.Clear;
for i:=0 to 94 do
str:=str+inttoHEX(dataout4[i],2);
osenddata:=vararraycreate([0,(length(str) div 2) -1],varbyte);
for i:=1 to (length(str) div 2) do
begin
osenddata[i-1]:=strtoint('$'+(str[2*i-1]+str[2*i]));
memo11.lines.add(inttostr(osenddata[i-1])); //显示发送的数据
end;
osendstr:=osenddata;
try
mscomm1.output:=osendstr;
except
end;
flag_4:=true;
end;
}
//数据转化,为的是让硬件识别,仿真无需要变换类型输出
//五通道发送数据
{
if(flag_4=true) then
begin
memo12.lines.Clear;
for i:=0 to 94 do
str:=str+inttoHEX(dataout5[i],2);
osenddata:=vararraycreate([0,(length(str) div 2) -1],varbyte);
for i:=1 to (length(str) div 2) do
begin
osenddata[i-1]:=strtoint('$'+(str[2*i-1]+str[2*i]));
memo12.lines.add(inttostr(osenddata[i-1])); //显示发送的数据
end;
osendstr:=osenddata;
try
mscomm1.output:=osendstr;
except
end;
flag_5:=true;
end;
}
//数据转化,为的是让硬件识别,仿真无需要变换类型输出
//六通道发送数据
{
if(flag_5=true) then
begin
memo13.lines.Clear;
for i:=0 to 94 do
str:=str+inttoHEX(dataout6[i],2);
osenddata:=vararraycreate([0,(length(str) div 2) -1],varbyte);
for i:=1 to (length(str) div 2) do
begin
osenddata[i-1]:=strtoint('$'+(str[2*i-1]+str[2*i]));
memo13.lines.add(inttostr(osenddata[i-1])); //显示发送的数据
end;
osendstr:=osenddata;
try
mscomm1.output:=osendstr;
except
end;
flag_1:=false; //保证通讯顺序用的
flag_2:=false;
flag_3:=false;
flag_4:=false;
flag_5:=false;
end;
}
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
if(mscomm1.PortOpen=true) then mscomm1.portopen:=false;
mscomm1.CommPort:=3;
mscomm1.InBufferSize:=256;
mscomm1.OutBufferSize:=256;
mscomm1.Settings:='9600,n,8,1';
mscomm1.InputLen:=0;
mscomm1.InBufferCount:=0;
mscomm1.OutBufferCount:=0;
mscomm1.RThreshold:=1;
mscomm1.InputMode:=comINputmodeBinary;
mscomm1.PortOpen:=true;
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
mscomm1.PortOpen:=false;
end;
//################################
//一通道添加波形
procedure TForm1.Button10Click(Sender: TObject);
var
i : integer;
b:integer;
cc:boolean;
begin
//添加选中波形
for i := 0 to listbox1.Count -1 do
begin
if listbox1.Selected[i] then
begin
for b:=0 to listbox4.Count-1 do
begin
//判断是否已经添加过
if listbox4.Items[b]=listbox1.Items[i] then
begin
cc:=true
end;
end;
if cc=true then
begin
cc:=false;
end
else
begin
listbox4.Items.Add(listbox1.Items[i]);
m1:=m1+1;
// Label1.Caption:=inttostr(m);
end;
end;
end;
end;
//################################
//二通道添加波形
procedure TForm1.Button11Click(Sender: TObject);
var
i : integer;
b:integer;
cc:boolean;
begin
//添加选中波形
for i := 0 to listbox1.Count -1 do
begin
if listbox1.Selected[i] then
begin
for b:=0 to listbox5.Count-1 do
begin
//判断是否已经添加过
if listbox5.Items[b]=listbox1.Items[i] then
begin
cc:=true
end;
end;
if cc=true then
begin
cc:=false;
end
else
begin
listbox5.Items.Add(listbox1.Items[i]);
m2:=m2+1;
// Label1.Caption:=inttostr(m);
end;
end;
end;
end;
//################################
//三通道添加波形
procedure TForm1.Button15Click(Sender: TObject);
var
i : integer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -