VERSION 5.00
Object = "{459BCFBD-20C6-4262-89FD-436BC90C3A9D}#1.0#0"; "MotecDriverCmd.ocx"
Begin VB.Form Form1 
   Caption         =   "vb测试例程"
   ClientHeight    =   4020
   ClientLeft      =   120
   ClientTop       =   450
   ClientWidth     =   6300
   LinkTopic       =   "Form1"
   ScaleHeight     =   4020
   ScaleWidth      =   6300
   StartUpPosition =   3  'Windows Default
   Begin MOTECDRIVERCMDLib.MotecDriverCmd MotecDriverCmd1 
      Height          =   375
      Left            =   2160
      TabIndex        =   24
      Top             =   3240
      Width           =   735
      _Version        =   65536
      _ExtentX        =   1296
      _ExtentY        =   661
      _StockProps     =   0
   End
   Begin VB.Timer Timer1 
      Interval        =   500
      Left            =   840
      Top             =   3480
   End
   Begin VB.TextBox txtVelDisp 
      Height          =   375
      Left            =   1440
      TabIndex        =   19
      Text            =   "0"
      Top             =   2520
      Width           =   1575
   End
   Begin VB.TextBox txtDisDisp 
      Height          =   375
      Left            =   1440
      TabIndex        =   18
      Text            =   "0"
      Top             =   1920
      Width           =   1575
   End
   Begin VB.TextBox txtVel 
      Height          =   375
      Left            =   1440
      TabIndex        =   17
      Text            =   "500"
      Top             =   1320
      Width           =   1575
   End
   Begin VB.TextBox txtDis 
      Height          =   375
      Left            =   1440
      TabIndex        =   16
      Text            =   "100000"
      Top             =   720
      Width           =   1575
   End
   Begin VB.CommandButton btnStop 
      BackColor       =   &H000000FF&
      Caption         =   "急停"
      Height          =   375
      Left            =   4680
      TabIndex        =   11
      Top             =   3600
      Width           =   1335
   End
   Begin VB.CommandButton btnAbs 
      Caption         =   "绝对运动"
      Height          =   375
      Left            =   4680
      TabIndex        =   10
      Top             =   3120
      Width           =   1335
   End
   Begin VB.CommandButton btnRelative 
      Caption         =   "相对运动"
      Height          =   375
      Left            =   4680
      TabIndex        =   9
      Top             =   2520
      Width           =   1335
   End
   Begin VB.CommandButton btnSetVel 
      Caption         =   "设置速度"
      Height          =   375
      Left            =   4680
      TabIndex        =   8
      Top             =   1920
      Width           =   1335
   End
   Begin VB.CommandButton btnDisable 
      Caption         =   "释放电机"
      Height          =   375
      Left            =   4680
      TabIndex        =   7
      Top             =   1320
      Width           =   1335
   End
   Begin VB.CommandButton btnEnable 
      Caption         =   "使能电机"
      Height          =   375
      Left            =   4680
      TabIndex        =   6
      Top             =   720
      Width           =   1335
   End
   Begin VB.PictureBox Picture1 
      Height          =   255
      Left            =   4680
      ScaleHeight     =   195
      ScaleWidth      =   195
      TabIndex        =   5
      Top             =   120
      Width           =   255
   End
   Begin VB.ComboBox cbBaud 
      Height          =   315
      Left            =   3120
      TabIndex        =   3
      Top             =   120
      Width           =   1335
   End
   Begin VB.ComboBox cbCom 
      Height          =   315
      Left            =   840
      TabIndex        =   1
      Top             =   120
      Width           =   1215
   End
   Begin VB.CommandButton btnConnect 
      Caption         =   "连接"
      Height          =   375
      Left            =   4680
      TabIndex        =   4
      Top             =   120
      Width           =   1335
   End
   Begin VB.Label Label10 
      Caption         =   "RPM"
      Height          =   255
      Left            =   3240
      TabIndex        =   23
      Top             =   2640
      Width           =   735
   End
   Begin VB.Label Label9 
      Caption         =   "脉冲"
      Height          =   255
      Left            =   3240
      TabIndex        =   22
      Top             =   2040
      Width           =   735
   End
   Begin VB.Label Label8 
      Caption         =   "RPM"
      Height          =   255
      Left            =   3240
      TabIndex        =   21
      Top             =   1440
      Width           =   735
   End
   Begin VB.Label Label7 
      Caption         =   "脉冲"
      Height          =   255
      Left            =   3240
      TabIndex        =   20
      Top             =   840
      Width           =   735
   End
   Begin VB.Label Label6 
      Caption         =   "速度显示"
      Height          =   255
      Left            =   120
      TabIndex        =   15
      Top             =   2640
      Width           =   1095
   End
   Begin VB.Label Label5 
      Caption         =   "位置显示"
      Height          =   255
      Left            =   120
      TabIndex        =   14
      Top             =   1920
      Width           =   1095
   End
   Begin VB.Label Label4 
      Caption         =   "设定速度"
      Height          =   255
      Left            =   120
      TabIndex        =   13
      Top             =   1320
      Width           =   1095
   End
   Begin VB.Label label3 
      Caption         =   "设定位置"
      Height          =   255
      Left            =   120
      TabIndex        =   12
      Top             =   720
      Width           =   975
   End
   Begin VB.Label Label2 
      Caption         =   "波特率："
      Height          =   255
      Left            =   2160
      TabIndex        =   2
      Top             =   120
      Width           =   855
   End
   Begin VB.Label Label1 
      Caption         =   "串口："
      Height          =   255
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   615
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub btnAbs_Click()
    MotecDriverCmd1.MoveAbsolute (Int(txtDis.Text))
    MotecDriverCmd1.Go
