www.pudn.com > Vb6.0.rar > MAINFRM.FRM, change:2004-03-17,size:13759b


VERSION 5.00 
Begin VB.Form MAIN_FRAME  
   Caption         =   "DMC1000编程示例之一" 
   ClientHeight    =   4410 
   ClientLeft      =   4185 
   ClientTop       =   3285 
   ClientWidth     =   5715 
   LinkTopic       =   "Form1" 
   ScaleHeight     =   4410 
   ScaleWidth      =   5715 
   Begin VB.Timer Timer1  
      Interval        =   100 
      Left            =   4800 
      Top             =   1560 
   End 
   Begin VB.OptionButton Option8  
      Caption         =   "T形驱动" 
      Height          =   375 
      Left            =   4560 
      TabIndex        =   23 
      Top             =   2760 
      Width           =   975 
   End 
   Begin VB.OptionButton Option_SpeedST  
      Caption         =   "S形驱动" 
      Height          =   375 
      Left            =   4560 
      TabIndex        =   22 
      Top             =   2400 
      Width           =   975 
   End 
   Begin VB.CommandButton Command_ClsPos  
      Caption         =   "位置清零" 
      Height          =   375 
      Left            =   4680 
      TabIndex        =   21 
      Top             =   3360 
      Width           =   975 
   End 
   Begin VB.CommandButton Command_Stop  
      Caption         =   "停止" 
      Height          =   375 
      Left            =   4680 
      TabIndex        =   20 
      Top             =   720 
      Width           =   975 
   End 
   Begin VB.CommandButton Command_Start  
      Caption         =   "开始" 
      Height          =   375 
      Left            =   4680 
      TabIndex        =   19 
      Top             =   120 
      Width           =   975 
   End 
   Begin VB.Frame Frame3  
      Caption         =   "速度设定" 
      Height          =   2295 
      Left            =   2160 
      TabIndex        =   13 
      Top             =   1440 
      Width           =   2295 
      Begin VB.TextBox Text_Pulse  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   27 
         Text            =   "6400" 
         Top             =   1320 
         Width           =   855 
      End 
      Begin VB.TextBox Text_Time  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   26 
         Text            =   "0.1" 
         Top             =   960 
         Width           =   855 
      End 
      Begin VB.TextBox Text_Speed  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   25 
         Text            =   "6400" 
         Top             =   600 
         Width           =   855 
      End 
      Begin VB.TextBox Text_Start  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   24 
         Text            =   "1600" 
         Top             =   240 
         Width           =   855 
      End 
      Begin VB.CheckBox Check_Dir  
         Caption         =   "驱动方向:正" 
         Height          =   375 
         Left            =   480 
         TabIndex        =   18 
         Top             =   1800 
         Width           =   1455 
      End 
      Begin VB.Label Label6  
         Caption         =   "定量脉冲:" 
         Height          =   375 
         Left            =   240 
         TabIndex        =   17 
         Top             =   1440 
         Width           =   1095 
      End 
      Begin VB.Label Label5  
         Caption         =   "变速时间:" 
         Height          =   375 
         Left            =   240 
         TabIndex        =   16 
         Top             =   1080 
         Width           =   975 
      End 
      Begin VB.Label Label4  
         Caption         =   "驱动速度:" 
         Height          =   255 
         Left            =   240 
         TabIndex        =   15 
         Top             =   720 
         Width           =   1335 
      End 
      Begin VB.Label Label3  
         Caption         =   "起始速度:" 
         Height          =   255 
         Left            =   240 
         TabIndex        =   14 
         Top             =   360 
         Width           =   1095 
      End 
   End 
   Begin VB.Frame Frame2  
      Caption         =   "配置参数" 
      Height          =   2295 
      Left            =   120 
      TabIndex        =   7 
      Top             =   1440 
      Width           =   1935 
      Begin VB.OptionButton Option6  
         Caption         =   "持续驱动" 
         Height          =   375 
         Left            =   360 
         TabIndex        =   12 
         Top             =   1800 
         Width           =   1335 
      End 
      Begin VB.OptionButton Option_MOVEST  
         Caption         =   "定量驱动" 
         Height          =   255 
         Left            =   360 
         TabIndex        =   11 
         Top             =   1560 
         Width           =   1095 
      End 
      Begin VB.CheckBox Check_SD  
         Caption         =   "外部减速" 
         Height          =   375 
         Left            =   240 
         TabIndex        =   10 
         Top             =   1080 
         Width           =   1695 
      End 
      Begin VB.CheckBox Check_PLogic  
         Caption         =   "脉冲逻辑:正" 
         Height          =   375 
         Left            =   240 
         TabIndex        =   9 
         Top             =   720 
         Width           =   1575 
      End 
      Begin VB.CheckBox Check_Pmode  
         Caption         =   "脉冲+方向" 
         Height          =   495 
         Left            =   240 
         TabIndex        =   8 
         Top             =   240 
         Width           =   1455 
      End 
   End 
   Begin VB.Frame Frame1  
      Caption         =   "地址信息及驱动轴选择" 
      Height          =   1215 
      Left            =   120 
      TabIndex        =   0 
      Top             =   120 
      Width           =   4335 
      Begin VB.OptionButton Option4  
         Caption         =   "U轴" 
         Height          =   375 
         Left            =   3120 
         TabIndex        =   6 
         Top             =   720 
         Width           =   735 
      End 
      Begin VB.OptionButton Option3  
         Caption         =   "Z轴" 
         Height          =   375 
         Left            =   2400 
         TabIndex        =   5 
         Top             =   720 
         Width           =   615 
      End 
      Begin VB.OptionButton Option2  
         Caption         =   "Y轴" 
         Height          =   300 
         Left            =   3120 
         TabIndex        =   4 
         Top             =   360 
         Width           =   735 
      End 
      Begin VB.OptionButton Option_AXISST  
         Caption         =   "X轴" 
         Height          =   255 
         Left            =   2400 
         TabIndex        =   3 
         Top             =   360 
         Width           =   615 
      End 
      Begin VB.Label Label_Irq  
         Caption         =   "中断号:0x00" 
         Height          =   255 
         Left            =   240 
         TabIndex        =   2 
         Top             =   840 
         Width           =   1695 
      End 
      Begin VB.Label Label_Address  
         Caption         =   "基地址:0x0000" 
         Height          =   375 
         Left            =   240 
         TabIndex        =   1 
         Top             =   360 
         Width           =   1575 
      End 
   End 
   Begin VB.Label Label_StaPos  
      Alignment       =   2  'Center 
      BorderStyle     =   1  'Fixed Single 
      Caption         =   "Label7" 
      Height          =   375 
      Left            =   120 
      TabIndex        =   28 
      Top             =   3960 
      Width           =   5535 
   End 
