西门子Prodave5.5使用说明及VC示例

本文介绍了Prodave作为早期西门子PLC通信接口的应用情况,包括其版本历史、特点及与不同型号PLC的兼容性。文中还提供了一个基于VC的测试程序示例,展示了如何使用Prodave进行读写操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2007年08月15日 23:24:00

西门子PLC的通信协议主要是PPI、MPI、Profibus、CP243/CP343/CP443 网络协议,prodave是早期完成的程序接口,除了网络协议外其它的主要协议都支持,SoftNet是西门子最新推出的通信协议接口,稳定,并且大而全,目前西门子所有主流的协议都支持(我的blog文章:西门子Softnet驱动的成功开发已经做了简单介绍),由于好多朋友对prodave都比较关注,所以我这里专门写篇blog来简单介绍一下。

我所知道的最新的Prodave的版本是V5.5,完整版的要45兆左右,由于出的比较早,所以动态库"W95_s7.dll"的名称保留至今,我最早接触是在01~02年,不过当时版本好像不到V5.5,与S7-200通信很不稳定,并且访问周期比较长。给我的感觉Prodave好像专门为S7-300制作的(从库函数的声明可以看出),连S7-300相对而言比较顺利。

组态王、力控好多主流工控软件访问西门子PLC都是通过Prodave或Softnet的,可以在驱动程序中看到熟悉的W95_s7.dll,所以通信能力大家还是应该放心的。

题外话,对嵌入式系统,如WinCE,由于不能直接使用Prodave和Softnet,所以要实现与西门子PLC通信,一般只有破解了(西门子的通信协议都是保密的,并且也是加密的,一般不公开给客户),目前实现的较好的主要有PPI,MPI(需要MPI适配器,不同适配器通信协议有一定区别),CP243,CP343/CP443。

下面是我在开发相关西门子通信程序时,做的一个VC测试程序,仅供参考(Prodave简版驱动和相关测试代码,我已经上传,文章后面附下载连接)。

void CTestDlg::OnProdave()
{
int iRes;
CString myStr;
signed
char Buffer[ 2048 ];

WORD
* Buffer_int = (WORD * )Buffer;
unsigned
char * Buffer_byte = (unsigned char * )Buffer; // WORD wValue;

// m_field_read MB200
iRes = m_field_read( 200 , 1 ,Buffer);

if (iRes == 0 )
{
m_Dis.SetSel(
100000 , 100000 );
m_Dis.ReplaceSel(
" " );

myStr.Format(
" MB200=%3d " ,Buffer_byte[ 0 ]);
m_Dis.ReplaceSel(myStr);

UpdateData(
false );
}
else
{
// myStr.Format("m_field_read error no:%d",iRes);
AfxMessageBox(ErrString(iRes));
}

// m_field_read
iRes = m_field_read( 100 , 1 ,Buffer);

if (iRes == 0 )
{
m_Dis.SetSel(
100000 , 100000 );
m_Dis.ReplaceSel(
" " );
myStr.Format(
" MB100=%3d " ,Buffer_byte[ 0 ]);

m_Dis.ReplaceSel(myStr);

UpdateData(
false );
}
else
{
AfxMessageBox(ErrString(iRes));
}

// m_field_read
iRes = a_field_read( 0 , 1 ,Buffer);

if (iRes == 0 )
{
m_Dis.SetSel(
100000 , 100000 );
m_Dis.ReplaceSel(
" " );
myStr.Format(
" QB0=%3d " ,Buffer_byte[ 0 ]);

m_Dis.ReplaceSel(myStr);

UpdateData(
false );
}
else
{
AfxMessageBox(ErrString(iRes));
}

// 写数据 MB110
unsigned long value;
value
= 100 ;
memcpy(Buffer,
& value, 4 );

iRes
= m_field_write( 111 , 1 ,Buffer);
if (iRes == 0 )
{
m_Dis.SetSel(
100000 , 100000 );
m_Dis.ReplaceSel(
" " );
myStr.Format(
" MB110=%3d " ,Buffer[ 0 ]);
m_Dis.ReplaceSel(myStr);
UpdateData(
false );
}
else
{
AfxMessageBox(ErrString(iRes));
}

// 写数据 MB4
BYTE value1;
value1
= 33 ;
memcpy(Buffer,
& value, 1 );
iRes
= m_field_write( 4 , 1 ,Buffer);
if (iRes == 0 )
{
m_Dis.SetSel(
100000 , 100000 );
m_Dis.ReplaceSel(
" " );
myStr.Format(
" MD4=%3d " ,Buffer[ 0 ]);
m_Dis.ReplaceSel(myStr);
UpdateData(
false );
}
else
{
AfxMessageBox(ErrString(iRes));
}
}