End Sub

Private Sub btnConnect_Click()
    Dim bResult As Boolean
    If btnConnect.Caption = "连接" Then
        bResult = MotecDriverCmd1.OpenCom(cbCom.ListIndex + 1, Int(cbBaud.Text), 8, 0, 0)
        bResult = MotecDriverCmd1.EchoTesting
        If bResult Then
            btnConnect.Caption = "断开"
            Picture1.BackColor = vbGreen
            Timer1.Enabled = True
        End If
    Else
        MotecDriverCmd1.CloseCom
        btnConnect.Caption = "连接"
        Picture1.BackColor = vbRed
        Timer1.Enabled = False
    End If
    
    
End Sub

Private Sub btnDisable_Click()
    MotecDriverCmd1.PutMotorEnableStatus (0)
End Sub

Private Sub btnEnable_Click()
    MotecDriverCmd1.PutMotorEnableStatus (1)
End Sub

Private Sub btnRelative_Click()
    MotecDriverCmd1.MoveRelative (Int(txtDis.Text))
    MotecDriverCmd1.Go
End Sub

Private Sub btnSetVel_Click()
    Dim N As Integer
    N = Int(txtVel.Text)
    MotecDriverCmd1.PutSProfileParameter N, 50, 50
End Sub

Private Sub btnStop_Click()
    MotecDriverCmd1.QuickStop
End Sub

Private Sub Form_Load()
    ''初始化
    cbCom.AddItem ("com1")
    cbCom.AddItem ("com2")
    cbCom.AddItem ("com3")
    cbCom.AddItem ("com4")
    cbCom.AddItem ("com5")
    cbCom.AddItem ("com6")
    cbCom.AddItem ("com7")
    cbCom.AddItem ("com8")
    cbCom.AddItem ("com9")
    cbCom.AddItem ("com10")
    cbCom.ListIndex = 3
    
    cbBaud.AddItem ("9600")
    cbBaud.AddItem ("19200")
    cbBaud.AddItem ("38400")
    cbBaud.AddItem ("115200")
    cbBaud.ListIndex = 3
    
    Picture1.BackColor = vbRed
    
    
End Sub

Private Sub Form_Unload(Cancel As Integer)
    MotecDriverCmd1.CloseCom
End Sub

Private Sub Timer1_Timer()

        Dim fVel1 As Single
        Dim fvel2 As Single
        MotecDriverCmd1.GetVelocity fVel1, fvel2
        txtVelDisp.Text = fVel1
        
        Dim nPos1 As Long
        Dim nPos2 As Long
        MotecDriverCmd1.GetPosition nPos1, nPos2
        txtDisDisp.Text = nPos1
End Sub
