大家好!
  请哪位有DELPHI跟PLC与仪表通信的源码,如果有相关资料也行,如果分不够,我会再给的,在等待中、、、

解决方案 »

  1.   

    plc看型号了 摸过段时间  看接口 和协议 串口 rs232 网口 ==  协议不过一般都是保密的。。有的 plc也提供想过的软件接口
      

  2.   

    卖plc的都有卖软件的呀,搞个盗版用用也行!你的是?型号
      

  3.   

    每个PLC厂家,都有不同的通讯协议,一般用RS232且在PLC厂家的说明书中都有
    我以前做过华光的,在delphi下用的是VARIAN ASYNC32 COMPONENT 控件
    有些厂家还会提供开发包,最好与你PLC家商联系
      

  4.   

    我找到了99年我用BCB写的与PLC通讯的一段程序,供参考(BCB很容易转成delphi的,其中 mycomm为VARIAN ASYNC32 COMPONENT 控件)
    --------------------------------------------------------------------------------
    #define ENQ 0x05
    #define SOH 0x01
    #define ETB 0x17
    #define STX 0x02
    #define ACK 0x06
    #define NAK 0x15
    #define ETX 0x03
    #define EOT 0x04struct  S_SOH {
      char soh;
      char pcno[2];  // 子局号
      char direct; //方向
      char func;  //功能
      char addr[4]; //地址
      char datalen[4]; //数据量
      char mainno[2];  //主局号
      char etb;
      char lrc;
    } mys = {
             SOH,
             {'0','1'},   // PLC no
             '0',    // dircct
             '0',    // function
             { '0','0','0','0' },  // address
             { '0','0','0','0' },  // len
             {'0','1' },           // computer no
             ETB,                  //etb
             0                     //lrc
    }  ;bool commreadstat=true;
    bool curcommstat=false;
    bool begcommstat=false;
    TForm *curform;
    char callid[]={0x4e,0x21,5};
    readplcdata(char func,char *addr,char *datalen,
                          unsigned char *destbuff)
    {
       unsigned char buff[40];
       int i,Count,len,rellen;
       char *p;   try {
    //  send hand signal
             mycomm->Write(callid,3);
    // get PLC ack
             Count=3;
             commtimeout->Enabled=true;
             while(commreadstat && ((len=mycomm->Read(buff,Count))<=0))
                  Application->ProcessMessages();
             commtimeout->Enabled=false;
             if (!commreadstat)
                throw -1;
             if (!(len==3 && buff[0]=='N' && buff[1]==0x21 && buff[2]==0x06))
                throw -1;
    // begin to read data
    // send SOH
             mys.direct='0';    //read
             mys.func=func;
             mys.addr[0]=addr[0];
             mys.addr[1]=addr[1];
             mys.addr[2]=addr[2];
             mys.addr[3]=addr[3];
             mys.datalen[0]=datalen[0];
             mys.datalen[1]=datalen[1];
             mys.datalen[2]=datalen[2];
             mys.datalen[3]=datalen[3];
             mys.lrc=0;
             p = (char *)&mys;
             for(i=1;i<=14;i++)
                mys.lrc ^= *(p+i);
             mycomm->Write(p,17);
    // get PLC ack
             Count=1;
             commtimeout->Enabled=true;
             while(commreadstat && ((len=mycomm->Read(buff,Count))<=0))
                  Application->ProcessMessages();
             commtimeout->Enabled=false;
             if ((!commreadstat) || (buff[0]!=ACK))
                throw -1;
    // get PLC data
             rellen=StrToInt((String)"0x"+datalen);         Count=30;
             commtimeout->Enabled=true;
             while(commreadstat && ((len=mycomm->Read(buff,Count))<=0))
                  Application->ProcessMessages();
             commtimeout->Enabled=false;
             if (!commreadstat || (buff[0]!=STX))
                throw -1;
             rellen=StrToInt((String)"0x"+datalen);
             i=1;
             if (rellen<=len-3)
                memmove(destbuff,buff+1,len-3);
                else
                  {
                     rellen-=(len-1);  // ingrno STX
                     memmove(destbuff,buff+1,len-1);
                     destbuff+=(len-1);
                     while(rellen>7)
                        {
                           i++;
                           Count=30;
                           commtimeout->Enabled=true;
                           while(commreadstat && ((len=mycomm->Read(buff,Count))<=0))
                               Application->ProcessMessages();
                           commtimeout->Enabled=false;
                           if (!commreadstat)
                              throw -1;
                           rellen-=len;
                           memmove(destbuff,buff,len);
                           destbuff+=len;
                         }
                       Count=6;
                       commtimeout->Enabled=true;
                       while(commreadstat && ((len=mycomm->Read(buff,Count))<=0))
                            Application->ProcessMessages();
                       commtimeout->Enabled=false;
                       if (!commreadstat)
                           throw -1;
                       memmove(destbuff,buff,rellen);
                  }// send ACK to PLC
             buff[0]=ACK;
             mycomm->Write(buff,1);
    // get EOT from PLC
             Count=1;
             commtimeout->Enabled=true;
             while(commreadstat && ((len=mycomm->Read(buff,Count))<=0))
                  Application->ProcessMessages();
             commtimeout->Enabled=false;
             if ((!commreadstat) || (buff[0]!=EOT))
                throw -1;
    // send EOT to PLC
             mycomm->Write(buff,1);
             return true;
      }
      

  5.   

    S7-200  可以用 rs232方式 或者用西门子提供的软件
    还有是否 plc用了 其他通讯 模块