📄 logic_analyzer.frm
字号:
Private Sub Command1_Click()
CommonDialog1.Filter = "Ird文件|*.ird"
CommonDialog1.ShowOpen
Dim temp_Filename As String
Dim save_Filename As String
Dim temp_counter As Long
temp_Filename = CommonDialog1.FileName
'CommonDialog1.ShowSave
'save_Filename = CommonDialog1.FileName
On Error GoTo fuck
Open temp_Filename For Binary As #1
For temp_counter = 0 To 63488
Get #1, , Buffer1(temp_counter)
Next
For temp_counter = 0 To 63488
Get #1, , Buffer2(temp_counter)
Next
For temp_counter = 0 To 63488
Get #1, , Buffer3(temp_counter)
Next
Close #1
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
GoTo out
fuck:
MsgBox "打开文件出错"
out:
End Sub
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 = "串口已关闭,数据采集被强行停止"
Data_point = 0
Label2.Caption = "0 Bit/s"
Command2.Caption = "开始采集"
Picture1.Cls
Command1.Enabled = True
Command3.Enabled = True
Case True
Command2.Caption = "强行停止"
Command2.Enabled = True
Combo1.Enabled = False
Command1.Enabled = False
Command3.Enabled = False
Label1.Caption = "串口已开启,波特率为115200bps,等待数据中..."
Time = 0
Timer1.Interval = 200
End Select
End Sub
Private Sub Command3_Click()
CommonDialog1.Filter = "Ird文件|*.ird"
CommonDialog1.ShowSave
Dim temp_Filename As String
Dim temp_counter As Long
temp_Filename = CommonDialog1.FileName
'CommonDialog1.ShowSave
'save_Filename = CommonDialog1.FileName
On Error GoTo fuck
Open temp_Filename For Binary As #1
For temp_counter = 0 To 63488
Put #1, , Buffer1(temp_counter)
Next
For temp_counter = 0 To 63488
Put #1, , Buffer2(temp_counter)
Next
For temp_counter = 0 To 63488
Put #1, , Buffer3(temp_counter)
Next
Close #1
GoTo out
fuck:
MsgBox "保存文件出错"
out:
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 File1_Click()
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(Combo2.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 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()
Form3.Show
End Sub
Private Sub Label13_Click()
Form2.Show
End Sub
Private Sub Label14_Click()
Form4.Show
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
Dim temp As Variant
Label1.Caption = "数据采集已开始,串口波特率为115200 kbps"
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
Command1.Enabled = True
Command3.Enabled = True
Label1.Caption = "串口已关闭,数据采集已停止。共采集" & Str(Time / 5) & "秒时长的数据"
Picture1.Cls
Timer1.Interval = 0
Line4.BorderWidth = Int((Data_point / 63488) * Picture2.ScaleWidth * 2) + 1
Label12.Caption = Int((Data_point / 63488) * 100) & "%"
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()
If Data_point > 0 Then Time = Time + 1
Dim temp_rate As Long
temp_rate = MSComm1.InBufferCount
'Label1.Caption = "串口已开启" & Str(Time / 2) & "秒时长"
Line4.BorderWidth = Int((Data_point / 63488) * Picture2.ScaleWidth * 2) + 1
Label12.Caption = Int((Data_point / 63488) * 100) & "%"
Label2.Caption = (Data_point + temp_rate - Data_rate) * 40 & "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 + -