📄 logic_analyzer.frm
字号:
PrintWord 0, Y + 20, Str(Round(Start * Width_per_BIT * 8 / 1000, 3)) & "ms"
For j = 0 To Int(Time_long / 50)
Picture1.Line (j * 50 * Width_per_20us, Y + 100)-(j * 50 * Width_per_20us, START_Y + 200), RGB(200, 200, 255)
Next
End Function
Function PrintWord(ByVal x, Y As Integer, ByVal toprint As String)
Dim temp1, temp2 As Integer
temp1 = Picture1.CurrentX
temp2 = Picture1.CurrentY
With Picture1
.CurrentX = x
.CurrentY = Y
.ForeColor = RGB(255, 96, 96)
End With
Picture1.Print toprint
With Picture1
.CurrentX = temp1
.CurrentY = temp2
End With
End Function
Private Sub Command2_Click()
If MSComm1.PortOpen = False Then Init_com
Select Case MSComm1.PortOpen
Case False
Data_point = 0
End Select
MSComm1.PortOpen = Not MSComm1.PortOpen
Select Case MSComm1.PortOpen
Case False
Timer1.Interval = 0
Label1.Caption = "串口已关闭,数据采集已停止"
Label2.Caption = "0 Bit/s"
Command2.Caption = "开始采集"
Picture1.Cls
Case True
Command2.Caption = "停止"
Command2.Enabled = False
Combo1.Enabled = False
Label1.Caption = "串口已开启,波特率为115200bps"
Time = 0
Timer1.Interval = 500
End Select
End Sub
Private Sub Command5_Click()
If Wave_width >= 10240 Then Wave_width = 10240
Wave_width = Wave_width * 2
HScroll1.Max = 63486 / 2 - (Picture1.Width / Wave_width) / 8
Picture1.Cls
Draw_Square_Wave temp_long * 2, 0, 900, Wave_width, 1
Draw_Square_Wave temp_long * 2, 0, 2200, Wave_width, 2
Draw_Square_Wave temp_long * 2, 0, 3500, Wave_width, 3
End Sub
Private Sub Command6_Click()
Wave_width = Wave_width / 2
If Wave_width < 2.5 Then Wave_width = 2.5
HScroll1.Max = 63486 / 2 - (Picture1.Width / Wave_width) / 8
Picture1.Cls
Draw_Square_Wave temp_long * 2, 0, 900, Wave_width, 1
Draw_Square_Wave temp_long * 2, 0, 2200, Wave_width, 2
Draw_Square_Wave temp_long * 2, 0, 3500, Wave_width, 3
End Sub
Private Sub Form_Load()
Data_point = 0
Wave_width = 10
Init_com
Width_per_BIT = 20.0736
HScroll1.Max = 63486 / 2 - (Picture1.Width / Wave_width) / 8
End Sub
Function hex2(ByVal val As Integer)
Dim temp As String
temp = Hex(val)
If Len(temp) = 1 Then
hex2 = "0" & temp
Else
hex2 = temp
End If
End Function
Function Init_com()
With MSComm1
.CommPort = val(Combo1.Text)
.RThreshold = 1024 ' 设置触发oncom事件的字节数
.SThreshold = 0
.Settings = "115200,n,8,1"
.InBufferCount = 0 '清空缓存
.OutBufferCount = 0
.InputMode = comInputModeBinary
.InputLen = 1024
End With
End Function
Private Sub Frame1_DragDrop(Source As Control, x As Single, Y As Single)
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
Private Sub HScroll1_Change()
Picture1.Cls
temp_long = HScroll1.Value
Draw_Square_Wave temp_long * 2, 0, 900, Wave_width, 1
Draw_Square_Wave temp_long * 2, 0, 2200, Wave_width, 2
Draw_Square_Wave temp_long * 2, 0, 3500, Wave_width, 3
End Sub
Private Sub Label10_Click()
Form2.Show
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
Dim temp As Variant
temp = MSComm1.Input
Select Case Int(val(Combo1.Text))
Case 1
For i = 0 To 1023
Buffer1(i + Data_point) = temp(i)
Next
Case 2
For i = 0 To 1023
Buffer2(i + Data_point) = temp(i)
Next
Case 3
For i = 0 To 1023
Buffer3(i + Data_point) = temp(i)
Next
End Select
Data_point = Data_point + 1024
If Data_point >= 63487 Then
Dim Temp_text As String
Dim Temp_text2 As String
Label2.Caption = "Recieve OK!"
MSComm1.PortOpen = False
Command2.Caption = "开始采集"
Command2.Enabled = True
Combo1.Enabled = True
Label1.Caption = "串口已关闭,数据采集已停止"
Picture1.Cls
Timer1.Interval = 0
Draw_Square_Wave 0, 0, 900, Wave_width, 1
Draw_Square_Wave 0, 0, 2200, Wave_width, 2
Draw_Square_Wave 0, 0, 3500, Wave_width, 3
' End Select
' For i = 0 To 61
' For j = 0 To 1023
' Temp_text = Temp_text & hex2(Buffer(j + i * 1024)) & " "
' Next
' Temp_text2 = Temp_text2 & Temp_text
' Temp_text = ""
' Next
' Text1.Text = Temp_text2
End If
End Select
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Click_flag = True Then
Picture1.Line (x, 0)-(x, Picture1.HEiGHT), RGB(173, 225, 255)
Picture1.Line (Old_X, Y)-(x, Y), RGB(1, 117, 180)
Picture1.Line (Old_X, Y)-(Old_X + 200, Y - 100), RGB(1, 117, 180)
Picture1.Line (Old_X, Y)-(Old_X + 200, Y + 100), RGB(1, 117, 180)
Picture1.Line (x, Y)-(x - 200, Y + 100), RGB(1, 117, 180)
Picture1.Line (x, Y)-(x - 200, Y - 100), RGB(1, 117, 180)
PrintWord (x + Old_X) / 2, Int(Y), Str(Round(((x - Old_X) / Wave_width * Width_per_BIT) / 1000, 3)) & "ms"
Else
Old_X = x
Old_Y = Y
Picture1.Line (x, 0)-(x, Picture1.HEiGHT), RGB(173, 225, 255)
End If
Click_flag = Not Click_flag
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
WIDTH_per_100us = 25
With Line1
.X1 = x
.Y1 = 0
.X2 = x
.Y2 = Picture1.HEiGHT
.BorderColor = RGB(0, 255, 0)
End With
With Label3
.Left = x
.Top = Y + 500
.Caption = Str(Round((temp_long * 16 + x / Wave_width) * Width_per_BIT / 1000, 3)) & "ms"
End With
End Sub
Private Sub Timer1_Timer()
Time = Time + 1
Dim temp_rate As Long
temp_rate = MSComm1.InBufferCount
Label5.Caption = "串口已开启" & Str(Time / 2) & "秒时长"
Label2.Caption = (Data_point + temp_rate - Data_rate) * 16 & "Bit/s"
Data_rate = Data_point + temp_rate
' If MSComm1.InBufferCount >= 1024 Then
' Dim temp As Variant
'
' temp = MSComm1.Input
' For i = 0 To 6400
' Buffer(i) = temp(i)
'' Next
' Label2.Caption = "Recieve OK!"
' For i = 0 To 6400
' Text_temp = Text_temp & hex2(Buffer(i)) & " "
' Next
' Text1.Text = Text_temp
' End If
End Sub
Private Sub Timer2_Timer()
Flag_about = Not Flag_about
If Flag_about = True Then
Label10.Caption = "关于本程序"
Else
Label10.Caption = "Click Me!!"
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -