Connect to the device via USB ports. This function is used for communicating with H-series devices via USB ports instead of USB client. For communication via USB client, see Connect_Com.
Device number
Return True if it is successful, or return False.
Disconnect, Connect_Net, Connect_Com
//Create Standalone SDK class dynamicly. zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass(); int idwErrorCode = 0; //the boolean value identifies whether the device is connected bool bIsConnected = false; int iMachineNumber = 1; bool USBClientcommon = true; //connect the device via the virtual serial port created by USB bool virtualPort = true; if (USBClientcommon)//the common USBClient { //In fact,when you are using common USBClient communication,parameter Machinenumber will be ignored,that is any integer will all right.Here we use 1. iMachineNumber = 1; bIsConnected = axCZKEM1.Connect_USB(iMachineNumber); } else if (virtualPort)//connect the device via the virtual serial port created by USB { string sCom = ""; bool bSearch = SearchforCom(ref sCom); if (bSearch == false) { MessageBox.Show("Can not find the virtual serial port that can be used", "Error"); return; } int iPort; for (iPort = 1; iPort < 10; iPort++) if (sCom.IndexOf(iPort.ToString()) > -1) break; if (iMachineNumber == 0 || iMachineNumber > 255) { MessageBox.Show("The Machine Number is invalid!", "Error"); return; } int iBaudRate = 115200;//115200 is one possible baudrate value(its value cannot be 0) bIsConnected = axCZKEM1.Connect_Com(iPort, iMachineNumber, iBaudRate); } if (bIsConnected == true) { 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(ref idwErrorCode); MessageBox.Show("Unable to connect the device,ErrorCode=" + idwErrorCode.ToString(), "Error"); }
'Create Standalone SDK class dynamicly. Dim axCZKEM1 As zkemkeeper.CZKEMClass = New zkemkeeper.CZKEMClass() Dim idwErrorCode As Integer = 0 'the boolean value identifies whether the device Is connected Dim bIsConnected As Boolean = False Dim iMachineNumber As Integer = 1 Dim USBClientcommon As Boolean = True 'connect the device via the virtual serial port created by USB Dim virtualPort As Boolean = True If USBClientcommon = True Then 'the common USBClient iMachineNumber = 1 'In fact,when you are using common USBClient communication,parameter Machinenumber will be ignored,that is any integer will all right.Here we use 1. bIsConnected = axCZKEM1.Connect_USB(iMachineNumber) Else If virtualPort = True Then 'connect the device via the virtual serial port created by USB Dim sCom As String = "" Dim bSearch As Boolean Dim iPort As Integer bSearch = SearchforCom(sCom) If bSearch = False Then MsgBox("Can not find the virtual serial port that can be used", MsgBoxStyle.Exclamation, "Error") Return End If For iPort = 1 To 9 If sCom.IndexOf(iPort.ToString()) > -1 Then Exit For End If Next If iMachineNumber = 0 Or iMachineNumber > 255 Then MsgBox("The Machine Number is invalid!", MsgBoxStyle.Exclamation, "Error") Cursor = Cursors.Default Return End If Dim iBaudRate = 115200 '115200 is one possible baudrate value(its value cannot be 0) bIsConnected = axCZKEM1.Connect_Com(iPort, iMachineNumber, iBaudRate) End If End If If bIsConnected = True Then 'Here you can register the realtime events that you want axCZKEM1.RegEvent(iMachineNumber, 65535) Else axCZKEM1.GetLastError(idwErrorCode) MsgBox("Unable to connect the device,ErrorCode=" & idwErrorCode.ToString(), MsgBoxStyle.Exclamation, "Error") End If