void CTestDlg::OnLoad()
{
adr_table_type myTable[
2 ];
myTable[
0 ].adr = 3 ;
myTable[
0 ].segmentid = 0 ;
myTable[
0 ].slotno = 2 ;
myTable[
0 ].rackno = 0 ;
myTable[
1 ].adr = 0 ;
myTable[
1 ].segmentid = 0 ;
myTable[
1 ].slotno = 2 ;
myTable[
1 ].rackno = 0 ;
int iRes;
CString myStr;
// 初始化ProDave300
iRes = load_tool( 1 , " S7ONLINE " ,myTable);
if (iRes == 0 )
{
m_Dis.SetSel(
30000 , 30000 );
m_Dis.ReplaceSel(
" " );
m_Dis.ReplaceSel(
" load_tool ok! " );
UpdateData(
false );
}
else
{
AfxMessageBox(ErrString(iRes));
unload_tool();
return ;
}
}

void CTestDlg::OnUnloadtool()
{
int iRes;
CString myStr;
iRes
= unload_tool();
if (iRes == 0 )
{
m_Dis.SetSel(
30000 , 30000 );
m_Dis.ReplaceSel(
" " );
m_Dis.ReplaceSel(
" unload_tool ok! " );
m_Dis.ReplaceSel(
" " );
UpdateData(
false );
}
else
{
AfxMessageBox(ErrString(iRes));
}
}

void CTestDlg::OnStatus()
{
int iRes;
CString myStr;
char myInfo[ 512 ];
iRes
= ag_zustand(myInfo);
if (iRes == 0 )
{
m_Dis.SetSel(
30000 , 30000 );
m_Dis.ReplaceSel(
" " );
m_Dis.ReplaceSel(
" ag_zustand ok! " );
UpdateData(
false );
if (myInfo[ 0 ] == 0 )
{
m_Dis.ReplaceSel(
" " );
m_Dis.ReplaceSel(
" RUN " );
}
else
{
m_Dis.ReplaceSel(
" " );
m_Dis.ReplaceSel(
" STOP " );
}
UpdateData(
false );
}
else
{
AfxMessageBox(ErrString(iRes));
}
}
LPSTR CTestDlg::ErrString(WORD wErrCode)
{
LPSTR myStr1;
switch (wErrCode)
{
case 517 :
{
return " PRODAVE not initialized. " ;
break ;
}
case 787 :
{
return " Incorrect rate/Interrupt vector. " ;
break ;
}
case 789 :
{
return " MPI Address error. " ;
break ;
}
case 800 :
case 818 :
{
return " hardware fault. " ;
break ;
}
case 820 :
{
return " com not avaliable. " ;
break ;
}
case 898 :
case 900 :
{
return " no driver or device found. " ;
break ;
}
case 16386 :
{
return " Connection not established. " ;
break ;
}
default :
{
CString myStr;
myStr.Format(
" %d " ,wErrCode);
myStr1
= myStr.GetBuffer( 0 );
myStr.ReleaseBuffer();
return myStr1;
}
}
}

void CTestDlg::OnNewss()
{
// 激活连接
int iRes;
iRes
= new_ss( 1 );
if (iRes == 0 )
{
m_Dis.SetSel(
100000 , 100000 );
m_Dis.ReplaceSel(
" " );
m_Dis.ReplaceSel(
" new_ss ok! " );
UpdateData(
false );
}
else
{
AfxMessageBox(ErrString(iRes));
unload_tool();
return ;
}
}

void CTestDlg::OnAginfo()
{
// 读PLC信息
int iRes;
char myInfo[ 512 ];
iRes
= ag_info( & myInfo[ 0 ] );
if (iRes == 0 )
{
m_Dis.SetSel(
100000 , 100000 );
m_Dis.ReplaceSel(
" " );
m_Dis.ReplaceSel(
" ag_info ok! " );
UpdateData(
false );

m_Dis.ReplaceSel(
" " );
m_Dis.ReplaceSel(
& myInfo[ 4 ]);

UpdateData(
false );
}
else
{
AfxMessageBox(ErrString(iRes));
unload_tool();
return ;
}
}

prodave 测试程序:http://download.youkuaiyun.com/source/228758

Prodave简版驱动:http://download.youkuaiyun.com/source/228765



Trackback: http://tb.blog.youkuaiyun.com/TrackBack.aspx?PostId=1745782


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值