因此,我遇到了一个问题,即尝试将API和.NET中编写的示例代码集成到VB中编写的旧代码中,而我遇到的问题是事件。 API给出的示例应用程序正在使用表单,但是我尝试在触发事件时在控制台应用程序中重复此操作。我需要实现许多不同的事件调用,但这是一个示例: .NET呼叫:
ReplyInteract.BaseConnection conn = new ReplyInteract.BaseConnection();
conn.BaseonLine += Conn_BaseonLine;
这是电话
private void Conn_BaseonLine(int BaseID,int BaseState)
{
string status = "";
switch (BaseState)
{
case 1: status = "Connected:Status 1"; txtCurrentBaseID.Text = BaseID.ToString(); break;
case 0: status = "Connection failed or closed: Status 0"; break;
case -1: status = "Connectiontype not supported:Status -1"; break;
case -2: status = "Invalid Base ID: Status -2"; break;
case -3: status = "No base connected or the usb port is occupied: Status - 3"; break;
case -5: status = "Basestation busy with another application. Please disconnect first";break;
case -6: status = "No Reply Interact Base station. Does not work with the Interact API";break;
default: status = BaseState.ToString(); break;
}
writeDebug("Base ID: " + BaseID.ToString() + " >> Status: " + status);
}
我不习惯在VB中进行编程,但这是我在VB中进行复制的尝试
Dim WithEvents conn As New ReplyInteract.BaseConnection
AddHandler conn.BaseonLine,AddressOf Conn_BaseonLine
Public Sub Conn_BaseonLine(ByVal BaseID As Integer,ByVal BaseState As Integer)
Dim status As String
Select Case BaseState
Case 1 : status = "Connected:Status 1"
Case 0 : status = "Connection failed or closed: Status 0"
Case -1 : status = "Connectiontype not supported:Status -1"
Case -2 : status = "Invalid Base ID: Status -2"
Case -3 : status = "No base connected or the usb port is occupied: Status - 3"
Case -5 : status = "Basestation busy with another application. Please disconnect first"
Case -6 : status = "No Reply Interact Base station. Does not work with the Interact API"
Case Else
status = BaseState.ToString()
End Select
End Sub
现在我不确定如何实际触发该事件吗?这是我目前拥有的完整vb代码
Module Module1
Dim WithEvents conn As New ReplyInteract.BaseConnection
Dim mg As New ReplyInteract.BaseManage
Sub Main()
While (True)
conn.BaseIP = "200.0.0.251"
Dim BaseonLine As String
conn.Open(1,"1")
conn.License = "****"
AddHandler conn.BaseonLine,AddressOf Conn_BaseonLine
End While
End Sub
Public Sub Conn_BaseonLine(ByVal BaseID As Integer,ByVal BaseState As Integer)
Dim status As String
Select Case BaseState
Case 1 : status = "Connected:Status 1"
Case 0 : status = "Connection failed or closed: Status 0"
Case -1 : status = "Connectiontype not supported:Status -1"
Case -2 : status = "Invalid Base ID: Status -2"
Case -3 : status = "No base connected or the usb port is occupied: Status - 3"
Case -5 : status = "Basestation busy with another application. Please disconnect first"
Case -6 : status = "No Reply Interact Base station. Does not work with the Interact API"
Case Else
status = BaseState.ToString()
End Select
End Sub