DELPHI访问PLC输出口

这段代码展示了如何用Delphi通过定时器Timer1读取PLC的输出点,并根据读取的数据控制图片的可见性。同时,它还读取了一些特定地址的Word数据并进行转换显示。代码询问是否有更直接的方法来访问PLC的输入输出及内部功能。

procedure TForm1.Timer1Timer(Sender: TObject);
var
  ibyteindex:integer;
  ibitindex:integer;
  errreadoutputpoint:integer;
  vdata:olevariant;
  datatype:pointdatatypeconstants;
  i,j,k,l:integer;
  begin
  k:=0;
  //s7prosim1.ExecuteSingleScan;
  for i:=0 to 4 do
  begin
   for j:=0 to 7 do
   begin
     ibyteindex:=i;
     ibitindex:=j;
     datatype:=s7_bit;
     errreadoutputpoint:=s7prosim1.ReadOutputPoint(ibyteindex,ibitindex,datatype,vdata);
     table1.Edit;
     table1.FieldByName('Q'+inttostr(i)+'.'+inttostr(j)).AsInteger:=vdata;
     table1.Post;
   end;
   end;
   if table2.FieldByName('Q0.0').AsInteger =1 then
  begin
    image1.Visible :=true;
  end
  else
  begin
    image1.Visible :=false;
  end;
    if table1.FieldByName('Q0.1').AsInteger =1 then
  begin
    image2.Visible :=true;
  end
  else
  begin
    image2.Visible :=false;
  end;
    if table1.FieldByName('Q0.2').AsInteger =1 then
  begin
    image3.Visible :=true;
  end
  else
  begin
    image3.Visible :=false;
  end;
    if table1.FieldByName('Q0.3').AsInteger =1 then
  begin
    image4.Visible :=true;
  end
  else
  begin
    image4.Visible :=false;
  end;
    if table1.FieldByName('Q0.4').AsInteger =1 then
  begin
    image5.Visible :=true;
  end
  else
  begin
    image5.Visible :=false;
  end;
    if table1.FieldByName('Q0.5').AsInteger =1 then
  begin
    image6.Visible :=true;
  end
  else
  begin
    image6.Visible :=false;
  end;
    if table1.FieldByName('Q0.6').AsInteger =1 then
  begin
    image7.Visible :=true;
  end
  else
  begin
    image7.Visible :=false;
  end;
    if table1.FieldByName('Q0.7').AsInteger =1 then
  begin
    image8.Visible :=true;
  end
  else
  begin
    image8.Visible :=false;
  end;
  if table1.FieldByName('Q1.0').AsInteger =1 then
  begin
    image9.Visible :=true;
  end
  else
  begin
    image9.Visible :=false;
  end;  if table1.FieldByName('Q1.1').AsInteger =1 then
  begin
    image10.Visible :=true;
  end
  else
  begin
    image10.Visible :=false;
  end;  if table1.FieldByName('Q1.2').AsInteger =1 then
  begin
    image11.Visible :=true;
  end
  else
  begin
    image11.Visible :=false;
  end;
    if table1.FieldByName('Q1.3').AsInteger =1 then
  begin
    image12.Visible :=true;
  end
  else
  begin
    image12.Visible :=false;
  end;
    if table1.FieldByName('Q1.4').AsInteger =1 then
  begin
    image13.Visible :=true;
  end
  else
  begin
    image13.Visible :=false;
  end;
    if table1.FieldByName('Q1.5').AsInteger =1 then
  begin
    image14.Visible :=true;
  end
  else
  begin
    image14.Visible :=false;
  end;
    if table1.FieldByName('Q1.6').AsInteger =1 then
  begin
    image15.Visible :=true;
  end
  else
  begin
    image15.Visible :=false;
  end;
    if table1.FieldByName('Q1.7').AsInteger =1 then
  begin
    image16.Visible :=true;
  end
  else
  begin
    image16.Visible :=false;
  end;
    if table1.FieldByName('Q2.0').AsInteger =1 then
  begin
    image17.Visible :=true;
  end
  else
  begin
    image17.Visible :=false;
  end;
    if table1.FieldByName('Q2.1').AsInteger =1 then
  begin
    image18.Visible :=true;
  end
  else
  begin
    image18.Visible :=false;
  end;
    if table1.FieldByName('Q2.2').AsInteger =1 then
  begin
    image19.Visible :=true;
  end
  else
  begin
    image19.Visible :=false;
  end;
      if table1.FieldByName('Q2.3').AsInteger =1 then
  begin
    image20.Visible :=true;
  end
  else
  begin
    image20.Visible :=false;
  end;
      if table1.FieldByName('Q2.4').AsInteger =1 then
  begin
    image21.Visible :=true;
  end
  else
  begin
    image21.Visible :=false;
  end;
      if table1.FieldByName('Q2.5').AsInteger =1 then
  begin
    image22.Visible :=true;
  end
  else
  begin
    image22.Visible :=false;
  end;
      if table1.FieldByName('Q2.6').AsInteger =1 then
  begin
    image23.Visible :=true;
  end
  else
  begin
    image23.Visible :=false;
  end;
      if table1.FieldByName('Q2.7').AsInteger =1 then
  begin
    image24.Visible :=true;
  end
  else
  begin
    image24.Visible :=false;
  end;
      if table1.FieldByName('Q3.0').AsInteger =1 then
  begin
    image25.Visible :=true;
  end
  else
  begin
    image25.Visible :=false;
  end;
      if table1.FieldByName('Q3.1').AsInteger =1 then
  begin
    image26.Visible :=true;
  end
  else
  begin
    image26.Visible :=false;
  end;
      if table1.FieldByName('Q3.2').AsInteger =1 then
  begin
    image27.Visible :=true;
  end
  else
  begin
    image27.Visible :=false;
  end;
      if table1.FieldByName('Q0.1').AsInteger =1 then
  begin
    image2.Visible :=true;
  end
  else
  begin
    image2.Visible :=false;
  end;
      if table1.FieldByName('Q3.3').AsInteger =1 then
  begin
    image28.Visible :=true;
  end
  else
  begin
    image28.Visible :=false;
  end;
      if table1.FieldByName('Q3.4').AsInteger =1 then
  begin
    image29.Visible :=true;
  end
  else
  begin
    image29.Visible :=false;
  end;
      if table1.FieldByName('Q3.5').AsInteger =1 then
  begin
    image30.Visible :=true;
  end
  else
  begin
    image30.Visible :=false;
  end;
        if table1.FieldByName('Q3.6').AsInteger =1 then
  begin
    image31.Visible :=true;
  end
  else
  begin
    image31.Visible :=false;
  end;
        if table1.FieldByName('Q3.7').AsInteger =1 then
  begin
    image32.Visible :=true;
  end
  else
  begin
    image32.Visible :=false;
  end;
        if table1.FieldByName('Q4.0').AsInteger =1 then
  begin
    image33.Visible :=true;
  end
  else
  begin
    image33.Visible :=false;
  end;
        if table1.FieldByName('Q4.1').AsInteger =1 then
  begin
    image34.Visible :=true;
  end
  else
  begin
    image34.Visible :=false;
  end;
        if table1.FieldByName('Q4.2').AsInteger =1 then
  begin
    image35.Visible :=true;
  end
  else
  begin
    image35.Visible :=false;
  end;
        if table1.FieldByName('Q4.3').AsInteger =1 then
  begin
    image36.Visible :=true;
  end
  else
  begin
    image36.Visible :=false;
  end;
     if errreadoutputpoint<>s_ok then
  begin
     timer1.Enabled :=false;
    showerror (errreadoutputpoint);
  end;
   datatype:=s7_word;
  s7prosim1.ReadOutputPoint(100,0,datatype,vdata);
  edit1.Text:=inttostr(round(vdata/10));
  edit3.Text:=inttostr(round(vdata/10));
  s7prosim1.ReadOutputPoint(102,0,datatype,vdata);
  edit2.Text:=inttostr(round(vdata/10));
  edit4.Text:=inttostr(round(vdata/10));
  s7prosim1.ReadOutputPoint(104,0,datatype,vdata);
  edit8.Text:=inttostr(round(vdata/10));
  edit6.Text:=inttostr(round(vdata/10));
  edit11.Text:=inttostr(round(vdata/10));
  edit10.Text:=inttostr(round(vdata/10));
  s7prosim1.ReadOutputPoint(106,0,datatype,vdata);
  edit7.Text:=inttostr(round(vdata/10));
  edit5.Text:=inttostr(round(vdata/10));
  edit9.Text:=inttostr(round(vdata/10));
  edit12.Text:=inttostr(round(vdata/10));
end;

以上代码为访问PLCSIM的具体代码,请问各位高手有没有直接访问PLC输入输出口与内部功能的更好方法,请赤脚!!

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值