📄 mega8.vb
字号:
Option Strict Off
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
Dim connectOK As Boolean
Dim buf As Object
Dim cont As Byte
Dim comport As Byte
Dim hwid As Boolean
Dim cid As Boolean
Dim portopen As Boolean
Public Sub chgcomport()
If MSComm1.portopen = True Then
MSComm1.portopen = False
End If
Er1:
If comport > 5 Then comport = 0
comport = comport + 1
MSComm1.CommPort = comport
On Error Resume Next
If MSComm1.portopen = False Then
MSComm1.portopen = True
End If
If MSComm1.PortOpen = False Then GoTo Er1
TextHW.Text = "Trying connect on com" & Str(comport)
cont = 0
'MSComm1.OutBufferCount = 0
Timer1.Enabled = True
End Sub
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
cid = False
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
MSComm1.Output = "e"
End Sub
Private Sub Command3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command3.Click
MSComm1.Output = "h"
End Sub
Private Sub Command4_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command4.Click
MSComm1.Output = "f"
End Sub
Private Sub Command5_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command5.Click
MSComm1.Output = "l"
End Sub
Private Sub Command6_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command6.Click
MSComm1.Output = "i"
cid = False
End Sub
Private Sub Command7_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command7.Click
MSComm1.Output = "1"
cid = False
End Sub
Private Sub Command8_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command8.Click
MSComm1.Output = "2"
cid = False
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
TextHW.Text = "Not Connect..."
comport = 0
cont = 0
chgcomport()
End Sub
Private Sub Form1_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
If MSComm1.portopen = True Then
MSComm1.portopen = False
End If
Me.Close()
End Sub
Private Sub MSComm1_OnComm(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MSComm1.OnComm
'Dim r As Byte
'If MSComm1.CommEvent = comEvReceive Then
'TextHW.Text = TextHW.Text + MSComm1.Input
'End If
End Sub
Public Sub GetHWinfo()
If buf = "" Then
cid = True
MSComm1.Output = "c" 'Send command request program board
Else
If buf = "Atmega Parallel Programer V1.0" Then 'Board reply OK ?
TextHW.Text = buf
buf = ""
hwid = True
connectOK = True 'has connect OK
cid = False
End If
End If
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
buf = MSComm1.Input
If Not hwid Then 'continue send request command to device
GetHWinfo()
End If
If Not cid Then
GetCID() 'connect Ok ... get mcu ID
End If
If cont > 3 And Not hwid Then
chgcomport()
Else
If Not connectOK Then cont = cont + 1
End If
End Sub
Public Sub GetCID()
If buf = "" Then
MSComm1.Output = "s"
Else
TextCID.Text = buf
cid = True
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -