求助:C#使用prodave S7_6.2与西门子S7-300PLC以太网通讯
流火火 2016-09-29 09:52:25 前提:
本人已经在网上找到了相关的方法,但是在执行LoadConnection_ex6进行连接时,总是不成功,返回的int型代码也不知道含义.已经安装并授权prodave.请问还有什么注意的地方?PLC相关的机架号及槽号设置都正确,IP地址没问题.代码如下:
int ConNr1 = 0; // First connection;(0 63);(max. 64 connections).
string AccessPoint1 = "S7ONLINE"; // Default access point——S7ONLINE
Prodave6.CON_TABLE_TYPE pConTable1; //这是结构体
int ConTableLen1 = System.Runtime.InteropServices.Marshal.SizeOf(typeof(Prodave6.CON_TABLE_TYPE)); // Length of the connection table
pConTable1.Adr = new byte[] { 192, 168, 1, 2, 0, 0 };
pConTable1.AdrType = 2;
pConTable1.SlotNr = 2;
pConTable1.RackNr = 0;
int errcode = Prodave6.LoadConnection_ex6(ConNr1, AccessPoint1, ConTableLen1, ref pConTable1); //建立PLC连接
//以下测试SetActiveConnection_ex6
UInt16 UConNr = (UInt16)ConNr1;
errcode = Prodave6.SetActiveConnection_ex6(UConNr);
if (errcode == 0)
{
label1.Text = "PLC连接成功";
}
else
{
label1.Text = "PLC连接失败";
}