Connect_Com

Definition

Usage

Connect to the device via a serial port, that is, via RS232 or RS485 port. Note: This function can be also used for some devices that use USB Client to communicate with the PC. However, the USB client driver must be first installed to simulate a serial port. After the installation succeeds, you can view the serial port number via the device manager on the PC or find the virtual serial port number via the program. For details, see "USBClient" of the demo program.

Parameter

Serial port number of the PC for connecting to the device

Device number

Baud rate

Return Value

Return True if it is successful, or return False.

Related Function

Disconnect, Connect_Net, Connect_USB

 

Ejemplo

C#

			//Create Standalone SDK class dynamicly.
            zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
            //the boolean value identifies whether the device is connected
            bool bIsConnected = false;

            int iMachineNumber = 1;


            int idwErrorCode = 0;
            //accept serialport number from string like "COMi"
            int iPort;
            string sPort = "COM1";
            for (iPort = 1; iPort < 10; iPort++)
            {
                if (sPort.IndexOf(iPort.ToString()) > -1)
                {
                    break;
                }
            }

            //when you are using the serial port communication,you can distinguish different devices by their serial port number.
            iMachineNumber = 1;

            //The boundrate value
            int iBaudRate = 115200;
            
            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");
            }

VB

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

        Dim idwErrorCode As Integer

        'the serial number of the device.After connecting the device ,this value will be changed.
        Dim iMachineNumber As Integer

        'accept serialport number from string like "COMi"
        Dim iPort As Integer
        'Dim sPort = cbPort.Text.Trim()
        Dim sPort As String = "COM1"
        'the boolean value identifies whether the device is connected
        For iPort = 1 To 9
            If sPort.IndexOf(iPort.ToString()) > -1 Then
                Exit For
            End If
        Next

        Dim bIsConnected = False
        'The boundrate value
        Dim iBaudRate As Integer
        iBaudRate = 115200


        iMachineNumber = 1 '//when you are using the serial port communication,you can distinguish different devices by their serial port number.
        bIsConnected = axCZKEM1.Connect_Com(iPort, iMachineNumber, iBaudRate)

        If bIsConnected = True Then
            'Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
            axCZKEM1.RegEvent(iMachineNumber, 65535)
        Else
            AxCZKEM1.GetLastError(idwErrorCode)
            MsgBox("Unable to connect the device,ErrorCode=" & idwErrorCode, MsgBoxStyle.Exclamation, "Error")
        End If