⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmain.frm

📁 实现步进电机的串口控制
💻 FRM
📖 第 1 页 / 共 2 页
字号:
      _ExtentX        =   14870
      _ExtentY        =   1508
      ButtonWidth     =   1455
      ButtonHeight    =   1349
      Appearance      =   1
      ImageList       =   "ImageList"
      _Version        =   393216
      BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
         NumButtons      =   4
         BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            ImageIndex      =   1
            Style           =   3
         EndProperty
         BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "参数设置"
            ImageIndex      =   1
         EndProperty
         BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
         BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "退出"
            ImageIndex      =   8
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.ImageList ImageList 
      Left            =   8160
      Top             =   240
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   32
      ImageHeight     =   32
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   13
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":90FA
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":99D4
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":A6AE
            Key             =   ""
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":AF88
            Key             =   ""
         EndProperty
         BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":B862
            Key             =   ""
         EndProperty
         BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":C53C
            Key             =   ""
         EndProperty
         BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":CE16
            Key             =   ""
         EndProperty
         BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":D6F0
            Key             =   ""
         EndProperty
         BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":DFCA
            Key             =   ""
         EndProperty
         BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":E8A4
            Key             =   ""
         EndProperty
         BeginProperty ListImage11 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":F17E
            Key             =   ""
         EndProperty
         BeginProperty ListImage12 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":FA58
            Key             =   ""
         EndProperty
         BeginProperty ListImage13 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmMain.frx":10732
            Key             =   ""
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "FrmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Public vel As Long

Private Sub Check1_Click()
If Check1.Value = 1 Then
TxtDis.Enabled = False
Else
TxtDis.Enabled = True
End If

End Sub

Private Sub CmdE_Click()

sudden_stop2 AxisLeft, AxisRight
CmdS.Enabled = True
CmdE.Enabled = False
End Sub



Private Sub CmdS_Click()
CmdS.Enabled = False
CmdE.Enabled = True
SetVel
If Option2(0).Value = True Then  '直线前进
   If Check1.Value = 1 Then       '一直运动
   GoLine 1, -1
   Else                          '指定距离运动
    If TxtDis.Text = "" Or TxtDis.Text = 0 Then
      MsgBox "请输入运动距离"
      TxtDis.SetFocus
      CmdSAndCmdE
      Exit Sub
    End If
   GoLine 1, Val(Trim(TxtDis.Text))
   End If

ElseIf Option2(1).Value = True Then  '直线后退
   If Check1.Value = 1 Then       '一直运动
   GoLine -1, -1
   Else                          '指定距离运动
    If TxtDis.Text = "" Or TxtDis.Text = 0 Then
    MsgBox "请输入运动距离"
    TxtDis.SetFocus
    CmdSAndCmdE
    Exit Sub
    End If
   GoLine -1, Val(Trim(TxtDis.Text))
   End If

ElseIf Option2(2).Value = True Then  '走左圆
   If TxtR.Text = "" Or TxtR.Text = 0 Then
     MsgBox "请输入半径"
     TxtR.SetFocus
     CmdSAndCmdE
     Exit Sub
   End If
   GoRing 1, Val(Trim(TxtR.Text))

ElseIf Option2(3).Value = True Then  '走右圆
   If TxtR.Text = "" Or TxtR.Text = 0 Then
     MsgBox "请输入半径"
     TxtR.SetFocus
     CmdSAndCmdE
     Exit Sub
   End If
   GoRing -1, Val(Trim(TxtR.Text))

ElseIf Option2(4).Value = True Then   '原地左转
   GoRing 1, Val(DisLtoR / 2)

ElseIf Option2(5).Value = True Then   '原地右转
   GoRing -1, Val(DisLtoR / 2)

ElseIf Option2(6).Value = True Then   '走正方

   If TxtBorder.Text = "" Or TxtBorder.Text = 0 Then
     MsgBox "请输入边长"
     TxtBorder.SetFocus
     CmdSAndCmdE
     Exit Sub
   End If
   
    GoLine 1, Val(Trim(TxtBorder))
    GoRing -1, Val(DisLtoR / 2)
    GoLine 1, Val(Trim(TxtBorder))
    GoRing -1, Val(DisLtoR / 2)
    GoLine 1, Val(Trim(TxtBorder))
    GoRing -1, Val(DisLtoR / 2)
    GoLine 1, Val(Trim(TxtBorder))
    GoRing -1, Val(DisLtoR / 2)

