连接按钮的代码如下:
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
If txtIP.Text.Trim() = "" Or txtPort.Text.Trim() = "" Then
MsgBox("IP and Port cannot be null", MsgBoxStyle.Exclamation, "Error")
Return
End If
Dim idwErrorCode As Integer
Cursor = Cursors.WaitCursor
If btnConnect.Text = "Disconnect" Then
AxCZKEM1.Disconnect()
bIsConnected = False
btnConnect.Text = "Connect"
lblState.Text = "Current State:Disconnected"
Cursor = Cursors.Default
Return
End If
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
End Sub
我的IP及端口都是正确的,密码是123456应该加在哪里?不然在VS中启动运行代码会出现下面的错误提示: