Visual Basic開發(fā)BACnet IP主站程序方法介紹
這里要說的方法就是調(diào)用BACnet IP主站快速開發(fā)工具OMBACnetIPMaster.dll。
步驟1、創(chuàng)建通道,而通道管理所有的Bacnet屬性對(duì)象。參數(shù)分別IP地址,端口號(hào)和網(wǎng)絡(luò)**時(shí)時(shí)間,默認(rèn)是100毫秒。
Private Sub OpenChannelButton_Click()
StringToByte txtIPAddress, IPAddress()
ChannelHandle(0) = CreateBacnetChannel(IPAddress(0), CLng(txtPort), 100)
End Sub
通道編輯操作的相關(guān)API函數(shù)聲明如下
‘ 通道管理用于創(chuàng)建、修改、刪除通道。創(chuàng)建通道以后,才能創(chuàng)建Bacnet屬性對(duì)象
‘ 創(chuàng)建一個(gè)通道對(duì)象只要是為了設(shè)置不同設(shè)備的IP地址和端口號(hào)。網(wǎng)絡(luò)**時(shí)等待時(shí)間默認(rèn)是100毫秒
Function CreateBacnetChannel Lib 'OMBacnetIPMaster.dll' Alias '_CreateChannel@12' (ByRef IPAddress As Byte, ByVal nPort As Long, ByVal nTimeOut As Long) As Long
Function ConfigureChannel Lib 'OMBacnetIPMaster.dll' Alias '_ConfigureChannel@16' (ByVal ChannelHandle As Long, ByRef IPAddress As Byte, ByVal nPort As Long, ByVal nTimeOut As Long) As Long
Function RemoveChannel Lib 'OMBacnetIPMaster.dll' Alias '_RemoveChannel@4' (ByVal ChannelHandle As Long) As Long
步驟2、創(chuàng)建Bacnet屬性對(duì)象。
Private Sub CreateBacnetObjButton_Click()
TagHandle(0) = CreateBacnetObj(ChannelHandle(0), 1, 1, 85)
End Sub
BACnet屬性對(duì)象編輯相關(guān)的API函數(shù)申明如下
‘ BACnet對(duì)象管理,創(chuàng)建、修改、刪除
‘參數(shù) ChannelHandle 為通道對(duì)象的句柄
‘參數(shù) nBacnetObjType 為Bacent屬性對(duì)象的類型ID,譬如0表示 Analog Input,1表示Analog Output
‘參數(shù) nInstanceNum 為指明哪一個(gè)對(duì)象,譬如要訪問Analog Input 1。則 nInstanceNum為1
‘參數(shù) nProperityID 為要訪問屬性的ID,譬如當(dāng)前值的屬性ID是85
‘參數(shù) TagHandle 為Bacnet對(duì)象的句柄
Function CreateBacnetObj Lib 'OMBacnetIPMaster.dll' Alias '_CreateBacnetObject@16' (ByVal ChannelHandle As Long, ByVal nBacnetObjType As Long, ByVal nInstanceNum As Long, ByVal nProperityID As Long) As Long
Function ConfigureObject Lib 'OMBacnetIPMaster.dll' Alias '_ConfigureObject@16' (ByVal ChannelHandle As Long, ByVal nBacnetObjType As Long, ByVal nInstanceNum As Long, ByVal nProperityID As Long) As Long
Function RemoveBacnetObject Lib 'OMBacnetIPMaster.dll' Alias '_RemoveBacnetObject@4' (ByVal TagHandle As Long) As Long
步驟3、BACnet屬性對(duì)象的讀寫
Private Sub WriteBacnetObjectButtton_Click()
error = WriteBacnetObj(TagHandle(0), CSng(Tag2.Text), 0)
End Sub
Private Sub ReadBacnetObjButton_Click()
Dim a As Variant
error = ReadBacnetObj(TagHandle(0), a)
Tag1.Text = a
End Sub
‘ BACnet對(duì)象屬性值讀寫
‘參數(shù) nTagNum 為Bacnet對(duì)象的Tag Number。也就是要寫的對(duì)象屬性的數(shù)據(jù)類型。當(dāng)操作過ReadBacnet以后,這個(gè)參數(shù)可以為空。
‘當(dāng)只寫操作的時(shí)候,則需要用戶自己指明是什么數(shù)據(jù)類型。譬如Analog Output為4.也就是單精度浮點(diǎn)型。
Function ReadBacnetObj Lib 'OMBacnetIPMaster.dll' Alias '_ReadBacnetObject@8' (ByVal TagHandle As Long, ByRef Value As Variant) As Long
Function WriteBacnetObj Lib 'OMBacnetIPMaster.dll' Alias '_WriteBacnetObject@12' (ByVal TagHandle As Long, ByRef Value As Variant, ByVal nTagNum As Long) As Long
步驟4、關(guān)閉程序時(shí),釋放對(duì)象資源。
Private Sub RemoveBacnetObjButton_Click()
error = RemoveBacnetObject(ByVal TagHandle(0))
End Sub
Private Sub RemoveChannelButton_Click()
error = RemoveChannel(ByVal ChannelHandle(0))
End Sub
最后討論一下輔助函數(shù)的作用
‘以下是輔助函數(shù),可以選擇性使用
‘設(shè)置寫操作的**等級(jí)
Function SetBacnetPriority Lib 'OMBacnetIPMaster.dll' Alias '_SetBacnetPriority@8' (ByVal TagHandle As Long, ByVal nPriority As Long) As Long
‘返回Bacnet對(duì)象屬性的數(shù)據(jù)類型,一般用于寫操作
Function GetBacnetObjType Lib 'OMBacnetIPMaster.dll' Alias '_GetBacnetObjType@4' (ByVal TagHandle As Long) As Long
‘通信故障狀況回調(diào)函數(shù)
Function EnableErrorMsgNofity Lib 'OMBacnetIPMaster.dll' Alias '_EnableErrorMsgNofity@4' (ByVal Callback As Long) As Long
Function EnableAbortMsgNofity Lib 'OMBacnetIPMaster.dll' Alias '_EnableAbortMsgNofity@4' (ByVal Callback As Long) As Long
Function EnableRejectMsgNofity Lib 'OMBacnetIPMaster.dll' Alias '_EnableRejectMsgNofity@4' (ByVal Callback As Long) As Long
|