📄 form1.frm
字号:
Width = 975
End
Begin VB.Label Label9
Caption = "实际速度"
Height = 255
Left = 3240
TabIndex = 5
Top = 3000
Width = 975
End
Begin VB.Label Label10
Caption = "实际位置"
Height = 255
Left = 3240
TabIndex = 4
Top = 3600
Width = 975
End
End
End
Attribute VB_Name = "axes"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim i As String
Dim x, y, z, n, m As Integer
Dim oResult, oEnable As Boolean
Private Sub Form_Load()
Dim Instring As String
MSComm1.CommPort = 2
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
MSComm1.PortOpen = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
Timer1.Enabled = False
MSComm1.Output = "s r0x24 0" & Chr$(13)
End Sub
Private Sub Command5_Click()
m = 0
Timer1.Enabled = True
Buffer$ = ""
MSComm1.Output = "s r0x90 9600" & Chr$(13)
Do
DoEvents
Buffer$ = MSComm1.Input
Loop Until InStr(Buffer$, "ok") Or m = 10
If InStr(Buffer$, "ok") = 0 Then
MsgBox " COM2 communication ERROR! "
Else
Buffer$ = ""
MSComm1.Output = "s r0x24 0" & Chr$(13)
Do
DoEvents
Buffer$ = MSComm1.Input
Loop Until InStr(Buffer$, "ok")
MsgBox "COM2 communication RIGHT!"
oEnable = True
End If
End Sub
Private Sub Combo1_Click()
If Combo1 = "Programmed Current Mode" Then
Label14.Visible = False
Label15.Visible = False
Label16.Visible = False
Label17.Visible = False
Label18.Visible = True
Label19.Visible = True
Text7.Visible = False
Text8.Visible = False
Text9.Visible = True
Combo2.Visible = False
Combo3.Visible = False
Text1.Enabled = True
Text2.Enabled = False
Text3.Enabled = False
End If
If Combo1 = "Programmed Velative Mode" Then
Label14.Visible = True
Label15.Visible = True
Label16.Visible = True
Label17.Visible = True
Label18.Visible = False
Label19.Visible = False
Text7.Visible = True
Text8.Visible = True
Text9.Visible = False
Combo2.Visible = False
Combo3.Visible = False
Text1.Enabled = False
Text2.Enabled = True
Text3.Enabled = False
End If
If Combo1 = "Programmed Position Mode" Then
Label14.Visible = True
Label15.Visible = True
Label16.Visible = True
Label17.Visible = True
Label18.Visible = False
Label19.Visible = False
Text7.Visible = True
Text8.Visible = True
Text9.Visible = False
Combo2.Visible = True
Combo3.Visible = True
Text1.Enabled = False
Text2.Enabled = True
Text3.Enabled = True
End If
End Sub
Private Sub Command1_Click()
If Combo1 = "Programmed Current Mode" Then
Buffer$ = ""
MSComm1.Output = "s r0x24 1" & Chr$(13)
Do
DoEvents
Buffer$ = MSComm1.Input
Loop Until InStr(Buffer$, "ok")
End If
If Combo1 = "Programmed Velative Mode" Then
Buffer$ = ""
MSComm1.Output = "s r0x24 11" & Chr$(13)
Do
DoEvents
Buffer$ = MSComm1.Input
Loop Until InStr(Buffer$, "ok")
End If
If Combo1 = "Programmed Position Mode" Then
Buffer$ = ""
MSComm1.Output = "t 1" & Chr$(13)
Do
DoEvents
Buffer$ = MSComm1.Input
Loop Until InStr(Buffer$, "ok")
End If
End Sub
Private Sub Command2_Click()
Buffer$ = ""
MSComm1.Output = "s r0x24 0" & Chr$(13)
Do
DoEvents
Buffer$ = MSComm1.Input
Loop Until InStr(Buffer$, "ok")
End Sub
Private Sub Timer1_Timer()
m = m + 1
If (oEnable) Then
n = n + 1
oResult = UpdateStatus()
End If
End Sub
Private Sub Command3_Click()
If Combo1 = "Programmed Current Mode" Then
i = "s r0x6a " & Text9.Text
MSComm1.Output = i & Chr$(13)
For y = 1 To 1000000
Next
z = Text1.Text / 10
i = "s r0x02 " & z
MSComm1.Output = i & Chr$(13)
For y = 1 To 1000000
Next
End If
If Combo1 = "Programmed Velative Mode" Then
z = Text8.Text / 1000
i = "s r0x36 " & z
MSComm1.Output = i & Chr$(13)
For y = 1 To 1000000
Next
z = Text7.Text / 1000
i = "s r0x37 " & z
MSComm1.Output = i & Chr$(13)
For y = 1 To 1000000
Next
z = Text2.Text * 10
i = "s r0x2f " & z
MSComm1.Output = i & Chr$(13)
For y = 1 To 1000000
Next
End If
If Combo1 = "Programmed Position Mode" Then
If Combo2 = "Absolute move" Then
If Combo3 = "Trapezoidal profile" Then
MSComm1.Output = "s r0xc8 0" & Chr$(13)
For y = 1 To 1000000
Next
Else
MSComm1.Output = "s r0xc8 1" & Chr$(13)
For y = 1 To 1000000
Next
End If
Else
If Combo3 = "Trapezoidal profile" Then
MSComm1.Output = "s r0xc8 256" & Chr$(13)
For y = 1 To 1000000
Next
Else
MSComm1.Output = "s r0xc8 257" & Chr$(13)
For y = 1 To 1000000
Next
End If
End If
i = "s r0xca " & Text3.Text
MSComm1.Output = i & Chr$(13)
For y = 1 To 1000000
Next
z = Text2.Text * 100
i = "s r0xcb " & z
MSComm1.Output = i & Chr$(13)
For y = 1 To 1000000
Next
z = Text8.Text / 10
i = "s r0xcc " & z
MSComm1.Output = i & Chr$(13)
For y = 1 To 1000000
Next
z = Text7.Text / 10
i = "s r0xcd " & z
MSComm1.Output = i & Chr$(13)
For y = 1 To 1000000
Next
MSComm1.Output = "s r0x24 21" & Chr$(13)
For y = 1 To 1000000
Next
End If
End Sub
Private Sub Command4_Click()
If Combo1 = "Programmed Current Mode" Then
Buffer$ = ""
MSComm1.Output = "s r0x24 0" & Chr$(13)
Do
DoEvents
Buffer$ = MSComm1.Input
Loop Until InStr(Buffer$, "ok")
End If
If Combo1 = "Programmed Velative Mode" Then
Buffer$ = ""
MSComm1.Output = "s r0x24 0" & Chr$(13)
Do
DoEvents
Buffer$ = MSComm1.Input
Loop Until InStr(Buffer$, "ok")
End If
If Combo1 = "Programmed Position Mode" Then
Buffer$ = ""
MSComm1.Output = "t 0" & Chr$(13)
Do
DoEvents
Buffer$ = MSComm1.Input
Loop Until InStr(Buffer$, "ok")
End If
End Sub
Public Function UpdateStatus() As Boolean
If (n = 1) Then
MSComm1.Output = "g r0x0c" & Chr$(13)
For y = 1 To 1000000
Next
i = MSComm1.Input
If (Left(i, 1) = "v") Then
x = Right(i, Len(i) - 2)
Text4.Text = x * 10
End If
End If
If (n = 2) Then
MSComm1.Output = "g r0x18" & Chr$(13)
For y = 1 To 1000000
Next
i = MSComm1.Input
If (Left(i, 1) = "v") Then
x = Right(i, Len(i) - 2)
Text5.Text = x / 10
End If
End If
If (n = 3) Then
MSComm1.Output = "g r0x32" & Chr$(13)
For y = 1 To 1000000
Next
i = MSComm1.Input
If (Left(i, 1) = "v") Then
x = Right(i, Len(i) - 2)
Text6.Text = x
End If
n = 0
End If
UpdateStatus = True
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -