大家好!
请哪位有DELPHI跟PLC与仪表通信的源码,如果有相关资料也行,如果分不够,我会再给的,在等待中、、、
请哪位有DELPHI跟PLC与仪表通信的源码,如果有相关资料也行,如果分不够,我会再给的,在等待中、、、
解决方案 »
- 刚入行,多指教
- ADO连接ORACLE出错
- 有关XPMenu的问题
- 求MMTools的Delphi XE2版可用的控件包!
- 针打能打印图形吗?怎么打?
- 在下载频道放了一个XE2开发的MapInfo电子地图,带有一个超级的ObjInspector,欢迎您下
- 那位前辈用过CODEWARP,这东西做什么的,好用吗
- 怎么使软盘不能复制? 但此软盘可读,最好有这类软件。
- 为什么DevExpress中的TCxLookupcombobox在开发BPL插件系统中,其EditValue的返回值是NULL。其他ExpressEditors中的控件情况也是一样?
- 如何动态建立构件,怎样访问它们?
- 招聘Delphi高手
- UIDstr := '000000';与UIDstr :=edit1.Text 之间的区别????
我以前做过华光的,在delphi下用的是VARIAN ASYNC32 COMPONENT 控件
有些厂家还会提供开发包,最好与你PLC家商联系
--------------------------------------------------------------------------------
#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;
}
还有是否 plc用了 其他通讯 模块