服務(wù)熱線
4006-598-119
海灣DH-GST-COM電氣火災(zāi)監(jiān)控設(shè)備集成應(yīng)用編程接口
目 錄
3.2.2電氣火災(zāi)監(jiān)控設(shè)備復(fù)位
3.2.3電氣火災(zāi)監(jiān)控設(shè)備消音
3.2.4啟動電氣火災(zāi)監(jiān)控設(shè)備巡檢命令
4.1 VB編程環(huán)境中GstCom 的創(chuàng)建
4.2 VC編程環(huán)境中GstCom 的創(chuàng)建
4.3 C#編程環(huán)境中GstCom 的創(chuàng)建
4.4 Delphi編程環(huán)境中GstCom 的創(chuàng)建
海灣GSTCOM火災(zāi)報(bào)警控制器集成應(yīng)用軟件接口(以下簡稱接口)是用于第三方進(jìn)行系統(tǒng)集成的專用編程接口,它可與GST-DH9000電氣火災(zāi)監(jiān)控設(shè)備(以下簡稱電氣火災(zāi)監(jiān)控設(shè)備)進(jìn)行通訊。本接口為方便用戶進(jìn)行二次開發(fā),附帶了VB、VC、C#、Delphi編程樣例程序,供用戶參考。
Windows XP、Windows 7、Windows 10
軟件:本控件使用前需要對GstCom.Dll進(jìn)行注冊,安裝程序已經(jīng)自動將此控件注冊。
硬件:需要一塊與電氣火災(zāi)監(jiān)控設(shè)備相適應(yīng)的標(biāo)準(zhǔn)RS232通訊接口板,標(biāo)準(zhǔn)RS232通訊接口板與計(jì)算機(jī)用串口線連接。
將安裝文件拷貝到任意目錄下,運(yùn)行GstLDCom_Setup.exe 即可。
安裝完成后查看用戶選擇的安裝目錄下是否有如圖1文件。
圖1
目錄下的GstCom.Dll是GstCom消防通訊接口控件, GstComVbSample.exe是VB應(yīng)用程序,GstLDCom.doc文件為用戶手冊,Include目錄下為GstCom消防通訊接口控件在VC編程應(yīng)用環(huán)境下所需的頭文件,Samples目錄下為示例程序的源碼。
安裝完成后,開始菜單欄“程序”子菜單出現(xiàn)GstCom-> GstCom Test Sample。啟動系統(tǒng)能正常運(yùn)行。
用戶 次使用接口時(shí),若該控件未注冊,將彈出未注冊對話框。若用戶希望注冊該控件,請將注冊對話框中的用戶信息通過電話、Email、傳真等方式傳遞給我公司,我們將生成注冊碼傳給用戶,填入正確的注冊碼后,控件注冊成功。
OpenGstCom m_nCom, m_nControllerID, m_nProtocol, Resevered,lResult;
m_nCom 串口標(biāo)識變量的index;
m_nControllerID 電氣火災(zāi)監(jiān)控設(shè)備地址;
m_nProtocol 協(xié)議變量(即:電氣火災(zāi)監(jiān)控設(shè)備類型,數(shù)值如下);
200 表示GstDH9000中文通訊板
Resevered 保留參數(shù)(0);
LResult 返回狀態(tài)(參見返回狀態(tài)參數(shù)說明);
ResetController m_nControllerID, lResult;
m_nControllerID 電氣火災(zāi)監(jiān)控設(shè)備地址;
lResult 返回狀態(tài)(參見返回狀態(tài)參數(shù)說明);
MuteController m_nControllerID, lResult;
m_nControllerID 電氣火災(zāi)監(jiān)控設(shè)備地址;
lResult 返回狀態(tài)(參見返回狀態(tài)參數(shù)說明);
StartQuery m_nControllerID, nType,Reserved,lResult;
m_nControllerID 電氣火災(zāi)監(jiān)控設(shè)備地址;
nType 啟動類型;(0 停止查詢,2 啟動查詢)
Reserved 保留參數(shù)(0);
LResult 返回狀態(tài)(參見返回狀態(tài)參數(shù)說明);
CloseGstCom m_nControllerID,lResult;
m_nControllerID 電氣火災(zāi)監(jiān)控設(shè)備地址;
LResult 返回狀態(tài)(參見返回狀態(tài)參數(shù)說明);
返回狀態(tài)參數(shù)說明如表1.
表1
返回參數(shù) | 說明 |
LResult=0 (RET_Successfu)l | 命令執(zhí)行成功 |
LResult=1 (RET_Busy) | 電氣火災(zāi)監(jiān)控設(shè)備忙 |
LResult =2 (RET_ParamInvalide) | 參數(shù)非法 |
LResult =3 (RET_ShakeHandFail) | 通訊握手失敗 |
LResult =4 (RET_GstComError) | 命令執(zhí)行內(nèi)部錯(cuò)誤 |
LResult =5 (RET_ReplyError) | 命令執(zhí)行應(yīng)答錯(cuò)誤 |
LResult =6 (RET_ReplyTimeout) | 命令發(fā)送應(yīng)答超時(shí) |
LResult =10 (RET_Rs232Error) | 串口打開失敗 |
LResult =255(RET_NotCommand) | 不支持此命令 |
UpLDDeviceCurrent nControllerID, nLoop, nAddress, lCurrent, pResult
m_nControllerID 電氣火災(zāi)監(jiān)控設(shè)備地址;
nLoop 回路號;
nAddress 一次碼;
lCurrent 返回電流值;
lResult 返回狀態(tài)(參見返回狀態(tài)參數(shù)說明);
UpLDDeviceTemperature ControllerID, nLoop, nAddress, lCurrent, pResult
m_nControllerID 電氣火災(zāi)監(jiān)控設(shè)備地址;
nLoop 回路號;
nAddress 一次碼;
lCurrent 返回溫度值;
lResult 返回狀態(tài)(參見返回狀態(tài)參數(shù)說明);
GstCom_AlarmEvent(ByVal nControllerID As Long, ByVal nEventType As Long, ByVal
bstrDeviceID As String, ByVal Value As Long)
nControllerID 電氣火災(zāi)監(jiān)控設(shè)備地址;
nEventType 事件的類型;
bstrDeviceID 相關(guān)設(shè)備編碼(設(shè)備二次碼);
Value 對應(yīng)事件類型的相關(guān)數(shù)據(jù);
參數(shù)詳細(xì)描述如表2。
表2
事件的類型 (nEventType) | 相關(guān)設(shè)備編碼(bstrDeviceID) | 對應(yīng)事件類型的相關(guān)數(shù)據(jù)(Value ) | 說明 |
AE_CommNormal (0) | --------- | ---------- | 消防系統(tǒng)正常,無報(bào)警、故障等信息 |
AE_CommRetryFault (2) | ---------- | --------- | 應(yīng)答錯(cuò)誤 |
AE_CommTimeout (1) | ------------ | ----------- | 超時(shí)錯(cuò)誤 |
AE_ControllerReset(3) | ------------ | ------------ | 電氣火災(zāi)監(jiān)控設(shè)備消音復(fù)位 |
AE_ControllerStatus(4) | Value=狀態(tài)代碼:(H->L) bit7-自動 (1允許, 0不允許) bit6-手動 (1允許, 0不允許) bit5-噴灑 (1允許, 0不允許) 狀態(tài)代碼低四位值為: 1H 主電故障 2H 主電恢復(fù) 3H 備電故障 4H 備電恢復(fù) 5H 開機(jī) 例如: 67 表示 手動允許,備電故障 | 電氣火災(zāi)監(jiān)控設(shè)備消音狀態(tài)置位 | |
AE_ControllerMute (5) | ------------ | ------------ | 電氣火災(zāi)監(jiān)控設(shè)備消音 |
AE_DeviceRestore (8) | 設(shè)備編碼 | ------------ | 設(shè)備恢復(fù) |
AE_DeviceAlarm (16) | 設(shè)備編碼
| ------------ | 設(shè)備報(bào)警 |
AE_DeviceStart (32) | 設(shè)備編碼 | ------------ | 設(shè)備啟動 |
AE_DeviceStop (64) | 設(shè)備編碼 | ------------ | 設(shè)備停止 |
AE_DeviceAction (128) | 設(shè)備編碼 | ------------ | 設(shè)備動作 |
AE_DeviceFault (256) | 設(shè)備編碼
| Value=1:一般故障 Value=2:設(shè)備損壞故障 Value=4: 停電故障Value=8: 傳感器故障 | 設(shè)備故障 |
AE_DeviceIsolate (512) | 設(shè)備編碼 | ---------- | 設(shè)備隔離 |
AE_DeviceRelease (1024) | 設(shè)備編碼 | ---------- | 設(shè)備釋放 |
l 在VB編程環(huán)境中引用GstCom控件;
l 在應(yīng)用程序頭部定義GstCom,如:Public WithEvents MyGstCom As GstComCtl;
l 在程序初始化階段,創(chuàng)建GstCom對象,如:Set MyGstCom = New GstComCtl。
l 在應(yīng)用程序的頭文件中加入如下文件
#include "GstCom.h"
#include "GstComDefines.h"
#include "GstComEventSink.h"
l 在應(yīng)用程序的代碼文件中加入如下文件
#include "GstCom_i.c"
l 在應(yīng)用程序中定義GstCom的引用及相關(guān)變量,
IGstComCtl *m_IGstComCtl;
CGstComEventSink* m_pGstComEventSink;
IUnknown* m_pControlUnk;
l 在應(yīng)用程序中創(chuàng)建接口實(shí)例
HRESULT hr;
hr = CoInitialize(0);
hr = CoCreateInstance( CLSID_GstComCtl , NULL, CLSCTX_INPROC_SERVER,
IID_IGstComCtl, (void**) &m_IGstComCtl);
if (!SUCCEEDED(hr))
{
AfxMessageBox("CoCreateInstance Failed.");
return FALSE;
}
m_IGstComCtl->QueryInterface(IID_IGstComCtl, (void**)&m_pControlUnk);
m_pGstComEventSink = new CGstComEventSink();
if (m_pGstComEventSink)
hr = m_pGstComEventSink->DispEventAdvise(m_pControlUnk);
else
AfxMessageBox("Event Creater Failed.");
執(zhí)行成功后應(yīng)用程序就會得到GstCom的引用m_IGstComCtl。同時(shí)用戶將報(bào)警事件處理代碼添加到GstComEventSink.h文件的“用戶代碼”處
l 應(yīng)用程序退出,斷開連接釋放資源:
m_pIRayRtdb->Release(); //一定要釋放,否則退出時(shí),會有內(nèi)存泄露
m_pIUnknown->Release(); //一定要釋放,否則退出時(shí),會有內(nèi)存泄露
if(m_pRtdbEventSink)
delete m_pRtdbEventSink;
CoUninitialize();
if (m_pGstComEventSink)
{
m_pGstComEventSink->DispEventUnadvise(m_pControlUnk);//斷開事件
m_pControlUnk->Release(); //釋放查詢指針
delete m_pGstComEventSink;//刪除事件接收對象
}
if (m_IGstComCtl)
m_IGstComCtl->Release();
l 在C#的“解決方案資源管理器中”引用GstCom.dll控件,在“引用”中可得到GSTCOMLIB庫。
l 在應(yīng)用程序頭部定義GstCom,即:using GSTCOMLIB;
l 在程序初始化階段,創(chuàng)建GstComCtl對象,即:
GstComCtl myGstComCtl=new GstComCtl();
myGstComCtl.OpenGstCom(m_nCom, m_nControllerID, m_nProtocol, 100, out hResult);
用于打開COM接口,在調(diào)用方法的時(shí)候傳進(jìn)參數(shù)的類型必須和要求的一致。
l 在應(yīng)用程序中創(chuàng)建事件響應(yīng)
處理COM 接口的事件時(shí)需要引入下列代碼:
gstComCtl.AlarmEvent +=new
_IGstComCtlEvents_AlarmEventEventHandler(gstComCtl_AlarmEvent);
創(chuàng)建時(shí)間處理方法gstComCtl_AlarmEvent,如:
private void gstComCtl_AlarmEvent(byte nCom, int nControllerID, int nEventType, string bstrDeviceID, int Value)
{
//用戶代碼
}
l 在Delphi的引用GstCom.dll控件,得到GStCOMLib_TLB庫。即:注冊GstCom.dll—>打開Delphi7—>component—>Impot ActiveX Contrl—>選擇GstCom1.0 Type Library—>createUnit。得到GStCOMLib_TLB;
l 在應(yīng)用程序頭部使用GStCOMLib_TLB、,即:uses GStCOMLib_TLB,ComObj;
l 在程序初始化階段,創(chuàng)建GstComCtl對象,即:
var
GstComCtl : IGstComCtl;
GstComCtl:=CreateComObject(CLASS_GstComCtl) as IGstComCtl;