ElseIf Option2(7).Value = True Then   '走八字
   If Txt8R.Text = "" Or Txt8R.Text = 0 Then
   
     MsgBox "请输入8字半径"
     Txt8R.SetFocus
     CmdSAndCmdE
     Exit Sub
   End If
    GoRing -1, Val(Trim(Txt8R.Text))
    GoRing 1, Val(Trim(Txt8R.Text))

End If



End Sub

Private Sub GoLine(ByVal dir As Long, ByVal Dis As Long)
reset_pos AxisLeft
reset_pos AxisRight
If Dis = -1 Then
con_vmove2 AxisLeft, dir, AxisRight, dir
Else
 If dir = 1 Then
   con_pmove2 AxisLeft, Dis, AxisRight, Dis
 Else
   con_pmove2 AxisLeft, -Dis, AxisRight, -Dis
 End If
End If

Do Until check_done2(AxisLeft, AxisRight) = 0
DoEvents
Loop


End Sub

Private Sub GoRing(ByVal dir As Long, ByVal R As Long)
If R - DisLtoR / 2 = 0 Then   '原地转圈
  
        If dir = 1 Then '左转
         con_pmove AxisRight, 2 * Pi * DisLtoR
        Else           '右转
         con_pmove AxisLeft, 2 * Pi * DisLtoR
        End If

Else                         '走圆
  
        If dir = 1 Then '左圆
        '2 * Pi * ( R-DisLtoR / 2)  左轮移动距离
        '2 * Pi * ( R+DisLtoR / 2)  右轮移动距离
        'vel 左轮速度
        'vel*(( R+DisLtoR / 2)/( R-DisLtoR / 2))  右轮速度
        
        set_conspeed AxisLeft, vel
        set_conspeed AxisRight, vel * ((R + DisLtoR / 2) / (R - DisLtoR / 2))
        con_pmove AxisLeft, 2 * Pi * (R - DisLtoR / 2)
        con_pmove AxisRight, 2 * Pi * (R + DisLtoR / 2)
        Else           '右圆
        set_conspeed AxisRight, vel
        set_conspeed AxisLeft, vel * ((R + DisLtoR / 2) / (R - DisLtoR / 2))
        con_pmove AxisRight, 2 * Pi * (R - DisLtoR / 2)
        con_pmove AxisLeft, 2 * Pi * (R + DisLtoR / 2)
        End If


End If

Do Until check_done2(AxisLeft, AxisRight) = 0
DoEvents
Loop


End Sub




Private Sub SetVel()


If Option1(0).Value = True Then
vel = PUsOf1mm * DefaultVel
ElseIf Option1(1).Value = True Then
vel = PUsOf1mm * DefaultVel * 2
ElseIf Option1(2).Value = True Then
vel = PUsOf1mm * DefaultVel / 2
End If
    set_conspeed AxisLeft, vel
    set_conspeed AxisRight, vel

End Sub






Private Sub Form_Load()
Dim ret As Long
    
ret = 0

'初始化电机控制卡
ret = SetBoard
If ret < 0 Then
MsgBox "抱歉,初始化电机控制卡失败"
'End
End If
    
    

ReadIniPara
Option2_Click (0)
End Sub

'该函数对板卡进行设置,可在窗体加载时调用
Private Function SetBoard() As Integer
    Dim Rtn As Integer

    Rtn = auto_set()            '对板卡进行自动设置
    If Rtn <= 0 Then            '若自动设置错误则返回0
        SetBoard = -1
        Exit Function
    End If
    Rtn = init_board
    If Rtn <> 0 Then
        SetBoard = -2
        Exit Function
    End If
    SetBoard = 0
End Function

Private Sub Option2_Click(index As Integer)
    
    If index = 0 Or index = 1 Then
    Check1.Enabled = True
    TxtDis.Enabled = True
    Else
    Check1.Enabled = False
    TxtDis.Enabled = False
    End If

    If index = 2 Or index = 3 Then
    TxtR.Enabled = True
    Else
    TxtR.Enabled = False
    End If
   
    If index = 6 Then
    TxtBorder.Enabled = True
    Else
    TxtBorder.Enabled = False
    End If
    
    If index = 7 Then
    Txt8R.Enabled = True
    Else
    Txt8R.Enabled = False
    End If
    

End Sub

Private Sub CmdSAndCmdE()
CmdS.Enabled = True
CmdE.Enabled = False

End Sub



Private Sub Toolbar_ButtonClick(ByVal Button As MSComctlLib.Button)
    Select Case Button.Caption
        Case "参数设置"
           FrmSet.Show 1
        Case "退出"
            Unload Me
            End
    End Select
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -