我发送命令部分要实现的功能是:
(1)自动发送
(2)程序开始时会给用户选择菜单(checkbox),用户选择了哪几台仪表就读那几台仪表
(3)每次发送一台读命令(地址不同)等待Oncomm事件
(4)Timer时间间隔>1s,当然最好尽可能快
我原先用Sleep()时的读部分的代码是:
procedure TMainForm.Timer1Timer(Sender: TObject);
var SQLstring:string;
begin
StatusBar1.Panels[0].Text:='正在检测各仪表';
/////////////////////////////////////////////读出1号仪表的温度及状态
if (form1.CheckBox2.Checked=true) then
begin
Readtempt($30,$31);Temptorder1:=Temptorder; //mainform.Timer1.enable//仪表在运行状态时存数据库的内容
if (string_WCYzt<>'') then
begin
if (string_WCYzt='0') then
begin
SpeedButton9.Caption:='CH';Shape2.Brush.Color:=clyellow;SpeedButton9.Enabled:=true;
end else
if (string_WCYzt='1') then
begin
SpeedButton9.Caption:='CH'; Shape2.Brush.Color:=clyellow;SpeedButton9.Enabled:=true;
readPID($30,$31);PIDorder1:=PIDorder;
if (DisplayingWCY='1')then
begin
Paint20curve();
DisplayArray1:=Temptorder1;
DisplayArray2:=PIDorder1;
Display(DisplayArray1,DisplayArray2);
end;
end else
if (string_WCYzt='2') then
begin
SpeedButton9.Caption:='RUN'; Shape2.Brush.Color:=clgreen; SpeedButton9.Enabled:=true;
iAnalogDisplay21.Value:=strtointdef(Temptorder1[2],0);//段运行时间变化触发存储事件重要的设置!!!!!!!!
end else
if (string_WCYzt='3') then
begin
SpeedButton9.Caption:='RU'; Shape2.Brush.Color:=clgreen; SpeedButton9.Enabled:=true;
readPID($30,$31);
PIDorder1:=PIDorder;
ADOConnection1.Connected:=false;//先连接好对应1号仪表的数据库
ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/WSHAdata/WSH_A1.mdb;Persist Security Info=False';
UpdatePID();
Temptorder1[17]:=duan20[1];
iAnalogDisplay21.Value:=strtointdef(Temptorder1[2],0);//段运行时间变化触发存储事件重要的设置!!!!!!!!
if (DisplayingWCY='1')then
begin
Paint20curve();
DisplayArray1:=Temptorder1;
DisplayArray2:=PIDorder1;
Display(DisplayArray1,DisplayArray2);
end;
end else
if (string_WCYzt='ER') then
begin
SpeedButton9.Caption:='ER'; SpeedButton9.Enabled:=false; Shape2.Brush.Color:=clred;
end;
end;
end;
///////////////////////////////////读出2号仪表的温度及状态
if form1.CheckBox30.Checked=true then
begin
Readtempt($30,$32);Temptorder2:=Temptorder; //仪表在运行状态时存数据库的内容
if (string_WCYzt<>'') then
begin
if (string_WCYzt='0') then
begin
SpeedButton8.Caption:='CH';Shape3.Brush.Color:=clyellow;SpeedButton8.Enabled:=true;
end else
if (string_WCYzt='1') then
begin
SpeedButton8.Caption:='CH'; Shape3.Brush.Color:=clyellow;SpeedButton8.Enabled:=true;
readPID($30,$32);PIDorder2:=PIDorder;
if (DisplayingWCY='2')then
begin
Paint20curve();
DisplayArray1:=Temptorder2;
DisplayArray2:=PIDorder2;
Display(DisplayArray1,DisplayArray2);
等等。。。