Public Class Form1
'----------------------------------------------变量
Dim user_id As UInt32
Public HeartbeatThread As Thread = Nothing
Public AIC As ALARM_INFO_CALLBACK = Nothing
'-----------------------------------------------结构
Public Structure msg_download_pic_t
Public channel_no As Integer
Public pic_len As UInt32
End Structure
Public Structure Plate_result
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Public plate_num As String
Public plate_rect As rect_s
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=28)> _
Public plate_char_rec As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=7)> _
Public plate_char_confid As Single
Public confidence As Single
Public plate_intensity As Integer
Public plate_color As Integer
Private plate_type As Integer
Public vehicle_color As Integer
Public TimeValue As UInt32
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=31)> _
Public res As Integer
End Structure
Public Structure rect_s
Public left_x As Integer
Public left_y As Integer
Public right_x As Integer
Public right_y As Integer
End Structure
Public Structure msg_alarm_infoEx_t
Public alarm_ack As Integer
Public tm As msg_time_t
Public alarm_id As Int32
Public alarm_channel As Int32
Public alarm_type As Int32
Public ip As String
Public alarm_info As String
Public data As Byte
End Structure
Public Structure msg_time_t
Public year As Integer
Public month As Integer
Public day As Integer
Public hour As Integer
Public minute As Integer
Public second As Integer
End Structure
Public Structure plasta
Public nState As Integer
Public resver As String
End Structure
Public Structure audioTalk_config_t
<MarshalAs(UnmanagedType.I4)> _
Public iRate As Integer
<MarshalAs(UnmanagedType.I4)> _
Public iWidth As Integer
<MarshalAs(UnmanagedType.I4)> _
Public iFormat As Integer
<MarshalAs(UnmanagedType.I4)> _
Public iAmr_mode As Integer
<MarshalAs(UnmanagedType.I4)> _
Public iAmr_format As Integer
End Structure
'-----------------------------------------------委托
Public Delegate Function ALARM_INFO_CALLBACK(ByVal msg_alarm_info As msg_alarm_infoEx_t, ByVal context As IntPtr) As Integer
' =============================================初始化网络库
<DllImport("decNetLib.dll", CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function st_net_initClientNetLib() As UInt32
End Function
' ==========================================用户登录
<DllImport("decNetLib.dll", CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function st_net_userLogin(ByVal user_id As UInt32) As Integer
End Function
' ===========================================注册告警信息回调函数
<DllImport("decNetLib.dll", CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function st_net_registerServerAlarmInfoCallback(ByVal user_id As UInt32, ByVal callback As ALARM_INFO_CALLBACK, ByVal context As IntPtr) As Integer
End Function
' ===============================================获取心跳状态信息
<DllImport("decNetLib.dll", CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function st_net_getHeartbeatStatus(ByVal user_id As UInt32) As Integer
<DllImport("decNetLib.dll", CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function st_net_initServerInfo(ByVal ip_addr As String, ByVal port As Integer, ByVal user_name As String, ByVal user_pwd As String) As UInt32
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Control.CheckForIllegalCrossThreadCalls = False
End Sub
Private Shared Function callbak(ByVal msg_alarm_info As msg_alarm_infoEx_t, ByVal context As IntPtr) As Integer
'当抓取车牌后 直接提示“试图写入受保护的内存”
End Function
For t As Integer = 0 To 99
If user_id <> 0 Then
ListBox1.Items.Add("心跳探测结果:" & st_net_getHeartbeatStatus(user_id))
st_net_registerServerAlarmInfoCallback(user_id, AIC, IntPtr.Zero)
Thread.Sleep(3000)
Else
keepalive = False
Return
End If
Next
End While
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add("初始网络:" & st_net_initClientNetLib())
Dim ip As String = "192.168.1.110"
Dim port As Integer = 9660
Dim user As String = "Admin"
Dim pass As String = "111111"
user_id = st_net_initServerInfo(ip, port, user, pass)
ListBox1.Items.Add("初始服务:" & user_id)
ListBox1.Items.Add("用户登录:" & st_net_userLogin(user_id))
HeartbeatThread = New Thread(New ThreadStart(AddressOf HeartbeatThreadStatus))
HeartbeatThread.Start()
AIC = New ALARM_INFO_CALLBACK(AddressOf callbak)
GC.KeepAlive(AIC)
ListBox1.Items.Add("注册回调函数:" & st_net_registerServerAlarmInfoCallback(user_id, AIC, IntPtr.Zero))
End Sub
End Class