Website News (20/2)
DNS Severs should be
working fine now. If you
run into any issues please
feel free to contact us.
DNS Severs should be
working fine now. If you
run into any issues please
feel free to contact us.
VB6 for Dahua NET SDK
Updated January 13th, 2012
Updated January 13th, 2012
This is a sample VB6 module for the Dahua NET SDK.
The SDK can be downloaded here: Version 3.37
Contact us with feedback, questions, or errors. You may also send requests for additional features but there is no guarantee we can provide them at this time.
Some of the following code is included with the SDK.
Table of Contents
1. Updates
2. VB6 Module Code
3. Login, Play, and Exit
4. Auto Reconnect
5. Login Errors
6. Get Channel Count
7. PTZ Control
8. Audio Stream
9. Record DAV File
10. Saving Image
11. Get Camera Title
12. Get All Camera Titles
13. Get Record Status
14. Get All Record Status
15. Get Device Alarms
16. Get Alarm Status
17. Get All Alarm Status
18. Get Motion Status
19. Get All Motion Status
20. Get Video Loss Status
21. Get All Video Loss Status
Jan 13, 2012 - Examples added for Auto Reconnect and Login Errors
Jan 13, 2012 - Changed Login Error code, added Error Strings
Jan 13, 2012 - Changed EN_DVR to EN_DH, as this code is for DVR/IPC
Jan 13, 2012 - Added Auto Reconnect and Connect Time functions
Jan 11, 2012 - Changed MessFunc variable pchDVRIP to Long
Dec 02, 2011 - Changed DDNS2IP.dll to DNS2IP.dll for 32/64bit
Dec 02, 2011 - Added separate GetDDNS function used in ConnectX
Nov 22, 2011 - Fixed link to SDK download
Nov 22, 2011 - Fixed samples where it did not match new module code
This is for Visual Basic 6 only.
Option Explicit
'// VB6 CODE FOR DAHUA NETWORK SDK
'// AUTHOR: RORY KNOWLES, NASSAU BAHAMAS
'// EDIT: 07:00PM EST-5 01/13/12
'// REFERENCE DNS2IP.dll for ConnectX()
'// OR include DNS2IP class (cDNS2IP.cls)
'// Depends on ws2_32.dll (winsock)
'// SDK Initialization
Public Declare Function CLIENT_Init Lib "dhnetsdk.dll" (ByVal fDisConnect As Long, ByVal dwUser As Long) As Boolean
'// SDK exit and clear
Public Declare Sub CLIENT_Cleanup Lib "dhnetsdk.dll" ()
'// Set re-connection callback function after disconnection. Internal SDK auto connect again after disconnection
Public Declare Sub CLIENT_SetAutoReconnect Lib "dhnetsdk.dll" (ByVal fMessCallBack As Long, ByVal dwUser As Long)
'// Return the function execution failure code
Public Declare Function CLIENT_GetLastError Lib "dhnetsdk.dll" () As Long
'// Set device connection timeout value and trial times
Public Declare Sub CLIENT_SetConnectTime Lib "dhnetsdk.dll" (ByVal nWaitTime As Long, ByVal nTryTimes As Long)
'// Get SDK version information
Public Declare Function CLIENT_GetSDKVersion Lib "dhnetsdk.dll" () As Long
'// Register to the device
Public Declare Function CLIENT_Login Lib "dhnetsdk.dll" (ByVal pchDVRIP As String, ByVal wDVRPort As Long, ByVal pchUserName As String, ByVal pchPassword As String, lpDeviceInfo As NET_DEVICEINFO, ByRef lpError As EN_DH_LOGIN_ERROR) As Long
'// Log out the device
Public Declare Function CLIENT_Logout Lib "dhnetsdk.dll" (ByVal lLoginID As Long) As Boolean
'// Begin real-time monitor
Public Declare Function CLIENT_RealPlay Lib "dhnetsdk.dll" (ByVal lLoginID As Long, ByVal nChannelID As Long, ByVal hwnd As Long) As Long
'// Begin real-time monitor--extensive
Public Declare Function CLIENT_RealPlayEx Lib "dhnetsdk.dll" (ByVal lLoginID As Long, ByVal nChannelID As Long, ByVal hwnd As Long, ByVal rType As Long) As Long
'// Snapshot
Public Declare Function CLIENT_CapturePicture Lib "dhnetsdk.dll" (ByVal lMonitorID As Long, ByVal pchPicFileName As String) As Boolean
'// Set video fluency
Public Declare Function CLIENT_AdjustFluency Lib "dhnetsdk.dll" (ByVal lMonitorID As Long, ByVal nLevel As Long) As Boolean
'// Save data as DAV file
Public Declare Function CLIENT_SaveRealData Lib "dhnetsdk.dll" (ByVal lMonitorID As Long, ByVal pchFileName As String) As Boolean
'// Stop saving data as DAV file
Public Declare Function CLIENT_StopSaveRealData Lib "dhnetsdk.dll" (ByVal lMonitorID As Long) As Boolean
'// Open audio
Public Declare Function CLIENT_OpenSound Lib "dhnetsdk.dll" (ByVal lMonitorID As Long) As Boolean
'// Set volume
Public Declare Function CLIENT_SetVolume Lib "dhnetsdk.dll" (ByVal lMonitorID As Long, ByVal nVolume As Long) As Boolean
'// Stop audio
Public Declare Function CLIENT_CloseSound Lib "dhnetsdk.dll" () As Boolean
'// Stop real-time preview
Public Declare Function CLIENT_StopRealPlay Lib "dhnetsdk.dll" (ByVal lMonitorID As Long) As Boolean
'// stop real-time preview-extensive
Public Declare Function CLIENT_StopRealPlayEx Lib "dhnetsdk.dll" (ByVal lMonitorID As Long) As Boolean
'// general PTZ control
Public Declare Function CLIENT_PTZControl Lib "dhnetsdk.dll" (ByVal lLoginID As Long, ByVal nChannelID As Long, ByVal dwPTZCommand As EN_DH_CONTROLTYPE, ByVal dwStep As Long, ByVal dwStop As Boolean) As Boolean
'// Set alarm callback fucntion
Public Declare Sub CLIENT_SetDVRMessCallBack Lib "dhnetsdk.dll" (ByVal fMessCallBack As Long, ByVal dwUser As Long)
'// subscribe alarm
Public Declare Function CLIENT_StartListen Lib "dhnetsdk.dll" (ByVal lLoginID As Long) As Boolean
'// subscribe alarm---extensive
Public Declare Function CLIENT_StartListenEx Lib "dhnetsdk.dll" (ByVal lLoginID As Long) As Boolean
'// Stop subscribe alarm
Public Declare Function CLIENT_StopListen Lib "dhnetsdk.dll" (ByVal lLoginID As Long) As Boolean
'// Begin PC record
Public Declare Function CLIENT_RecordStart Lib "dhnetsdk.dll" () As Boolean
'// Stop PC record
Public Declare Function CLIENT_RecordStop Lib "dhnetsdk.dll" () As Boolean
'// add device into broadcast group
Public Declare Function CLIENT_AudioBroadcastAddDev Lib "dhnetsdk.dll" (ByVal lLoginID As Long) As Boolean
'// Remove device from the broadcast group
Public Declare Function CLIENT_AudioBroadcastDelDev Lib "dhnetsdk.dll" (ByVal lLoginID As Long) As Boolean
'// audio encode--complete and then exit
Public Declare Function CLIENT_ReleaseAudioEncode Lib "dhnetsdk.dll" () As Long
'// Search channel record staus
Public Declare Function CLIENT_QueryRecordState Lib "dhnetsdk.dll" (ByVal lLoginID As Long, ByRef pRSBuffer As String, ByVal maxlen As Long, ByRef nRSBufferlen As Long, ByVal waittime As Long) As Long
'// Search device status
Public Declare Function CLIENT_QueryDevState Lib "dhnetsdk.dll" (ByVal lLoginID As Long, ByVal nType As Long, ByRef pBuf As String, ByVal nBufLen As Long, ByRef pRetLen As Long, ByVal waittime As Long) As Boolean
Public Declare Function CLIENT_QueryAlarmState Lib "dhnetsdk.dll" Alias "CLIENT_QueryDevState" (ByVal lLoginID As Long, ByVal nType As Long, ByRef pBuf As NET_CLIENT_STATE, ByVal nBufLen As Long, ByRef pRetLen As Long, ByVal waittime As Long) As Boolean
'// Get channel bit stream
Public Declare Function CLIENT_GetStatiscFlux Lib "dhnetsdk.dll" (ByVal lLoginID As Long, ByVal lMonitorID As Long) As Long
'// Reboot device
Public Declare Function CLIENT_RebootDev Lib "dhnetsdk.dll" (ByVal lLoginID As Long) As Boolean
'// Shut down device
Public Declare Function CLIENT_ShutDownDev Lib "dhnetsdk.dll" (ByVal lLoginID As Long) As Boolean
'// Compulsive Iframe
Public Declare Function CLIENT_MakeKeyFrame Lib "dhnetsdk.dll" (ByVal lLoginID As Long, ByVal nChannelID As Long, ByVal nSubChannel As Long) As Boolean
'// Search device channel name
Public Declare Function CLIENT_QueryChannelName Lib "dhnetsdk.dll" (ByVal lLoginID As Long, ByRef pChannelName As String, ByVal maxlen As Long, ByRef nChannelCount As Long, ByVal waittime As Long) As Boolean
'// PTZ Control
'dwStep = Step/Speed. ranges from 1 to 8. 8 has the highest control capability
'dwStep is the preset value when you use preset function
'dwStop = Whether stop or not. It applies to PTZ direction and lens operation
'When you operate other functions, input this parameter as FALSE
Public Enum EN_DH_CONTROLTYPE
DH_PTZ_UP_CONTROL = 0 '// Up
DH_PTZ_DOWN_CONTROL '// Down
DH_PTZ_LEFT_CONTROL '// Left
DH_PTZ_RIGHT_CONTROL '// Right
DH_PTZ_ZOOM_ADD_CONTROL '// +Zoom in
DH_PTZ_ZOOM_DEC_CONTROL '// -Zoom out
DH_PTZ_FOCUS_ADD_CONTROL '// +Zoom in
DH_PTZ_FOCUS_DEC_CONTROL '// -Zoom out
DH_PTZ_APERTURE_ADD_CONTROL '// + Aperture
DH_PTZ_APERTURE_DEC_CONTROL '// -Aperture
DH_PTZ_POINT_MOVE_CONTROL '// Go to preset
DH_PTZ_POINT_SET_CONTROL '// Set
DH_PTZ_POINT_DEL_CONTROL '// Delete
DH_PTZ_POINT_LOOP_CONTROL '// Tour
DH_PTZ_LAMP_CONTROL '// Light and wiper
End Enum
'stop start ptz
Public Enum EN_DH_PTZSTOP
DH_PTZ_START = 0
DH_PTZ_STOP
End Enum
'ptz step speed
Public Enum EN_DH_PTZSTEP
DH_PTZ_STEP1 = 1
DH_PTZ_STEP2 = 2
DH_PTZ_STEP3 = 3
DH_PTZ_STEP4 = 4
DH_PTZ_STEP5 = 5
DH_PTZ_STEP6 = 6
DH_PTZ_STEP7 = 7
DH_PTZ_STEP8 = 8
End Enum
'// Fluency level
Public Enum EN_DH_FLUENCY
DH_FLUENCY_0 = 0
DH_FLUENCY_1
DH_FLUENCY_2
DH_FLUENCY_3
DH_FLUENCY_4
DH_FLUENCY_5
DH_FLUENCY_6
End Enum
'// Quality
Public Enum EN_DH_PLAYTYPE
DH_MAIN_STREAM = 0
DH_SUB_STREAM = 3
End Enum
'// Channel num
Public Enum EN_DH_CHANNEL
DH_CHANNEL_01 = 0
DH_CHANNEL_02
DH_CHANNEL_03
DH_CHANNEL_04
DH_CHANNEL_05
DH_CHANNEL_06
DH_CHANNEL_07
DH_CHANNEL_08
DH_CHANNEL_09
DH_CHANNEL_10
DH_CHANNEL_11
DH_CHANNEL_12
DH_CHANNEL_13
DH_CHANNEL_14
DH_CHANNEL_15
DH_CHANNEL_16
DH_CHANNEL_17
DH_CHANNEL_18
DH_CHANNEL_19
DH_CHANNEL_20
DH_CHANNEL_21
DH_CHANNEL_22
DH_CHANNEL_23
DH_CHANNEL_24
DH_CHANNEL_25
DH_CHANNEL_26
DH_CHANNEL_27
DH_CHANNEL_28
DH_CHANNEL_29
DH_CHANNEL_30
DH_CHANNEL_31
DH_CHANNEL_32
End Enum
'//New alarm protocol
Public Enum EN_DH_ALARMTYPE_EX
DH_ALARM_ALARMEX = 0 '// External alarm
DH_MOTIONDETECT_ALARMEX '// Motion detection alarm
DH_VEDIOSHELTER_ALARMEX '// Video loss alarm
DH_SHELTER_ALARMEX '// Camera masking alarm
DH_SOUNDDETECT_ALARMEX '// Audio detectino alarm
DH_DISKFULL_ALARMEX '// HDD full alarm
DH_DISKERROR_ALARMEX '// HDD malfunction alarm
DH_ENCODER_ALARMEX '// Encoder alarm
DH_URGENCY_ALARMEX '// Emergency alarm
DH_WIRELESS_ALARMEX '// Wireless alarm
DH_ALARM_DECODER_ALARMEX '// Alarm decoder alarm
DH_ALARM_NONE '// No alarm. To initialize.
End Enum
'// NET INFO
Public Type NET_DEVICEINFO
sSerialNumber As String * 48
byAlarmInPortNum As Byte
byAlarmOutPortNum As Byte
byDiskNum As Byte
byDVRType As Byte
byChanNum As Byte
End Type
Public devInfo As NET_DEVICEINFO
'// LOGIN ERROR
Public Enum EN_DH_LOGIN_ERROR
DH_LOGIN_ERROR_UNKNOWN = 0
DH_LOGIN_ERROR_PASSWORD
DH_LOGIN_ERROR_USER
DH_LOGIN_ERROR_TIMEOUT
DH_LOGIN_ERROR_RELOGGIN
DH_LOGIN_ERROR_LOCKED
DH_LOGIN_ERROR_BLACKLIST
DH_LOGIN_ERROR_BUSY
DH_LOGIN_ERROR_SUBCONNECT
DH_LOGIN_ERROR_NETWORK
DH_LOGIN_ERROR_MAXCONNECT
End Enum
Public loginError As EN_DH_LOGIN_ERROR
'// ERROR STRINGS
Public Const STR_ERROR_UNKNOWN As String = "Unknown Error."
Public Const STR_ERROR_PASSWORD As String = "Invalid password."
Public Const STR_ERROR_USER As String = "Account does not exist."
Public Const STR_ERROR_TIMEOUT As String = "Login time out."
Public Const STR_ERROR_RELOGGIN As String = "Account has logged in."
Public Const STR_ERROR_LOCKED As String = "Account is locked."
Public Const STR_ERROR_BLACKLIST As String = "Account is in the blacklist."
Public Const STR_ERROR_BUSY As String = "System is busy now."
Public Const STR_ERROR_SUBCONNECT As String = "Successfully logged in the device but can not create video channel. Please check network connection."
Public Const STR_ERROR_NETWORK As String = "Network connection failure."
Public Const STR_ERROR_MAXCONNECT As String = "Exceed maximum user connection."
'// NET STATE
'// General alarm informaiton
'// support 16 channel DVRs only
Public Type NET_CLIENT_STATE
channelcount As Long
alarminputcount As Long
alarm(0 To 15) As String * 1
motiondection(0 To 15) As String * 1
videolost(0 To 15) As String * 1
End Type
Public netState As NET_CLIENT_STATE
'// Search type, corresponding to CLIENT_QueryDevState
Public Const DH_DEVSTATE_COMM_ALARM As Long = 1 '// 0x0001 - Search general alarm status(including external alarm,video loss, motion detection)
Public Const DH_DEVSTATE_SHELTER_ALARM As Long = 2 '// 0x0002 - Search camera masking alarm status
Public Const DH_DEVSTATE_RECORDING As Long = 3 '// 0x0003 - Search record status
Public Const DH_DEVSTATE_DISK As Long = 4 '// 0x0004 - Search HDD information
Public Const DH_DEVSTATE_RESOURCE As Long = 5 '// 0x0005 - Search system resources status
Public Const DH_DEVSTATE_BITRATE As Long = 6 '// 0x0006 - Search channel bit stream
Public Const DH_DEVSTATE_CONN As Long = 7 '// 0x0007 - Search device connection status
Public Const DH_DEVSTATE_PROTOCAL_VER As Long = 8 '// 0x0008 - Search network protocol version number , pBuf = int*
Public Const DH_DEVSTATE_TALK_ECTYPE As Long = 9 '// 0x0009 - Search the audio talk format the device supported. Please refer to structure DHDEV_TALKFORMAT_LIST
Public Const DH_DEVSTATE_SD_CARD As Long = 10 '// 0x000A - Search SD card information(FOR IPC series)
Public Const DH_DEVSTATE_BURNING_DEV As Long = 11 '// 0x000B - Search burner information
Public Const DH_DEVSTATE_BURNING_PROGRESS As Long = 12 '// 0x000C - Search burning information
Public Const DH_DEVSTATE_PLATFORM As Long = 13 '// 0x000D - Search the embedded platform the device supported
Public Const DH_DEVSTATE_CAMERA As Long = 14 '// 0x000E - Search camera property information ( for IPC series)£¬pBuf = DHDEV_CAMERA_INFO *£¬there can be several structure.
Public Const DH_DEVSTATE_SOFTWARE As Long = 15 '// 0x000F - Search device software version information
Public Const DH_DEVSTATE_LANGUAGE As Long = 16 '// 0x0010 - Search the audio type the device supported
Public Const DH_DEVSTATE_DSP As Long = 17 '// 0x0011 - Search DSP capacity description
Public Const DH_DEVSTATE_OEM As Long = 18 '// 0x0012 - Search OEM information
Public Const DH_DEVSTATE_NET As Long = 19 '// 0x0013 - Search network running status information
Public Const DH_DEVSTATE_TYPE As Long = 20 '// 0x0014 - Search function attributes(for IPC serirs)
Public Const DH_DEVSTATE_SNAP As Long = 21 '// 0x0015 - Search snapshot function attribute(For IPC series)
Public Const DH_DEVSTATE_RECORD_TIME As Long = 22 '// 0x0016 - Query the first time and the recent video time
Public Const DH_DEVSTATE_NET_RSSI As Long = 23 '// 0x0017 - Query the wireless network signal strength£¬Please refer to structure DHDEV_WIRELESS_RSS_INFO
Public Const DH_DEVSTATE_BURNING_ATTACH As Long = 24 '// 0x0018 - Burning options inquiry
Public Const DH_DEVSTATE_BACKUP_DEV As Long = 25 '// 0x0019 - Query the list of backup device
Public Const DH_DEVSTATE_BACKUP_DEV_INFO As Long = 26 '// 0x001a - Query the backup device information
Public Const DH_DEVSTATE_BACKUP_FEEDBACK As Long = 27 '// 0x001b - backup rate of progress
Public Const DH_DEVSTATE_ATM_QUERY_TRADE As Long = 28 '// 0x001c - Query ATM trade type
Public Const DH_DEVSTATE_SIP As Long = 29 '// 0x001d - Query sip state
Public Const DH_DEVSTATE_VICHILE_STATE As Long = 30 '// 0x001e - Query wifi state of mobile DVR
Public Const DH_DEVSTATE_TEST_EMAIL As Long = 31 '// 0x001f - Query Email Function
Public Const DH_DEVSTATE_SMART_HARD_DISK As Long = 32 '// 0x0020 - Query Hard Disk Information
Public Const DH_DEVSTATE_TEST_SNAPPICTURE As Long = 33 '// 0x0021 - Query Snap Picture Function
Public Const DH_DEVSTATE_STATIC_ALARM As Long = 34 '// 0x0022 - Query static alarm state
Public Const DH_DEVSTATE_SUBMODULE_INFO As Long = 35 '// 0x0023 - Query submodule information
Public Const DH_DEVSTATE_DISKDAMAGE As Long = 36 '// 0x0024 - Query harddisk damage ability
'// Alarm type, corresponding to CLIENT_StartListen
Public Const DH_COMM_ALARM As Long = 4352 '// 0x1100 - General alarm(Including external alarm, video loss and motion detection)
Public Const DH_SHELTER_ALARM As Long = 4353 '// 0x1101 - Camera masking alarm
Public Const DH_DISK_FULL_ALARM As Long = 4354 '// 0x1102 - HDD full alarm
Public Const DH_DISK_ERROR_ALARM As Long = 4355 '// 0x1103 - HDD malfunction alarm
Public Const DH_SOUND_DETECT_ALARM As Long = 4356 '// 0x1104 - Audio detection alarm
Public Const DH_ALARM_DECODER_ALARM As Long = 4357 '// 0x1105 - Alarm decoder alarm
'// Extensive alarm type,corresponding to CLIENT_StartListenEx
Public Const DH_ALARM_ALARM_EX As Long = 8449 '// 0x2101 - External alarm
Public Const DH_MOTION_ALARM_EX As Long = 8450 '// 0x2102 - Motion detection alarm
Public Const DH_VIDEOLOST_ALARM_EX As Long = 8451 '// 0x2103 - Video loss alarm
Public Const DH_SHELTER_ALARM_EX As Long = 8452 '// 0x2104 - Camera masking alarm
Public Const DH_SOUND_DETECT_ALARM_EX As Long = 8453 '// 0x2105 - Audio detection alarm
Public Const DH_DISKFULL_ALARM_EX As Long = 8454 '// 0x2106 - HDD full alarm
Public Const DH_DISKERROR_ALARM_EX As Long = 8455 '// 0x2107 - HDD malfunction alarm
Public Const DH_ENCODER_ALARM_EX As Long = 8458 '// 0x210A - Encoder alarm
Public Const DH_URGENCY_ALARM_EX As Long = 8459 '// 0x210B - Emergency alarm
Public Const DH_WIRELESS_ALARM_EX As Long = 8460 '// 0x210C - Wireless alarm
Public Const DH_NEW_SOUND_DETECT_ALARM_EX As Long = 8461 '// 0x210D - New auido detection alarm. Please refer to DH_NEW_SOUND_ALARM_STATE for alarm information structure£»
Public Const DH_ALARM_DECODER_ALARM_EX As Long = 8462 '// 0x210E - Alarm decoder alarm
Public Const DH_DECODER_DECODE_ABILITY As Long = 8463 '// 0x210F - NVD£ºDecoding capacity
Public Const DH_FDDI_DECODER_ABILITY As Long = 8464 '// 0x2110 - Fiber encoder alarm
Public Const DH_PANORAMA_SWITCH_ALARM_EX As Long = 8465 '// 0x2111 - Panorama switch alarm
Public Const DH_LOSTFOCUS_ALARM_EX As Long = 8466 '// 0x2112 - Lost focus alarm
Public Const DH_OEMSTATE_EX As Long = 8467 '// 0x2113 - oem state
Public Const DH_DSP_ALARM_EX As Long = 8468 '// 0x2114 - DSP alarm
Public Const DH_ATMPOS_BROKEN_EX As Long = 8469 '// 0x2115 - atm and pos disconnection alarm, 0£ºdisconnection 1£ºconnection
Public Const DH_RECORD_CHANGED_EX As Long = 8470 '// 0x2116 - Record state changed alarm
Public Const DH_CONFIG_CHANGED_EX As Long = 8471 '// 0x2117 - Device config changed alarm
Public Const DH_DEVICE_REBOOT_EX As Long = 8472 '// 0x2118 - Device rebooting alarm
Public Const DH_STATIC_ALARM_EX As Long = 8482 '// 0x2122 - Static detection alarm
Public Const DH_PTZ_LOCATION_EX As Long = 8483 '// 0x2123 - ptz location info
Public Const DH_WINGDING_ALARM_EX As Long = 8473 '// 0x2119 - CoilFault alarm
Public Const DH_TRAF_CONGESTION_ALARM_EX As Long = 8474 '// 0x211A - traffic congestion alarm
Public Const DH_TRAF_EXCEPTION_ALARM_EX As Long = 8475 '// 0x211B - traffic exception alarm
Public Const DH_EQUIPMENT_FILL_ALARM_EX As Long = 8476 '// 0x211C - FlashFault alarm
'// MESSAGE RETURNS
Public dmsgCommand As Long
Public dmsgLoginID As Long
Public dmsgBuf As String
Public dmsgBufLen As Long
Public dmsgDVRIP As String
Public dmsgDVRPort As Long
Public dmsgUser As Long
'// MESSAGES
Public Function StartListenX(ByVal lLoginID As Long) As Boolean
Dim ret As Boolean
If lLoginID = 0 Then Exit Function
ret = CLIENT_StartListen(lLoginID) 'Listen
Call CLIENT_SetDVRMessCallBack(PtrToLong(AddressOf MessFunc), 0) 'Message callback
StartListenX = ret
End Function
Public Function StartListenEX(ByVal lLoginID As Long) As Boolean
Dim ret As Boolean
If lLoginID = 0 Then Exit Function
ret = CLIENT_StartListenEx(lLoginID) 'Listen
Call CLIENT_SetDVRMessCallBack(PtrToLong(AddressOf MessFunc), 0) 'Message callback
StartListenEX = ret
End Function
'message function
Public Sub MessFunc(ByVal lCommand As Long, ByVal lLoginID As Long, _
ByVal pBuf As Long, ByVal dwBufLen As Long, _
ByVal pchDVRIP As Long, ByVal nDVRPort As Long, ByVal dwUser As Long)
dmsgCommand = lCommand
dmsgLoginID = lLoginID
dmsgBuf = Space$(dwBufLen)
dmsgBuf = pBuf
dmsgBufLen = dwBufLen
dmsgDVRIP = pchDVRIP
dmsgDVRPort = nDVRPort
dmsgUser = dwUser
End Sub
'// ROUTINES
'init sdk
Public Function InitX() As Boolean
InitX = CLIENT_Init(PtrToLong(AddressOf DisConnectFunc), 0)
End Function
'disconnect function
Public Sub DisConnectFunc(ByVal lLoginID As Long, ByVal pchDVRIP As Long, ByVal nDVRPort As Long, ByVal dwUser As Long)
'// connection disconnects due to network error
End Sub
'auto reconnect
Public Sub SetAutoReconnectX()
Call CLIENT_SetAutoReconnect(PtrToLong(AddressOf AutoConnectFunc), 0)
End Sub
'auto reconnect function
Public Sub AutoConnectFunc(ByVal lLoginID As Long, ByVal pchDVRIP As Long, ByVal nDVRPort As Long, ByVal dwUser As Long)
'// reconnected successfully to device
End Sub
'set time to connect
Public Sub SetConnectTimeX(ByVal nWaitTime As Long)
Call CLIENT_SetConnectTime(nWaitTime, 0)
End Sub
'call when app is closing
Public Sub CleanupX()
Call CLIENT_Cleanup
End Sub
'resolve ddns to ip
Public Function GetDDNS(ByVal sAddr As String) As String
Dim oDDNS As cDNS2IP
Set oDDNS = New cDNS2IP
GetDDNS = oDDNS.ResolveDNS(sAddr)
Set oDDNS = Nothing
End Function
'login
Public Function ConnectX(ByVal pchDVRIP As String, ByVal wDVRPort As Long, ByVal pchUserName As String, Optional ByVal pchPassword As String = "") As Long
If LenB(pchDVRIP) = 0 Or wDVRPort = 0 Or LenB(pchUserName) = 0 Then Exit Function
pchDVRIP = GetDDNS(pchDVRIP)
ConnectX = CLIENT_Login(pchDVRIP, wDVRPort, pchUserName, pchPassword, devInfo, loginError)
End Function
'disconnect
Public Sub DisconnectX(ByVal lLoginID As Long)
If lLoginID Then Call CLIENT_Logout(lLoginID)
End Sub
'open video
Public Function PlayX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByVal hwnd As Long, ByVal rType As EN_DH_PLAYTYPE) As Long
If lLoginID = 0 Or hwnd = 0 Then Exit Function
PlayX = CLIENT_RealPlayEx(lLoginID, nChannelID, hwnd, rType)
End Function
'close video
Public Sub StopPlayX(ByRef lMonitorID As Long)
If lMonitorID = 0 Then Exit Sub
Call CLIENT_StopRealPlayEx(lMonitorID)
lMonitorID = 0
End Sub
'fluency level // 0-6
Public Function SetFluencyX(ByVal lMonitorID As Long, ByVal Level As EN_DH_FLUENCY) As Boolean
If lMonitorID = 0 Then Exit Function
SetFluencyX = CLIENT_AdjustFluency(lMonitorID, Level)
End Function
'save image
Public Function SnapshotX(ByVal lMonitorID As Long, ByVal FilePath As String) As Boolean
If lMonitorID = 0 Or LenB(FilePath) = 0 Then Exit Function
SnapshotX = CLIENT_CapturePicture(lMonitorID, FilePath)
End Function
'start recording // send full .dav file name and path
Public Function StartRecordX(ByVal lMonitorID As Long, ByVal FilePath As String) As Boolean
If lMonitorID = 0 Or LenB(FilePath) = 0 Then Exit Function
StartRecordX = CLIENT_SaveRealData(lMonitorID, FilePath)
End Function
'stop recording and close dav file
Public Function StopRecordX(ByVal lMonitorID As Long) As Boolean
If lMonitorID = 0 Then Exit Function
StopRecordX = CLIENT_StopSaveRealData(lMonitorID)
End Function
'open audio
Public Function StartAudioX(ByVal lMonitorID As Long) As Boolean
If lMonitorID = 0 Then Exit Function
StartAudioX = CLIENT_OpenSound(lMonitorID)
End Function
'close audio
Public Function StopAudioX() As Boolean
StopAudioX = CLIENT_CloseSound()
End Function
'general ptz control
Public Function PTZControlX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByVal pAction As EN_DH_CONTROLTYPE, ByVal pStep As EN_DH_PTZSTEP, _
Optional ByVal pStop As EN_DH_PTZSTOP = DH_PTZ_START) As Boolean
If lLoginID = 0 Then Exit Function
PTZControlX = CLIENT_PTZControl(lLoginID, nChannelID, pAction, pStep, pStop)
End Function
'ptz down
Public Function PTZDownX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByVal pStep As EN_DH_PTZSTEP, _
Optional ByVal pStop As EN_DH_PTZSTOP = DH_PTZ_START) As Boolean
If lLoginID = 0 Then Exit Function
PTZDownX = CLIENT_PTZControl(lLoginID, nChannelID, DH_PTZ_DOWN_CONTROL, pStep, pStop)
End Function
'ptz focus in
Public Function PTZFocusInX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByVal pStep As EN_DH_PTZSTEP, _
Optional ByVal pStop As EN_DH_PTZSTOP = DH_PTZ_START) As Boolean
If lLoginID = 0 Then Exit Function
PTZFocusInX = CLIENT_PTZControl(lLoginID, nChannelID, DH_PTZ_FOCUS_ADD_CONTROL, pStep, pStop)
End Function
'ptz focus out
Public Function PTZFocusOutX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByVal pStep As EN_DH_PTZSTEP, _
Optional ByVal pStop As EN_DH_PTZSTOP = DH_PTZ_START) As Boolean
If lLoginID = 0 Then Exit Function
PTZFocusOutX = CLIENT_PTZControl(lLoginID, nChannelID, DH_PTZ_FOCUS_DEC_CONTROL, pStep, pStop)
End Function
'ptz iris down
Public Function PTZIrisDownX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByVal pStep As EN_DH_PTZSTEP, _
Optional ByVal pStop As EN_DH_PTZSTOP = DH_PTZ_START) As Boolean
If lLoginID = 0 Then Exit Function
PTZIrisDownX = CLIENT_PTZControl(lLoginID, nChannelID, DH_PTZ_APERTURE_DEC_CONTROL, pStep, pStop)
End Function
'ptz iris up
Public Function PTZIrisUpX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByVal pStep As EN_DH_PTZSTEP, _
Optional ByVal pStop As EN_DH_PTZSTOP = DH_PTZ_START) As Boolean
If lLoginID = 0 Then Exit Function
PTZIrisUpX = CLIENT_PTZControl(lLoginID, nChannelID, DH_PTZ_APERTURE_ADD_CONTROL, pStep, pStop)
End Function
'ptz left
Public Function PTZLeftX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByVal pStep As EN_DH_PTZSTEP, _
Optional ByVal pStop As EN_DH_PTZSTOP = DH_PTZ_START) As Boolean
If lLoginID = 0 Then Exit Function
PTZLeftX = CLIENT_PTZControl(lLoginID, nChannelID, DH_PTZ_LEFT_CONTROL, pStep, pStop)
End Function
'ptz right
Public Function PTZRightX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByVal pStep As EN_DH_PTZSTEP, _
Optional ByVal pStop As EN_DH_PTZSTOP = DH_PTZ_START) As Boolean
If lLoginID = 0 Then Exit Function
PTZRightX = CLIENT_PTZControl(lLoginID, nChannelID, DH_PTZ_RIGHT_CONTROL, pStep, pStop)
End Function
'ptz up
Public Function PTZUpX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByVal pStep As EN_DH_PTZSTEP, _
Optional ByVal pStop As EN_DH_PTZSTOP = DH_PTZ_START) As Boolean
If lLoginID = 0 Then Exit Function
PTZUpX = CLIENT_PTZControl(lLoginID, nChannelID, DH_PTZ_UP_CONTROL, pStep, pStop)
End Function
'ptz zoom in
Public Function PTZZoomInX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByVal pStep As EN_DH_PTZSTEP, _
Optional ByVal pStop As EN_DH_PTZSTOP = DH_PTZ_START) As Boolean
If lLoginID = 0 Then Exit Function
PTZZoomInX = CLIENT_PTZControl(lLoginID, nChannelID, DH_PTZ_ZOOM_ADD_CONTROL, pStep, pStop)
End Function
'ptz zoom out
Public Function PTZZoomOutX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByVal pStep As EN_DH_PTZSTEP, _
Optional ByVal pStop As EN_DH_PTZSTOP = DH_PTZ_START) As Boolean
If lLoginID = 0 Then Exit Function
PTZZoomOutX = CLIENT_PTZControl(lLoginID, nChannelID, DH_PTZ_ZOOM_DEC_CONTROL, pStep, pStop)
End Function
'all alarm state - does not support 32 channel DVR
Public Function GetDeviceAlarmsX(ByVal lLoginID As Long, _
ByRef chancount As Long, ByRef alarmcount As Long, _
ByRef alarms As String, ByRef motion As String, ByRef videolost As String)
On Error GoTo Error_Handler
Dim bRet As Boolean, intI As Integer
If lLoginID = 0 Then Exit Function
bRet = CLIENT_QueryAlarmState(lLoginID, DH_DEVSTATE_COMM_ALARM, netState, Len(netState), 0, 1000)
If bRet Then
chancount = netState.channelcount
alarmcount = netState.alarminputcount
For intI = 0 To netState.channelcount - 1
If intI = 0 Then
alarms = Hex(Asc(netState.alarm(intI)))
motion = Hex(Asc(netState.motiondection(intI)))
videolost = Hex(Asc(netState.videolost(intI)))
Else
alarms = alarms & " " & Hex(Asc(netState.alarm(intI)))
motion = motion & " " & Hex(Asc(netState.motiondection(intI)))
videolost = videolost & " " & Hex(Asc(netState.videolost(intI)))
End If
Next intI
GetDeviceAlarmsX = True
End If
Error_Handler:
End Function
'alarm - does not support 32 channel DVR
Public Function GetAlarmStatusX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByRef alarm As String)
On Error GoTo Error_Handler
Dim bRet As Boolean
If lLoginID = 0 Then Exit Function
bRet = CLIENT_QueryAlarmState(lLoginID, DH_DEVSTATE_COMM_ALARM, netState, Len(netState), 0, 1000)
If bRet Then
If nChannelID > (netState.channelcount - 1) Then Exit Function
alarm = Hex(Asc(netState.alarm(nChannelID)))
GetAlarmStatusX = True
End If
Error_Handler:
End Function
'all alarms - does not support 32 channel DVR
Public Function GetAllAlarmStatusX(ByVal lLoginID As Long, ByRef chancount As Long, ByRef alarmcount As Long, ByRef alarms As String)
On Error GoTo Error_Handler
Dim bRet As Boolean, intI As Integer
If lLoginID = 0 Then Exit Function
bRet = CLIENT_QueryAlarmState(lLoginID, DH_DEVSTATE_COMM_ALARM, netState, Len(netState), 0, 1000)
If bRet Then
chancount = netState.channelcount
alarmcount = netState.alarminputcount
For intI = 0 To netState.channelcount - 1
If intI = 0 Then
alarms = Hex(Asc(netState.alarm(intI)))
Else
alarms = alarms & " " & Hex(Asc(netState.alarm(intI)))
End If
Next intI
GetAllAlarmStatusX = True
End If
Error_Handler:
End Function
'motion - does not support 32 channel DVR
Public Function GetMotionStatusX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByRef motion As String)
On Error GoTo Error_Handler
Dim bRet As Boolean
If lLoginID = 0 Then Exit Function
bRet = CLIENT_QueryAlarmState(lLoginID, DH_DEVSTATE_COMM_ALARM, netState, Len(netState), 0, 1000)
If bRet Then
If nChannelID > (netState.channelcount - 1) Then Exit Function
motion = Hex(Asc(netState.motiondection(nChannelID)))
GetMotionStatusX = True
End If
Error_Handler:
End Function
'all motion - does not support 32 channel DVR
Public Function GetAllMotionStatusX(ByVal lLoginID As Long, ByRef chancount As Long, ByRef alarmcount As Long, ByRef motion As String)
On Error GoTo Error_Handler
Dim bRet As Boolean, intI As Integer
If lLoginID = 0 Then Exit Function
bRet = CLIENT_QueryAlarmState(lLoginID, DH_DEVSTATE_COMM_ALARM, netState, Len(netState), 0, 1000)
If bRet Then
chancount = netState.channelcount
alarmcount = netState.alarminputcount
For intI = 0 To netState.channelcount - 1
If intI = 0 Then
motion = Hex(Asc(netState.motiondection(intI)))
Else
motion = motion & " " & Hex(Asc(netState.motiondection(intI)))
End If
Next intI
GetAllMotionStatusX = True
End If
Error_Handler:
End Function
'alarm - does not support 32 channel DVR
Public Function GetVideoLostStatusX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByRef videolost As String) As Boolean
On Error GoTo Error_Handler
Dim bRet As Boolean
If lLoginID = 0 Then Exit Function
bRet = CLIENT_QueryAlarmState(lLoginID, DH_DEVSTATE_COMM_ALARM, netState, Len(netState), 0, 1000)
If bRet Then
If nChannelID > (netState.channelcount - 1) Then Exit Function
videolost = Hex(Asc(netState.videolost(nChannelID)))
GetVideoLostStatusX = True
End If
Error_Handler:
End Function
'all video loss - does not support 32 channel DVR
Public Function GetAllVideoLostStatusX(ByVal lLoginID As Long, ByRef chancount As Long, ByRef alarmcount As Long, ByRef videolost As String)
On Error GoTo Error_Handler
Dim bRet As Boolean, intI As Integer
If lLoginID = 0 Then Exit Function
bRet = CLIENT_QueryAlarmState(lLoginID, DH_DEVSTATE_COMM_ALARM, netState, Len(netState), 0, 1000)
If bRet Then
chancount = netState.channelcount
alarmcount = netState.alarminputcount
For intI = 0 To netState.channelcount - 1
If intI = 0 Then
videolost = Hex(Asc(netState.videolost(intI)))
Else
videolost = videolost & " " & Hex(Asc(netState.videolost(intI)))
End If
Next intI
GetAllVideoLostStatusX = True
End If
Error_Handler:
End Function
'all record status
Public Function GetRecordStatusX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByRef recordstatus As String) As Boolean
On Error GoTo Error_Handler
Dim buf As String, chancount As Long, bRet As Boolean
Dim tmpBuf As String, intI As Integer
If lLoginID = 0 Then Exit Function
buf = Space$(32) '// 32 channel support
bRet = CLIENT_QueryRecordState(lLoginID, ByVal buf, 32, chancount, 1000)
If bRet Then
If nChannelID > (chancount - 1) Then Exit Function
tmpBuf = buf
buf = Space$(0)
recordstatus = Hex(Asc(Mid$(tmpBuf, nChannelID + 1, 1)))
GetRecordStatusX = True
End If
Error_Handler:
buf = Space$(0)
End Function
'all record status
Public Function GetAllRecordStatusX(ByVal lLoginID As Long, ByRef chancount As Long, ByRef recordstatus As String) As Boolean
On Error GoTo Error_Handler
Dim buf As String, bRet As Boolean
Dim tmpBuf As String, retStr As String, intI As Integer
If lLoginID = 0 Then Exit Function
buf = Space$(32) '// 32 channel support
bRet = CLIENT_QueryRecordState(lLoginID, ByVal buf, 32, chancount, 1000)
If bRet Then
tmpBuf = buf
buf = Space(0)
For intI = 1 To chancount
retStr = Hex(Asc(Mid$(tmpBuf, intI, 1)))
recordstatus = IIf(intI = 1, retStr, recordstatus & " " & retStr)
Next intI
GetAllRecordStatusX = True
End If
Error_Handler:
buf = Space$(0)
End Function
'camera title
Public Function GetTitleX(ByVal lLoginID As Long, ByVal nChannelID As EN_DH_CHANNEL, ByRef title As String) As Boolean
On Error GoTo Error_Handler
Dim buf As String, chancount As Long, bRet As Boolean
Dim tmpBuf As String, tmpStr As String, pos As Long
If lLoginID = 0 Then Exit Function
buf = Space$(1024) '// assign 32 x 32 bytes - 32 channel support
bRet = CLIENT_QueryChannelName(lLoginID, ByVal buf, 1024, chancount, 1000)
If bRet Then
tmpBuf = buf
buf = Space$(0)
pos = (nChannelID * 32)
If (pos + 32) > 1024 Then Exit Function
tmpStr = Mid$(tmpBuf, (pos + 1), 32)
title = Trim$(TrimNull(tmpStr))
GetTitleX = True
End If
Error_Handler:
buf = Space$(0)
End Function
'all camera titles
Public Function GetAllTitlesX(ByVal lLoginID As Long, ByRef titles As String, ByRef chancount As Long) As Boolean
On Error GoTo Error_Handler
Dim buf As String, bRet As Boolean, tmpBuf As String
Dim tmpStr As String, retStr As String, intI As Integer
If lLoginID = 0 Then Exit Function
buf = Space$(1024) '// assign 32 x 32 bytes - 32 channel support
bRet = CLIENT_QueryChannelName(lLoginID, ByVal buf, 1024, chancount, 1000)
If bRet Then
tmpBuf = buf
buf = Space$(0)
For intI = 1 To chancount
If Len(tmpBuf) < 32 Then Exit For
tmpStr = Left$(tmpBuf, 32)
If InStr(1, tmpStr, Chr$(0)) = 0 Then Exit For
retStr = Trim$(TrimNull(tmpStr))
If LenB(retStr) Then
titles = IIf(intI = 1, retStr, titles & vbCrLf & retStr)
End If
tmpBuf = Replace(tmpBuf, tmpStr, "")
Next intI
GetAllTitlesX = True
End If
Error_Handler:
buf = Space$(0)
End Function
'// general
Private Function TrimNull(Item As String)
Dim pos As Integer
pos = InStr(Item, Chr$(0))
If pos Then
TrimNull = Left$(Item, pos - 1)
Else
TrimNull = Item
End If
End Function
Public Function PtrToLong(ByVal func As Long) As Long
PtrToLong = func
End Function
CLIENT_Cleanup is called on exit to release the API from memory.
Reference DNS2IP.dll for ConnectX(), download from here (source included).
OR Include DNS2IP class (cDNS2IP.cls). Depends on ws2_32.dll (winsock).
Option Explicit
Private hLoginID As Long
Private hMonitorID As Long
Private bInited As Boolean
Private mIP As String
Private mPort As String
Private mUser As String
Private mPass As String
'// LOGIN AND PLAY VIDEO
Private Sub cmdPlayVideo_Click()
mIP = "192.168.1.108"
mPort = "37777"
mUser = "admin"
mPass = "admin"
If Login Then
Call StopPlayX(hMonitorID)
hMonitorID = PlayX(hLoginID, DH_CHANNEL_04, Picture1.hWnd, DH_SUB_STREAM)
If hMonitorID Then
Call SetFluencyX(hMonitorID, DH_FLUENCY_3)
Else
Picture1.Cls
MsgBox "Play Error"
End If
Else
Picture1.Cls
MsgBox "Cannot Connect"
End If
End Sub
'// CLOSE APPLICATION
Private Sub cmdExit_Click()
Unload Me
End Sub
'// APPLICATION CLOSES
Private Sub Form_Unload(Cancel As Integer)
Call StopPlayX(hMonitorID)
Call DisconnectX(hLoginID)
Call CleanupX
End Sub
'// LOGIN
Private Function Login() As Boolean
On Error GoTo Login_Error
If LenB(mIP) = 0 Then GoTo Login_Error
If LenB(mPort) = 0 Then GoTo Login_Error
If LenB(mUser) = 0 Then GoTo Login_Error
If bInited = False Then bInited = InitX 'SDK initialization
If bInited = False Then GoTo Init_Error
Call DisconnectX(hLoginID)
hLoginID = ConnectX(mIP, mPort, mUser, mPass) 'Login
If hLoginID Then Login = True
Exit Function
Init_Error:
MsgBox "Initialization failure"
Login_Error:
End Function
'// LOGIN
Private Function Login() As Boolean
On Error GoTo Login_Error
If LenB(mIP) = 0 Then GoTo Login_Error
If LenB(mPort) = 0 Then GoTo Login_Error
If LenB(mUser) = 0 Then GoTo Login_Error
If bInited = False Then bInited = InitX 'SDK initialization
If bInited Then
SetAutoReconnectX 'auto connects after 1 minute if connection fails
SetConnectTimeX 5000 'for connecting to slow servers (default is 3000ms)
End If
If bInited = False Then GoTo Init_Error
Call DisconnectX(hLoginID)
hLoginID = ConnectX(mIP, mPort, mUser, mPass) 'Login
If hLoginID Then Login = True
Exit Function
Init_Error:
MsgBox "Initialization failure"
Login_Error:
End Function
'// LOGIN AND PLAY VIDEO
Private Sub cmdPlayVideo_Click()
mIP = "192.168.1.108"
mPort = "37777"
mUser = "admin"
mPass = "admin"
If Login Then
Call StopPlayX(hMonitorID)
hMonitorID = PlayX(hLoginID, DH_CHANNEL_04, Picture1.hWnd, DH_SUB_STREAM)
If hMonitorID Then
Call SetFluencyX(hMonitorID, DH_FLUENCY_3)
Else
Picture1.Cls
MsgBox "Play Error"
End If
Else
Picture1.Cls
Select Case loginError
Case DH_LOGIN_ERROR_PASSWORD: MsgBox STR_ERROR_PASSWORD
Case DH_LOGIN_ERROR_USER: MsgBox STR_ERROR_USER
Case DH_LOGIN_ERROR_TIMEOUT: MsgBox STR_ERROR_TIMEOUT
Case DH_LOGIN_ERROR_RELOGGIN: MsgBox STR_ERROR_RELOGGIN
Case DH_LOGIN_ERROR_LOCKED: MsgBox STR_ERROR_LOCKED
Case DH_LOGIN_ERROR_BLACKLIST: MsgBox STR_ERROR_BLACKLIST
Case DH_LOGIN_ERROR_BUSY: MsgBox STR_ERROR_BUSY
Case DH_LOGIN_ERROR_SUBCONNECT: MsgBox STR_ERROR_SUBCONNECT
Case DH_LOGIN_ERROR_NETWORK: MsgBox STR_ERROR_NETWORK
Case DH_LOGIN_ERROR_MAXCONNECT: MsgBox STR_ERROR_MAXCONNECT
Case Else: MsgBox STR_ERROR_UNKNOWN
End Select
End If
End Sub
This value is returned from the login function.
Debug.Print "CHANNELS = " & devInfo.byChanNum
The default is to begin the PTZ action, you must then stop the action or it will continue.
'// PTZ UP START
Private Sub cmdPTZUp_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim ret As Boolean
ret = PTZUpX(hLoginID, DH_CHANNEL_01, DH_PTZ_STEP4)
End Sub
'// PTZ UP STOP
Private Sub cmdPTZUp_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim ret As Boolean
ret = PTZUpX(hLoginID, DH_CHANNEL_01, DH_PTZ_STEP4, DH_PTZ_STOP)
End Sub
Returns true if the audio channel exists, even if there is no connected audio.
'// AUDIO
Private Sub cmdAudio_Click()
Dim ret As Boolean
Static bAudioOpen As Boolean
Call StopAudioX
If bAudioOpen Then
cmdAudio.Caption = "Open Audio"
bAudioOpen = False
Else
ret = StartAudioX(hMonitorID)
If ret Then
bAudioOpen = True
cmdAudio.Caption = "Close Audio"
Else
cmdAudio.Caption = "Open Audio"
MsgBox "Audio Error"
End If
End If
End Sub
'// APPLICATION CLOSES
Private Sub Form_Unload(Cancel As Integer)
Call StopAudioX
Call StopPlayX(hMonitorID)
Call DisconnectX(hLoginID)
Call CleanupX
End Sub
Saves to DAV file format only - it must then be converted to AVI.
'// RECORD
Private Sub cmdRecord_Click()
Dim ret As Boolean
Static bRecording As Boolean
Call StopRecordX(hMonitorID)
If bRecording Then
cmdRecord.Caption = "Start Record"
bRecording = False
Else
ret = StartRecordX(hMonitorID, "C:\Test.dav")
If ret Then
bRecording = True
cmdRecord.Caption = "Stop Record"
Else
cmdRecord.Caption = "Start Record"
MsgBox "Record Error"
End If
End If
End Sub
'// APPLICATION CLOSES
Private Sub Form_Unload(Cancel As Integer)
Call StopRecordX(hMonitorID)
Call StopPlayX(hMonitorID)
Call DisconnectX(hLoginID)
Call CleanupX
End Sub
'// SNAPSHOT
Private Sub SnapShot()
Call SnapshotX(hMonitorId, "C:\Test.bmp")
End Sub
GetTitleX returns true if succeeded and the title in a string.
This also takes care of channels with no title - in that case it will show N/A.
This supports 32 channels.
'// get channel 1 title
Dim ret As Boolean, title As String
ret = GetTitleX(hLoginID, DH_CHANNEL_01, title)
If ret Then
Debug.Print "CHANNEL 1 = " & IIf(LenB(title), title, "N/A")
Else
Debug.Print "Error Getting Title"
End If
GetAllTitlesX returns true if succeeded and the titles in a string separated by vbCrLf.
This also takes care of channels with no title - in that case it will show N/A.
This also returns the channel count. This supports 32 channels.
'// GET ALL CAMERA TITLES
Private Sub GetAllCameraTitles()
Dim ret As Boolean, titles As String, chancount As Long
Dim arr() As String, title As String, flag As Boolean, i As Integer
ret = GetAllTitlesX(hLoginID, titles, chancount)
If chancount Then Debug.Print "CHANNELS = " & chancount
If ret Then
If LenB(titles) Then
arr = Split(titles, vbCrLf)
For i = 0 To chancount - 1
title = vbNullString
If i <= UBound(arr) Then title = arr(i)
Debug.Print "CHANNEL " & (i + 1) & " = " & IIf(LenB(title), title, "N/A")
Next i
Else
For i = 0 To chancount - 1
Debug.Print "CHANNEL " & (i + 1) & " = N/A"
Next i
End If
Else
Debug.Print "Error Getting Titles"
End If
End Sub
This gets the recording status of a single channel.
GetRecordStatusX returns true if succeeded and the record status in a string.
This supports 32 channels.
Dim ret As Boolean, recordstatus As String
ret = GetRecordStatusX(hLoginID, DH_CHANNEL_03, recordstatus)
If ret Then
Select Case recordstatus
Case "2"
Debug.Print "CHANNEL 1 = AUTO RECORD"
Case "1"
Debug.Print "CHANNEL 1 = MANUAL RECORD"
Case Else
Debug.Print "CHANNEL 1 = NOT RECORDING"
End Select
Else
Debug.Print "Error Getting Record Status"
End If
This gets the recording status of all channels.
GetRecordStatusX returns true if succeeded and the record status in a string separated by spaces.
This also returns the channel count. This supports 32 channels.
'// GET ALL RECORD STATUS
Private Sub GetAllRecordStatus()
Dim ret As Boolean, chancount As Long, recordstatus As String
Dim arr() As String, status As String, i As Integer
ret = GetAllRecordStatusX(hLoginID, chancount, recordstatus)
If chancount Then Debug.Print "CHANNELS = " & chancount
If LenB(ret) Then
arr = Split(recordstatus)
For i = LBound(arr) To UBound(arr)
status = arr(i)
Select Case status
Case "2"
Debug.Print "CHANNEL " & (i + 1) & " = AUTO RECORD"
Case "1"
Debug.Print "CHANNEL " & (i + 1) & " = MANUAL RECORD"
Case Else
Debug.Print "CHANNEL " & (i + 1) & " = NOT RECORDING"
End Select
Next i
Else
Debug.Print "Error Getting Record Status"
End If
End Sub
This gets the status of all device alarms.
This returns alarms, motion detection, and video loss
This only supports 16 channels. (SDK limitation)
Private Sub GetDeviceAlarms()
Dim ret As Boolean, chancount As Long, alarmcount As Long
Dim alarms As String, motion As String, videolost As String
Dim arrAlm() As String, arrMot() As String, arrVlost() As String
Dim bAlm As Boolean, bMot As Boolean, bVlost As Boolean
Dim i As Integer, strTmp As String
ret = GetDeviceAlarmsX(hLoginID, chancount, alarmcount, alarms, motion, videolost)
If ret Then
Debug.Print "==============="
Debug.Print chancount & " CHANNELS"
Debug.Print alarmcount & " ALARMS"
Debug.Print "==============="
arrAlm = Split(alarms)
arrMot = Split(motion)
arrVlost = Split(videolost)
For i = 0 To chancount - 1
bAlm = arrAlm(i)
bMot = arrMot(i)
bVlost = arrVlost(i)
strTmp = Trim$(IIf(bAlm, " ALARM", "") & IIf(bMot, " MOTION", "") & IIf(bVlost, " VIDLOSS", ""))
Debug.Print "CAMERA " & i + 1 & " = " & IIf(LenB(strTmp), strTmp, "NONE")
Next i
Else
Debug.Print "Error Getting Alarm State"
End If
End Sub
This checks the alarm status of a single channel.
This only supports 16 channels. (max)
Dim ret As Boolean, alarm As String
ret = GetAlarmStatusX(hLoginID, DH_CHANNEL_02, alarm)
If ret Then
Debug.Print "CAMERA 2 ALARM = " & CBool(alarm)
Else
Debug.Print "Error Getting CAMERA 2 ALARM"
End If
This checks the alarm status of all channels.
This only supports 16 channels. (max)
Private Sub GetAllAlarms()
Dim ret As Boolean, chancount As Long, alarmcount As Long
Dim alarms As String, arrAlm() As String, bAlm As Boolean, i As Integer
ret = GetAllAlarmStatusX(hLoginID, chancount, alarmcount, alarms)
If ret Then
Debug.Print "==============="
Debug.Print chancount & " CHANNELS"
Debug.Print alarmcount & " ALARMS"
Debug.Print "==============="
Debug.Print "ALARMS"
Debug.Print "==============="
arrAlm = Split(alarms)
For i = 0 To chancount - 1
bAlm = arrAlm(i)
Debug.Print "CAMERA " & i + 1 & " = " & bAlm
Next i
Else
Debug.Print "Error Getting All Alarms"
End If
End Sub
This checks the motion detection status of a single channel.
This only supports 16 channels. (SDK limitation)
Dim ret As Boolean, motion As String
ret = GetMotionStatusX(hLoginID, DH_CHANNEL_01, motion)
If ret Then
Debug.Print "CAMERA 1 MOTION = " & CBool(motion)
Else
Debug.Print "Error Getting CAMERA 1 MOTION"
End If
This checks the motion detection status of all channels.
This only supports 16 channels. (SDK limitation)
Private Sub GetAllMotion()
Dim ret As Boolean, chancount As Long, alarmcount As Long
Dim motion As String, arrMot() As String, bMot As Boolean, i As Integer
ret = GetAllMotionStatusX(hLoginID, chancount, alarmcount, motion)
If ret Then
Debug.Print "==============="
Debug.Print chancount & " CHANNELS"
Debug.Print alarmcount & " ALARMS"
Debug.Print "==============="
Debug.Print "MOTION DETECTION"
Debug.Print "==============="
arrMot = Split(motion)
For i = 0 To chancount - 1
bMot = arrMot(i)
Debug.Print "CAMERA " & i + 1 & " = " & bMot
Next i
Else
Debug.Print "Error Getting All Motion"
End If
End Sub
This checks the video loss status of a single channel.
This only supports 16 channels. (SDK limitation)
Dim ret As Boolean, videolost As String
ret = GetVideoLostStatusX(hLoginID, DH_CHANNEL_04, videolost)
If ret Then
Debug.Print "CAMERA 4 VIDEO LOST = " & CBool(videolost)
Else
Debug.Print "Error Getting CAMERA 4 VIDEO LOST"
End If
This checks the video loss status of all channels.
This only supports 16 channels. (SDK limitation)
Private Sub GetAllVideoLost()
Dim ret As Boolean, chancount As Long, alarmcount As Long
Dim videolost As String, arrVlost() As String, bVlost As Boolean, i As Integer
ret = GetAllVideoLostStatusX(hLoginID, chancount, alarmcount, videolost)
If ret Then
Debug.Print "==============="
Debug.Print chancount & " CHANNELS"
Debug.Print alarmcount & " ALARMS"
Debug.Print "==============="
Debug.Print "VIDEO LOST"
Debug.Print "==============="
arrVlost = Split(videolost)
For i = 0 To chancount - 1
bVlost = arrVlost(i)
Debug.Print "CAMERA " & i + 1 & " = " & bVlost
Next i
Else
Debug.Print "Error Getting All Video Loss"
End If
End Sub
Also see:
Search Results for Dahua
Dahua's Website

