ss.txt
来自「PC机与51单片机在管道机器人设计中的上位机控制程序 主要用来控制下位机中步进」· 文本 代码 · 共 366 行
TXT
366 行
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 87
Label3.Caption = "连接中"
MSComm1.Output = "1"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "小车前进中"
Else
Label3.Caption = "连接失败"
End If
Case 83
Label3.Caption = "连接中"
MSComm1.Output = "2"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "小车后退中"
Else
Label3.Caption = "连接失败"
End If
Case 65
Label3.Caption = "连接中"
MSComm1.Output = "3"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "小车左转中"
Else
Label3.Caption = "连接失败"
End If
Case 68
Label3.Caption = "连接中"
MSComm1.Output = "4"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "小车右转中"
Else
Label3.Caption = "连接失败"
End If
Case 32
Label3.Caption = "停止运行"
MSComm1.Output = "9"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "小车已经停止"
Else
Label3.Caption = "无法停止"
End If
Case 101
Label3.Caption = "连接中"
MSComm1.Output = "5"
delayms 101
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "摄像头上移中"
Else
Label3.Caption = "连接失败"
End If
Case 98
Label3.Caption = "连接中"
MSComm1.Output = "6"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "摄像头下移中"
Else
Label3.Caption = "连接失败"
End If
Case 97
Label3.Caption = "连接中"
MSComm1.Output = "7"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "摄像头左移中"
Else
Label3.Caption = "连接失败"
End If
Case 99
Label3.Caption = "连接中"
MSComm1.Output = "8"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "摄像头右移中"
Else
Label3.Caption = "连接失败"
End If
End Select
End Sub
Private Sub Command11_Click()
Label3.Caption = "连接中"
MSComm1.Output = "1"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "小车前进中"
Else
Label3.Caption = "连接失败"
End If
End Sub
'Private Sub Command11_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'Label3.Caption = "小车前进"
'End Sub
Private Sub Command12_Click()
Label3.Caption = "连接中"
MSComm1.Output = "2"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "小车后退中"
Else
Label3.Caption = "连接失败"
End If
End Sub
'Private Sub Command12_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'Label3.Caption = "小车后退"
'End Sub
Private Sub Command13_Click()
Label3.Caption = "连接中"
MSComm1.Output = "3"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "小车左转中"
Else
Label3.Caption = "连接失败"
End If
End Sub
'Private Sub Command13_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'Label3.Caption = "小车左转"
'End Sub
Private Sub Command14_Click()
Label3.Caption = "连接中"
MSComm1.Output = "4"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "小车右转中"
Else
Label3.Caption = "连接失败"
End If
End Sub
'Private Sub Command14_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'Label3.Caption = "小车右转"
'End Sub
'======================
'以下为摄像头方向控制
'======================
Private Sub Command15_Click()
Label3.Caption = "连接中"
MSComm1.Output = "5"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "摄像头上移中"
'MSComm1.Output = "9"
Else
Label3.Caption = "连接失败"
End If
End Sub
'Private Sub Command15_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'Label3.Caption = "摄像头上移"
'End Sub
Private Sub Command16_Click()
Label3.Caption = "连接中"
MSComm1.Output = "6"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "摄像头下移中"
Else
Label3.Caption = "连接失败"
End If
End Sub
'Private Sub Command16_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'Label3.Caption = "摄像头下移"
'End Sub
Private Sub Command17_Click()
Label3.Caption = "连接中"
MSComm1.Output = "7"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "摄像头左移中"
Else
Label3.Caption = "连接失败"
End If
End Sub
'Private Sub Command17_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'Label3.Caption = "摄像头左移"
'End Sub
Private Sub Command18_Click()
Label3.Caption = "连接中"
MSComm1.Output = "8"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "摄像头右移中"
Else
Label3.Caption = "连接失败"
End If
End Sub
Private Sub Command19_Click()
Label3.Caption = "停止运行"
MSComm1.Output = "9"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "小车已经停止"
Else
Label3.Caption = "无法停止"
End If
End Sub
Private Sub Command20_Click()
Label3.Caption = "停止运行"
MSComm1.Output = "9"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "小车已经停止"
Else
Label3.Caption = "无法停止"
End If
End Sub
'Private Sub Command18_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'Label3.Caption = "摄像头右移"
'End Sub
Private Sub Command2_Click()
MSComm1.Output = "9"
delayms 100
buf = MSComm1.Input
If buf = "0" Then
Label3.Caption = "小车已经停止"
Else
Label3.Caption = "无法停止"
End If
Command1.Enabled = True
Command2.Enabled = False
Vid.CaptureEnd
Form2.Show
Form2.Playback.FileName = Vid.CaptureFile
End Sub
Private Sub Command2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label3.Caption = "停止存储"
End Sub
Private Sub Command4_Click()
Set spShell = CreateObject("Shell.Application")
Set spFolder = spShell.BrowseForFolder(0, "选择目录:", 0, ssfDRIVES)
Set spFolderItem = spFolder.Self
spPath = spFolderItem.Path
spPath = Replace(spPath, "\", "\")
Text1.Text = spPath
End Sub
Private Sub Command6_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label3.Caption = "音频设置"
End Sub
'=============================================
'串口的设置,只设置了两个串口,分别是COM1和COM2。
'==============================================
Private Sub Form_Load()
Show
On Error Resume Next
MSComm1.PortOpen = False
MSComm1.CommPort = 1
MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
MSComm1.CommPort = 1
MSComm1.Settings = "1200,n,8,1"
MSComm1.PortOpen = True
Label3.Caption = "自动选择COM1"
Else
MSComm1.PortOpen = False
MSComm1.CommPort = 2
MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
MSComm1.CommPort = 2
MSComm1.Settings = "1200,n,8,1"
MSComm1.PortOpen = True
Label3.Caption = "自动选择COM2"
Else
MSComm1.PortOpen = False
Label3.Caption = "通信端口无法给您用"
End If
End If
End Sub
'Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'Label3.Caption = "Welcome To Cam-Cap v1.0"
'End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
End
End Sub
Private Sub Form_Terminate()
End
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
'Private Sub Frame1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'Label3.Caption = "Welcome To Cam-Cap v1.0"
'End Sub
Private Sub HScroll1_Change()
Label1.Caption = "Current Frame Rate (" & HScroll1.Value & " fps)"
Vid.PreviewRate = HScroll1.Value
Vid.CaptureRate = HScroll1.Value
End Sub
Private Sub HScroll1_Scroll()
Label1.Caption = "Current Frame Rate (" & HScroll1.Value & " fps)"
Vid.PreviewRate = HScroll1.Value
Vid.CaptureRate = HScroll1.Value
End Sub
'Private Sub Label3_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'abel3.Caption = "Welcome To Cam-Cap v1.0"
'End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?