关于C#如何使用Prodave(实战DllImport)
2009-06-16 08:33:22 来源:WEB开发网严格意义上讲,此文不算OPC的范畴。起因是,另一个项目的PLC强人说,OPC慢,用prodave吧,好,用就用吧,装好Prodave看是看其英文资料,虽然英文不好,但好在这里英文很简单。好了,上网查了点资料,这里还要感谢几个朋友的帮忙,让我对于C#与C++的数据结构有了更进一步的认识,也学会了使用DllImport在本文的开头,我要说明下,Prodave是西门子的通信方式,即使我提供了Prodave6.dll,您不注册也是没用用的,所以请使用西门子的安装程序,哪里下载?自己百度一下。不要来问我哪里下载Prodave6.dll,也不要问我为什么程序会报错说没有注册dll
下面开始进入正文。
(1)上来第一个函数,就是连接PLC的LoadConnection_ex6,在说明书里描述如下:
LoadConnection_ex6
The basic LoadConnection_ex6 function initializes the adapter, checks if the
driver is loaded, initializes the addresses that have been assigned parameters and
activates the selected interface.
LoadConnection_ex6 is used to set up a transport connection via MPI/PB- or IP
addresses (TCP/IP protocol)
int LoadConnection_ex6 (int ConNr, char* pAccessPoint, int ConTableLen,
CON_TABLE_TYPE * pConTable);
Parameters
ConNr
[in] Number of the connection (max. 64 connections).
pAccessPoint
[in] access point (zero-terminated) of the driver used, e.g. "S7ONLINE" for the MPI
driver or 0 (default).
ConTableLen
[in] length of the table of connections provided by the user in bytes
pConTable
[in] pointer to address list of connected users; ‘Adr ==0’ is taken as the end mark of
the list.
#pragma pack(1)
typedef union {
unsigned char Mpi; // MPI/PB station address (2)
unsigned char Ip[4]; // IP address (192.168.0.1)
unsigned char Mac[6]; // MAC address (08-00-06-01-AA-BB)
} CON_ADR_TYPE;
typedef struct {
CON_ADR_TYPE Adr; // connection address
unsigned char AdrType; // Type of address: MPI/PB (1), IP (2), MAC (3)
unsigned char SlotNr; // Slot number
unsigned char RackNr; // Rack number
} CON_TABLE_TYPE;
#pragma pack(1)
更多精彩
赞助商链接