'Create Standalone SDK class dynamicly.
Public axCZKEM1 As New zkemkeeper.CZKEM

#Region "Communication"
'*********************************************************************************************************************************************
'* Before you refer to this demo,we strongly suggest you read the development manual deeply first. *
'* This part is for demonstrating the communication with your device.There are 3 communication ways: "TCP/IP","Serial Port" and "USB Client".*
'* The communication way which you can use duing to the model of the device. *
'* *******************************************************************************************************************************************
Private bIsConnected = False 'the boolean value identifies whether the device is connected
Private iMachineNumber As Integer 'the serial number of the device.After connecting the device ,this value will be changed.

bIsConnected = AxCZKEM1.Connect_Net(txtIP.Text.Trim(), Convert.ToInt32(txtPort.Text.Trim()))
If bIsConnected = True Then
btnConnect.Text = "Disconnect"
btnConnect.Refresh()
lblState.Text = "Current State:Connected"
iMachineNumber = 1 'In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
AxCZKEM1.RegEvent(iMachineNumber, 65535) 'Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
Else
AxCZKEM1.GetLastError(idwErrorCode)
MsgBox("Unable to connect the device,ErrorCode=" & idwErrorCode, MsgBoxStyle.Exclamation, "Error")
End If
Cursor = Cursors.Default

'accept serialport number from string like "COMi"
Dim iPort As Integer
'Dim sPort = cbPort.Text.Trim()
Dim sPort As String = cbPort.Text.Trim()
For iPort = 1 To 9
If sPort.IndexOf(iPort.ToString()) > -1 Then
Exit For
End If
Next

iMachineNumber = Convert.ToInt32(txtMachineSN.Text.Trim()) '//when you are using the serial port communication,you can distinguish different devices by their serial port number.
bIsConnected = AxCZKEM1.Connect_Com(iPort, iMachineNumber, Convert.ToInt32(cbBaudRate.Text.Trim()))

If bIsConnected = True Then
btnRsConnect.Text = "Disconnect"
btnRsConnect.Refresh()
lblState.Text = "Current State:Connected"
AxCZKEM1.RegEvent(iMachineNumber, 65535) 'Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
Else
AxCZKEM1.GetLastError(idwErrorCode)
MsgBox("Unable to connect the device,ErrorCode=" & idwErrorCode, MsgBoxStyle.Exclamation, "Error")
End If
Cursor = Cursors.Default
End Sub
'If your device supports the USBCLient, you can refer to this.
'Not all series devices can support this kind of connection.Please make sure your device supports USBClient.
'Connect the device via the virtual serial port created by USBClient
Private Sub btnUSBConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUSBConnect.Click
Dim idwErrorCode As Integer

AxCZKEM1.EnableDevice(iMachineNumber, False) 'disable the device
If AxCZKEM1.GetDeviceStatus(iMachineNumber, 6, iValue) = True Then 'Here we use the function "GetDeviceStatus" to get the record's count.The parameter "Status" is 6.
MsgBox("The count of the AttLogs in the device is " + iValue.ToString(), MsgBoxStyle.Information, "Success")
Else
AxCZKEM1.GetLastError(idwErrorCode)
MsgBox("Operation failed,ErrorCode=" & idwErrorCode, MsgBoxStyle.Exclamation, "Error")
End If