📄 main.frm
字号:
If instr1 = "OK" Then
BankNo.Caption = Combo1
BankNo.BackColor = &HC000&
End If
Timer2.Enabled = True
Exit Sub
Errhandler:
a = MsgBox("Error occurent", vbExclamation, "ERROR")
Timer2.Enabled = True
End Sub
'*****Communication setting********
Private Sub CommOff_Click()
On Error GoTo Errhandler
MSComm1.PortOpen = False
If MSComm1.PortOpen = False Then
CommOn.Enabled = True
CommOff.Enabled = False
Operation.Enabled = False
StatusBar1.Panels.Item(1).Text = "Communicate stopping"
End If
Timer2.Enabled = False
Timer1.Enabled = False
Exit Sub
Errhandler:
a = MsgBox("Error occurent", vbExclamation, "ERROR")
End Sub
'*****Communication setting********
Private Sub CommOn_Click()
On Error GoTo Errhandler
If MSComm1.PortOpen = False Then
MSComm1.CommPort = ComSet.Combo1
MSComm1.Settings = ComSet.BaudRate & "," & ComSet.Parity & "," & ComSet.DataLength & "," & ComSet.StopBit
'MSComm1.InBufferSize = 1024
MSComm1.InputMode = comInputModeText
MSComm1.InputLen = 0
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
CommOn.Enabled = False
CommOff.Enabled = True
Timer3.Enabled = True
StatusBar1.Panels.Item(1).Text = "Communicating . " & MSComm1.Settings
Call Light_state_reading
Call Image_display_mode
Call Bank_No_mode
Operation.Enabled = True
End If
End If
Exit Sub
Errhandler:
MsgBox (" Communication failed!Check the power supply,communication cable and COM port settings")
End Sub
'**********Light ON*****
Sub Light_ON()
On Error GoTo Errhandler
MSComm1.InBufferCount = 0
Timer2.Enabled = False
Call Write_db("LC", "0")
instr2 = MSComm1.Input
instr2 = Mid(instr2, 1, 2)
If instr2 = "OK" Then
LSOn.Enabled = True
LSOff.Enabled = False
LSOn.BackColor = &HC000&
LSOff.BackColor = &H8000000A
a = MsgBox("Light status is already ON.", vbInformation, "Information")
End If
Timer2.Enabled = True
Exit Sub
Errhandler:
a = MsgBox("Error occurent", vbExclamation, "ERROR")
Timer2.Enabled = True
End Sub
'**********Light OFF*****
Sub Light_OFF()
On Error GoTo Errhandler
MSComm1.InBufferCount = 0
Timer2.Enabled = False
Call Write_db("LC", "2")
instr3 = MSComm1.Input
instr3 = Mid(instr3, 1, 2)
If instr3 = "OK" Then
LSOn.Enabled = False
LSOff.Enabled = True
LSOff.BackColor = &HC000&
LSOn.BackColor = &H8000000A
a = MsgBox("Light status is already OFF.", vbInformation, "Information")
End If
Timer2.Enabled = True
Exit Sub
Errhandler:
a = MsgBox("Error occurent", vbExclamation, "ERROR")
Timer2.Enabled = True
End Sub
'**********Light state reading*****
Sub Light_state_reading()
On Error GoTo Errhandler
MSComm1.InBufferCount = 0
Call Read_db("LC")
instr1 = MSComm1.Input
str1 = Mid(instr1, 1, 2)
str2 = Mid(instr1, 4, 1)
If str1 = "OK" Then
If str2 = "0" Then
LSOn.Enabled = True
LSOff.Enabled = False
LSOn.BackColor = &HC000&
LSOff.BackColor = &H8000000A
Else
LSOn.Enabled = False
LSOff.Enabled = True
LSOff.BackColor = &HC000&
LSOn.BackColor = &H8000000A
End If
Exit Sub
End If
If str1 = "ER" Then
a = MsgBox("Then command is not executed,please check!", vbExclamation, "Warning")
End If
Exit Sub
Errhandler:
a = MsgBox("Error occurent", vbExclamation, "ERROR")
End Sub
'**********Image display mode*****
Sub Image_display_mode()
On Error GoTo Errhandler
MSComm1.InBufferCount = 0
Call Read_db("DC")
instr1 = MSComm1.Input
str1 = Mid(instr1, 1, 2)
str2 = Mid(instr1, 4, 1)
If str1 = "OK" Then
If str2 = "0" Then
Skill.Enabled = True
Live.Enabled = False
Skill.BackColor = &HC000&
Live.BackColor = &H8000000A
ElseIf str2 = "1" Then
Skill.Enabled = False
Live.Enabled = True
Skill.BackColor = &H8000000A
Live.BackColor = &HC000&
End If
Exit Sub
End If
If str1 = "ER" Then
a = MsgBox("Then command is not executed,please check!", vbExclamation, "Warning")
End If
Exit Sub
Errhandler:
a = MsgBox("Error occurent", vbExclamation, "ERROR")
End Sub
'**********Bank No.*****
Sub Bank_No_mode()
On Error GoTo Errhandler
MSComm1.InBufferCount = 0
Call Read_db("SN")
instr1 = MSComm1.Input
str1 = Mid(instr1, 1, 2)
str2 = Mid(instr1, 4, 1)
If str1 = "OK" Then
BankNo.Caption = str2
BankNo.BackColor = &HC000&
Exit Sub
End If
If str1 = "ER" Then
a = MsgBox("Then command is not executed,please check!", vbExclamation, "Warning")
End If
Exit Sub
Errhandler:
a = MsgBox("Error occurent", vbExclamation, "ERROR")
End Sub
Private Sub cSysTray1_MouseDown(Button As Integer, Id As Long)
Me.WindowState = 0 '掱彉夞?摓Normal忬?
Me.Visible = True '樃擟??拞惔彍??
cSysTray1.InTray = False '椷掱彉奅柺壜?
End Sub
Private Sub dcButton2_Click()
Unload Me
Unload HistoryFrom
Unload ComSet
Unload Openfrom
Unload backup
End Sub
Private Sub dcButton1_Click()
HistoryFrom.Show
End Sub
Private Sub dcButton4_Click()
ComSet.Show
End Sub
'***********Teaching**********
Private Sub dcButton5_Click()
On Error GoTo Errhandler
MSComm1.InBufferCount = 0
Timer2.Enabled = False
Call Write_db("GT", BankNo)
backup.Show
instr1 = MSComm1.Input
str1 = Mid(instr1, 1, 2)
ERROR1 = Mid(instr1, 2, 4)
If str1 = "OK" Then
Unload backup
a = MsgBox("Teaching is successful.", vbExclamation, "Teaching")
Exit Sub
ElseIf str1 = "ER" Then
Unload backup
a = MsgBox("Teaching is not executed.", vbExclamation, "Teaching")
Exit Sub
End If
ErrM (ERROR1)
Timer2.Enabled = True
Exit Sub
Errhandler:
a = MsgBox("Error occurent", vbExclamation, "ERROR")
Timer2.Enabled = True
End Sub
'*****Image display mode exchange*********
Private Sub DMChange_Click()
On Error GoTo Errhandler
If Skill.Enabled = False And Live.Enabled = True Then
MSComm1.InBufferCount = 0
Timer2.Enabled = False
Call Write_db("DC", "0")
instr1 = Mid(ReadData, 1, 2)
If instr1 = "OK" Then
Skill.Enabled = True
Live.Enabled = False
Skill.BackColor = &HC000&
Live.BackColor = &H8000000A
End If
ElseIf Skill.Enabled = True And Live.Enabled = False Then
MSComm1.InBufferCount = 0
Timer2.Enabled = False
Call Write_db("DC", "1")
instr1 = Mid(ReadData, 1, 2)
If instr1 = "OK" Then
Skill.Enabled = False
Live.Enabled = True
Skill.BackColor = &HC000&
Live.BackColor = &H8000000A
End If
End If
Timer2.Enabled = True
Exit Sub
Errhandler:
a = MsgBox("Error occurent", vbExclamation, "ERROR")
Timer2.Enabled = True
End Sub
Private Sub Form_Load()
Dim I As Integer
For I = 0 To 9
Combo1.AddItem I
Next I
StatusBar1.Panels.Item(2).Text = "涍撉庢婎斅師悢:" & ReadNumber & ""
StatusBar1.Panels.Item(3).Text = "OK:" & ReadNumber
StatusBar1.Panels.Item(4).Text = "NG:" & ReadNumber
CommOn.Enabled = True
CommOff.Enabled = False
End Sub
Private Sub Form_Resize()
'*****TRY ICON*****
If Me.WindowState = 1 Then '擛掱彉?嵟彫壔???
cSysTray1.InTray = True '?錟摓擟??
Me.Visible = False '?掱彉奅柺晄壜?
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload HistoryFrom
HistoryFrom.Record.SaveFile App.Path & "\HistoryRecord.inf"
End Sub
'***********DELECT DATA LIST **********
Private Sub ListClean_Click()
a = MsgBox("Are you sure you want to delect the data of Data list?", vbApplicationModal + vbYesNo + vbExclamation)
If a = "6" Then List1.Clear
End Sub
Private Sub LSChange_Click()
If LSOn.Enabled = True And LSOff.Enabled = False Then
Call Light_OFF
ElseIf LSOn.Enabled = False And LSOff.Enabled = True Then
Call Light_ON
End If
End Sub
Private Sub ReadOne_Click()
On Error GoTo Errhandler
Timer3.Enabled = False
MSComm1.InBufferCount = 0
Timer2.Enabled = False
outstr1 = "GL" & Chr(13)
MSComm1.Output = outstr1
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 3
Timer1.Enabled = True
Exit Sub
Errhandler:
a = MsgBox("Error occurent", vbExclamation, "ERROR")
Timer2.Enabled = True
Timer3.Enabled = True
End Sub
'*****one reading data ********
Private Sub ReadOne_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReadOne.Caption = "Reading data"
' ReadOne.BackColor = &HC0&
ReadOne.BackColor = &H8000&
End Sub
Private Sub ReadOne_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReadOne.Caption = "Read data(one)"
' ReadOne.ForeColor = &H0&
ReadOne.BackColor = &HE4D1D2
End Sub
'*********READ FUNCTION*********
Public Function Read_db(ByVal Command As String) ', ByVal parameter As String)
Dim outstr1, instr1 As String
'On Error GoTo Errhandler
MSComm1.InBufferCount = 0
Command = UCase(Command)
outstr1 = Command + Chr$(13)
MSComm1.Output = outstr1
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 5
'Timer1.Enabled = True
'Call Timer1_Timer
Exit Function
'Errhandler:
' A = MsgBox("Error occurent", vbExclamation, "ERROR")
End Function
Public Function Write_db(ByVal Command As String, ByVal parameter As String)
'On Error GoTo Errhandler
Dim outstr2 As String
MSComm1.InBufferCount = 0
Command = UCase(Command)
outstr2 = Command + Chr$(32) + parameter
L = Len(parameter)
MSComm1.Output = outstr2 + Chr$(13)
Do
DoEvents
Loop Until (MSComm1.InBufferCount >= 3)
Exit Function
'Errhandler:
' A = MsgBox("Error occurent", vbExclamation, "ERROR")
End Function
'**********save*********
Private Sub save_Click()
End Sub
Private Sub SystemSet_Click()
If SystemSet.Caption = "System set" Then
Timer3.Enabled = False
ReadOne.Enabled = False
dcButton5.Enabled = False
SytemState.Enabled = True
SystemSet.Caption = "Complete setting"
SystemSet.BackColor = &HC000&
ElseIf SystemSet.Caption = "Complete setting" Then
SytemState.Enabled = False
SystemSet.Caption = "System set"
SystemSet.BackColor = &HE4D1D2
ReadOne.Enabled = True
dcButton5.Enabled = True
Timer3.Enabled = True
End If
End Sub
Private Sub Timer1_Timer()
ReadData = MSComm1.Input
ERROR1 = Mid(ReadData, 2, 4)
ReadNumber = ReadNumber + 1
StatusBar1.Panels.Item(2).Text = "涍撉庢婎斅師悢:" & ReadNumber
If ErrM(ERROR1) = "1" Then
NG = NG + 1
StatusBar1.Panels.Item(4).Text = "NG:" & NG
Timer1.Enabled = False
Timer3.Enabled = True
Exit Sub
End If
instr1 = ReadData
Data1.Caption = instr1
OK = OK + 1
No = No + 1 'LIST No.
' Timer2.Enabled = True
L1 = Len(ReadData)
L2 = Len(No)
L = (43 - L1)
List1.AddItem No & ")" & Space(6 - L2) & "|" & Space(L) & ReadData & Space(L) & "| " & Now
HistoryFrom.Record.Text = HistoryFrom.Record.Text & Chr$(13) & No & ")" & Space(7) & "****" & Now & " **** " & instr1 '+ Chr$(13)
StatusBar1.Panels.Item(3).Text = "OK:" & OK
Timer1.Enabled = False
Timer3.Enabled = True
End Sub
'Private Sub Timer2_Timer()
'Call Light_state_reading
'Call Image_display_mode
'Call Bank_No_mode
'End Sub
Private Sub Timer3_Timer()
On Error GoTo Errhandler
ReadData = MSComm1.Input
If ReadData <> "" Then
ERROR1 = Mid(ReadData, 2, 4)
ReadNumber = ReadNumber + 1
StatusBar1.Panels.Item(2).Text = "涍撉庢婎斅師悢:" & ReadNumber
If ErrM(ERROR1) = "1" Then
NG = NG + 1
StatusBar1.Panels.Item(4).Text = "NG:" & NG
MSComm1.InBufferCount = 0
Exit Sub
End If
Data1.Caption = ReadData
OK = OK + 1
No = No + 1 'LIST No.
' Timer2.Enabled = True
'ReadNumber = ReadNumber + 1
L1 = Len(ReadData)
L2 = Len(No)
L = (43 - L1)
List1.AddItem No & ")" & Space(6 - L2) & "|" & Space(L) & ReadData & Space(L) & "| " & Now
HistoryFrom.Record.Text = HistoryFrom.Record.Text & Chr$(13) & No & ")" & Space(7) & "****" & Now & " **** " & ReadData '+ Chr$(13)
StatusBar1.Panels.Item(3).Text = "OK:" & OK
End If
MSComm1.InBufferCount = 0
Errhandler:
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -