📄 frmmain.frm
字号:
VERSION 5.00
Begin VB.Form frmMain
BorderStyle = 1 'Fixed Single
Caption = "MPC2810 演示"
ClientHeight = 3705
ClientLeft = 150
ClientTop = 720
ClientWidth = 3885
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 3705
ScaleWidth = 3885
StartUpPosition = 3 '窗口缺省
Begin VB.Timer timGetdata
Interval = 200
Left = 2880
Top = 3000
End
Begin VB.CommandButton cmdFastMove
Caption = "快 速"
Height = 375
Left = 2640
TabIndex = 15
Top = 2640
Width = 855
End
Begin VB.CommandButton cmdConMove
Caption = "常 速"
Height = 375
Left = 2640
TabIndex = 14
Top = 2160
Width = 855
End
Begin VB.CommandButton cmdReset
Caption = "清 零"
Height = 375
Left = 2640
TabIndex = 13
Top = 1680
Width = 855
End
Begin VB.CommandButton cmdSlowStop
Caption = "缓 停"
Height = 375
Left = 2640
TabIndex = 12
Top = 720
Width = 855
End
Begin VB.CommandButton cmdSuddenStop
Caption = "急 停"
Height = 375
Left = 2640
TabIndex = 11
Top = 240
Width = 855
End
Begin VB.Frame Frame1
Caption = "运动参数设定"
Height = 2295
Left = 240
TabIndex = 0
Top = 120
Width = 2175
Begin VB.TextBox txtAxesNum
Height = 270
Left = 1080
TabIndex = 5
Text = "1"
Top = 360
Width = 855
End
Begin VB.TextBox txtDis
Height = 270
Left = 1080
TabIndex = 4
Text = "200000"
Top = 1800
Width = 855
End
Begin VB.TextBox txtAccel
Height = 270
Left = 1080
TabIndex = 3
Text = "10000"
Top = 1440
Width = 855
End
Begin VB.TextBox txtHighSpeed
Height = 270
Left = 1080
TabIndex = 2
Text = "20000"
Top = 1080
Width = 855
End
Begin VB.TextBox txtLowSpeed
Height = 270
Left = 1080
TabIndex = 1
Text = "100"
Top = 720
Width = 855
End
Begin VB.Label labLineAxesX
Caption = "轴号"
Height = 255
Left = 600
TabIndex = 10
Top = 360
Width = 375
End
Begin VB.Label Label9
Caption = "移动距离"
Height = 255
Left = 240
TabIndex = 9
Top = 1800
Width = 1095
End
Begin VB.Label Label8
Caption = "加速度"
Height = 255
Left = 480
TabIndex = 8
Top = 1440
Width = 855
End
Begin VB.Label Label7
Caption = "最高速度"
Height = 255
Left = 240
TabIndex = 7
Top = 1080
Width = 1095
End
Begin VB.Label Label6
Caption = "初速度"
Height = 255
Left = 480
TabIndex = 6
Top = 720
Width = 855
End
End
Begin VB.Label Label4
Caption = "反馈:"
Height = 375
Left = 240
TabIndex = 21
Top = 3240
Width = 615
End
Begin VB.Label labEnc
Height = 255
Left = 960
TabIndex = 20
Top = 3240
Width = 1455
End
Begin VB.Label labSpeed
Height = 255
Left = 960
TabIndex = 19
Top = 2880
Width = 1455
End
Begin VB.Label labPos
Height = 255
Left = 960
TabIndex = 18
Top = 2520
Width = 1455
End
Begin VB.Label Label2
Caption = "速度:"
Height = 375
Left = 240
TabIndex = 17
Top = 2880
Width = 615
End
Begin VB.Label Label1
Caption = "脉冲:"
Height = 375
Left = 240
TabIndex = 16
Top = 2520
Width = 615
End
Begin VB.Menu mnuFile
Caption = "文件(&F)"
Begin VB.Menu mnuFileExit
Caption = "退出"
End
End
Begin VB.Menu mnuAbout
Caption = "关于(&A)"
Begin VB.Menu mnuCardInfo
Caption = "板卡信息"
End
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim AxesNum As Long
Dim lowspeed As Double
Dim highspeed As Double
Dim Accel As Double
Dim Dis As Long
Dim glTotalAxes As Long '当前计算机中轴数
Dim glTotalCards As Long '当前计算机中卡数
'*****************************************
'该函数对板卡进行设置,可在窗体加载时调用
Private Function SetBoard() As Integer
Dim Rtn As Integer, i As Integer
Rtn = auto_set() '对板卡进行自动设置
If Rtn <= 0 Then '若自动设置错误则返回0
SetBoard = -1
glTotalAxes = Rtn
Exit Function
End If
glTotalAxes = Rtn
Rtn = init_board
If Rtn <= 0 Then
SetBoard = -2
glTotalCards = Rtn
Exit Function
End If
glTotalCards = Rtn
For i = 1 To glTotalAxes
set_sd_logic i, 0
set_el_logic i, 0
set_org_logic i, 0
set_alm_logic i, 0
Next i
SetBoard = 0
End Function
'******************************************
'读取用户设置的运动参数
Private Sub GetParam()
AxesNum = Val(txtAxesNum.Text) '轴号
lowspeed = Val(txtLowSpeed.Text) '低速
highspeed = Val(txtHighSpeed.Text) '高速
Accel = Val(txtAccel.Text) '加速度
Dis = Val(txtDis.Text) '移动距离
set_maxspeed AxesNum, highspeed
set_conspeed AxesNum, lowspeed '设置常速运动参数
set_profile AxesNum, lowspeed, highspeed, Accel '设置梯形速度运动参数
End Sub
Private Sub cmdConMove_Click()
GetParam
con_pmove AxesNum, Dis
End Sub
Private Sub cmdFastMove_Click()
GetParam
fast_pmove AxesNum, Dis
End Sub
Private Sub cmdReset_Click()
reset_pos AxesNum
End Sub
Private Sub cmdSlowStop_Click()
decel_stop AxesNum
End Sub
Private Sub cmdSuddenStop_Click()
sudden_stop AxesNum
End Sub
Private Sub Form_Load()
If SetBoard < 0 Then
MsgBox "初始化错误!", vbOKOnly, "MPC02810演示 错误信息"
End If
GetParam
End Sub
Private Sub mnuCardInfo_Click()
Dim sInfo As String
Dim Rtn As Long
Dim BoardNum As Long
Dim i As Long
Dim ma(2) As Long, mi1(2) As Long, mi2(2) As Long
Dim nType As Long
sInfo = "计算机内插有 " & glTotalCards & " 个板卡。 共有 " & glTotalAxes & " 根轴。"
sInfo = sInfo & vbCrLf
Rtn = get_lib_ver(ma(0), mi1(0), mi2(0))
Rtn = get_sys_ver(ma(1), mi1(1), mi2(1))
Rtn = get_card_ver(1, nType, ma(2), mi1(2), mi2(2))
sInfo = sInfo & "板卡类型号 :" & nType & vbCrLf
sInfo = sInfo & "函数库版本号 :" & ma(0) & "." & mi1(0) & "." & mi2(0) & vbCrLf
sInfo = sInfo & "驱动程序版本号 :" & ma(1) & "." & mi1(1) & "." & mi2(1) & vbCrLf
sInfo = sInfo & "硬件版本号 :" & ma(2) & "." & mi1(2) & "." & mi2(2) & vbCrLf
' For i = 1 To glTotalAxes
' sudden_stop i
' Next i
'
' For i = 1 To glTotalAxes
' reset_pos i
' Next i
frmInfo.SetInfo sInfo
frmInfo.Show 1
End Sub
Private Sub mnuFileExit_Click()
Unload Me
End Sub
Private Sub timGetdata_Timer()
Dim pos As Long
Dim data As Long
Dim speed As Double, dbPos As Double
Dim lEnc As Long
get_abs_pos AxesNum, dbPos '读取位置
pos = Int(dbPos)
labPos.Caption = pos '显示位置
speed = get_rate(AxesNum) '读取速度
labSpeed.Caption = Int(speed) '显示速度
get_encoder AxesNum, lEnc '读取编码器反馈
labEnc.Caption = lEnc '显示编码器反馈
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -