只能 退出了,继续则进入 什么模式窗口了,只能强行退出了。
现在要完成的代码设置为:
Private Sub UpdatePortNameList()
Dim str1 As String
Dim Buf As String * GCAL_MAX_LEN_OF_PORTNAME_STRING
Dim lSize As Long
str1 = ComboPortName.Text
ComboPortName.Clear
Buf = Space$(GCAL_MAX_LEN_OF_PORTNAME_STRING)
If GCal_GetFirstPortName(Buf, GCAL_MAX_LEN_OF_PORTNAME_STRING) <> 0 Then
Do
lSize = InStr(Buf, vbNullChar)
If lSize > 0 Then
ComboPortName.AddItem Left(Buf, lSize)
End If
Buf = Space$(GCAL_MAX_LEN_OF_PORTNAME_STRING)
Loop Until GCal_GetNextPortName(Buf, GCAL_MAX_LEN_OF_PORTNAME_STRING) = 0
End If
If "" <> str1 Then
ComboPortName.Text = str1
Else
ComboPortName.ListIndex = 0
End If
End Sub
Private Sub RestartDevice()
If 0 <> DeviceID Then
GCal_CloseDevice (DeviceID)
End If
DeviceID = GCal_OpenDevice(ComboPortName.Text, ComboDeviceDescription.Text, Val(ComboBaudRate.Text))
DeviceChannel = Val(TextChannel.Text)
If 0 <> DeviceID Then
GCal_SetChannel DeviceID, DeviceChannel, 1
End If
End Sub
Private Sub ComboBaudRate_Change()
RestartDevice
End Sub
Private Sub ComboBaudRate_Click()
RestartDevice
End Sub
Private Sub ComboDeviceDescription_Change()
RestartDevice
End Sub
Private Sub ComboDeviceDescription_Click()
RestartDevice
End Sub
Private Sub ComboPortName_Change()
RestartDevice
End Sub
Private Sub ComboPortName_Click()
RestartDevice
End Sub
Private Sub CommandData_Click()
AddData
End Sub
Private Sub CommandExit_Click()
Unload Me
End Sub
Private Sub CommandZero_Click()
If 0 <> DeviceID Then
GCal_ZeroChannel DeviceID, DeviceChannel
End If
End Sub
Private Sub Form_Load()
DeviceID = 0
DeviceChannel = 0
GCal_SetCallBackProc AddressOf OnDataProc
UpdatePortNameList
ComboDeviceDescription.Clear
ComboDeviceDescription.AddItem "Auto1"
ComboDeviceDescription.AddItem "Auto1A"
ComboDeviceDescription.AddItem "Auto64A"
ComboDeviceDescription.AddItem "Ack64"
ComboDeviceDescription.AddItem "Ack64A"
ComboBaudRate.Clear
ComboBaudRate.AddItem "4800"
ComboBaudRate.AddItem "9600"
RestartDevice
End Sub
Private Sub Form_Unload(Cancel As Integer)
GCal_CloseAllDevices
End Sub
Private Sub ListData_Click()
End Sub
Private Sub TextChannel_Change()
Dim ch1 As Long
ch1 = Val(TextChannel.Text)
If ch1 <> DeviceChannel Then
GCal_SetChannel DeviceID, DeviceChannel, 0
DeviceChannel = ch1
GCal_SetChannel DeviceID, DeviceChannel, 1
End If
End Sub
Global DeviceID As Long
Global DeviceChannel As Long
Public Sub AddData()
With FormMain
If "" <> .LabelData.Caption Then
.ListData.AddItem .LabelData.Caption
.ListData.ListIndex = .ListData.ListCount - 1
End If
End With
End Sub
Public Sub OnDataProc(ByVal ID As Long, ByVal Channel As Long, ByVal Value As Long, ByVal KeyPressed As Byte)
Dim f As Double
Dim n1 As Long
Dim fmt As String
If (ID = DeviceID) And (Channel = DeviceChannel) Then
f = Val(FormMain.TextMultiplier.Text)
If 0 = f Then
f = 1
End If
f = f * Value / 100
n1 = Val(FormMain.TextDecimalDigits.Text)
fmt = IIf(0 = n1, "0", "0." & String(n1, "0"))
FormMain.LabelData.Caption = Format$(f, fmt)
If 0 <> KeyPressed Then
AddData
End If
End If
End Sub