End 
Attribute VB_Name = "MAIN_FRAME" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
'定义四个轴的常量 
Const XCH As Integer = 0 
Const YCH As Integer = 1 
Const ZCH As Integer = 2 
Const UCH As Integer = 3 
 
'******************************************** 
'    雷赛DMC1000控制卡编程示例之一 
' 
'? -主要演示功能: 
'    1. 控制卡的基本操作 
'    2. 单轴驱动脉冲,驱动模式 
'    3. T形和S形驱动方式选择 
'    4. 减速或急停控制,外部减速停 
'    5. 位置显示,位置清零及指定轴状态显示 
'    6. 定量驱动和持续驱动选择 
' 
'!-关键函数: 
'    1. 控制卡的基本操作函数 
'        d1000_board_init , d1000_board_close, d1000_get_board_base 
'        d1000_get_irq_channel 
' 
'    2. 单轴驱动,T形及S形选择 
'        d1000_set_pls_outmode , d1000_set_pls_logic 
'        d1000_start_tv_move 持续驱动 
'        d1000_start_sv_move 
'        d1000_start_tr_move 定量驱动 
'        d1000_start_sr_move 
' 
'    3. 减速或急停 
'        d1000_decel_stop 当减速时间为0时为急停 
'        d1000_set_sd_enable 
' 
'    4. 位置显示及状态显示 
'        d1000_get_abs_position 
'        d1000_set_position 
'        d1000_check_done 
'        d1000_get_axis_status 
' 
'#-注意事项: 
'    1. 本例虽然只提供了四个驱动函数,实质上其它驱动函数都一致 
' 
' 
'    Writen by LEISAI-SUPPORT 
'    FAX: 0755 - 26402718 
'    TEL: 0755 - 26434329 
'EMAIL:     support@ LEISAI.com 
'HTTP:     www.LEISAI.com 
'******************************************** 
Dim nAxis As Integer    ' 选择的驱动轴 
Dim nSpeed As Integer   'S形或T形选择 
Dim nMove As Integer    '定量或持续选择 
 
Private Sub Check_Dir_Click() 
    UpdateControl 
End Sub 
 
Private Sub Check_PLogic_Click() 
    UpdateControl 
End Sub 
 
Private Sub Check_Pmode_Click() 
    UpdateControl 
End Sub 
 
 
Private Sub Command_ClsPos_Click() 
'位置清零 
    For i = 0 To 4 
        d1000_set_command_pos i, 0 
    Next 
End Sub 
 
Private Sub Command_Start_Click() 
'开始 
    Dim nStart, nSpeed, nPulse As Long 
    Dim fAccel As Double 
    Dim nDir As Integer 
     
    If d1000_check_done(nAxis) = 0 Then '若在运行,则返回 
        Exit Sub 
    End If 
    nStart = Val(Text_Start.Text) 
    nSpeed = Val(Text_Speed.Text) 
    fAccel = Val(Text_Time.Text) 
    nPulse = Val(Text_Pulse.Text) 
     
    If Check_Dir = 1 Then 
        nDir = 1 
    Else 
        nDir = -1 
    End If 
     
    '设定参数 
    If Check_Pmode = 1 Then 
        d1000_set_pls_outmode nAxis, 1 
    Else 
        d1000_set_pls_outmode nAxis, 0 
    End If 
    'If Check_PLogic = 1 Then 
    '    d1000_set_pls_logic nAxis, 1 
    'Else 
    '    d1000_set_pls_logic nAxis, 0 
    'End If 
     
    'If Check_SD = 1 Then 
    '    d1000_set_sd_enable nAxis, 1 
    'Else 
    '    d1000_set_sd_enable nAxis, 0 
    'End If 
 
    If nMove = 0 Then '定量 
        If nSpeed = 0 Then 'S形 
            d1000_start_s_move nAxis, nPulse * nDir, nStart, nSpeed, fAccel 
        Else 
            d1000_start_t_move nAxis, nPulse * nDir, nStart, nSpeed, fAccel 
        End If 
    Else '持续 
        If nSpeed = 0 Then 'S形 
            d1000_start_sv_move nAxis, nStart, nSpeed * nDir, m_fAccel 
        Else 
            d1000_start_tv_move nAxis, nStart, nSpeed * nDir, m_fAccel 
        End If 
    End If 
End Sub 
 
Private Sub Command_Stop_Click() 
'停止驱动 
    If d1000_check_done(XCH) = 0 Or d1000_check_done(YCH) = 0 Or d1000_check_done(ZCH) = 0 Or d1000_check_done(UCH) = 0 Then          '在运行 
        d1000_decel_stop (XCH) 
        d1000_decel_stop (YCH) 
        d1000_decel_stop (ZCH) 
        d1000_decel_stop (UCH) 
    End If 
End Sub 
 
Private Sub Form_Load() 
    Dim nCard As Integer 
    d1000_board_close 
    nCard = d1000_board_init() 
    If nCard < 1 Then '控制卡初始化 
        MsgBox "未找到控制卡!", vbOKOnly, "警告" 
    Else 
        '找到控制卡 
        Label_Address.Caption = "地址:0x" + Str(d1000_get_base_addr(0)) 
        Label_Irq.Caption = "中断号:0x" + Str(d1000_get_irq_channel(0)) 
        Check_Pmode = 1 
        Check_PLogic = 1 
        Check_Dir = 1 
        Check_SD = 1 
    End If 
    UpdateControl 
End Sub 
 
Private Sub Form_Unload(Cancel As Integer) 
    d1000_board_close    '关闭控制卡(此句一定要有) 
 
End Sub 
 
Private Sub Option_AXISST_Click() 
    nAxis = XCH 
End Sub 
 
Private Sub Option_MOVEST_Click() 
    nMove = 0 
End Sub 
 
Private Sub Option_SpeedST_Click() 
    nSpeed = 0 
End Sub 
 
Private Sub Option2_Click() 
    nAxis = YCH 
End Sub 
 
Private Sub Option3_Click() 
    nAxis = ZCH 
End Sub 
 
Private Sub Option4_Click() 
    nAxis = UCH 
End Sub 
 
Private Sub Option6_Click() 
    nMove = 1 
End Sub 
 
Private Sub Option8_Click() 
    nSpeed = 1 
End Sub 
 
Private Sub Timer1_Timer() 
 
    Label_StaPos.Caption = "状态:" + Str(d1000_get_axis_status(XCH)) 
    Label_StaPos.Caption = Label_StaPos.Caption + "," + Str(d1000_get_axis_status(YCH)) 
    Label_StaPos.Caption = Label_StaPos.Caption + "," + Str(d1000_get_axis_status(ZCH)) 
    Label_StaPos.Caption = Label_StaPos.Caption + "," + Str(d1000_get_axis_status(UCH)) 
    Label_StaPos.Caption = Label_StaPos.Caption + " #位置:" + Str(d1000_get_command_pos(XCH)) 
    Label_StaPos.Caption = Label_StaPos.Caption + "," + Str(d1000_get_command_pos(YCH)) 
    Label_StaPos.Caption = Label_StaPos.Caption + "," + Str(d1000_get_command_pos(ZCH)) 
    Label_StaPos.Caption = Label_StaPos.Caption + "," + Str(d1000_get_command_pos(UCH)) 
  
End Sub 
 
Public Sub UpdateControl() 
    If Check_Pmode = 1 Then 
        Check_Pmode.Caption = "脉冲+方向" 
    Else 
        Check_Pmode.Caption = "脉冲+脉冲" 
    End If 
     
    If Check_PLogic = 1 Then 
        Check_PLogic.Caption = "脉冲逻辑:正" 
    Else 
        Check_PLogic.Caption = "脉冲逻辑:负" 
    End If 
     
    If Check_Dir = 1 Then 
        Check_Dir.Caption = "驱动方向:正" 
    Else 
        Check_Dir.Caption = "驱动方向:负" 
    End If 
     
     
End Sub