DELPHI访问PLC输出口

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

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 :=tru

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值