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

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.