程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 關於C#如何使用Prodave(實戰DllImport)(1)

關於C#如何使用Prodave(實戰DllImport)(1)

編輯:關於C語言

嚴格意義上講,此文不算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)

好吧,起先其他的轉換網上都有 ,不難,但是出現了union共用體,恩C#沒有這個概念。怎麼辦?起先,參考網上的資料,采用

[StructLayout (LayoutKind.Explicit)]
struct S1
{
[FIEldOffset(0)]
int a;
[FIEldOffset(0)]
int b;
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved