www.pudn.com > Vb6.0.rar > mainframe.frm, change:2004-03-17,size:8411b


VERSION 5.00 
Begin VB.Form Main_Frame  
   Caption         =   "DMC1000编程示例之二" 
   ClientHeight    =   2415 
   ClientLeft      =   3795 
   ClientTop       =   4065 
   ClientWidth     =   4200 
   LinkTopic       =   "Form1" 
   ScaleHeight     =   2415 
   ScaleWidth      =   4200 
   Begin VB.Timer Timer1  
      Interval        =   100 
      Left            =   2640 
      Top             =   120 
   End 
   Begin VB.CommandButton Command_Stop  
      Caption         =   "停止" 
      Height          =   375 
      Left            =   3000 
      TabIndex        =   10 
      Top             =   1560 
      Width           =   1095 
   End 
   Begin VB.CommandButton Command_All  
      Caption         =   "四轴回原点" 
      Height          =   1215 
      Left            =   3000 
      TabIndex        =   9 
      Top             =   240 
      Width           =   1095 
   End 
   Begin VB.CommandButton Command_U  
      Caption         =   "执行" 
      Height          =   255 
      Left            =   2040 
      TabIndex        =   7 
      Top             =   1680 
      Width           =   735 
   End 
   Begin VB.CommandButton Command_Z  
      Caption         =   "执行" 
      Height          =   255 
      Left            =   2040 
      TabIndex        =   6 
      Top             =   1200 
      Width           =   735 
   End 
   Begin VB.CommandButton Command_Y  
      Caption         =   "执行" 
      Height          =   255 
      Left            =   2040 
      TabIndex        =   5 
      Top             =   720 
      Width           =   735 
   End 
   Begin VB.CommandButton Command_X  
      Caption         =   "执行" 
      Height          =   255 
      Left            =   2040 
      TabIndex        =   4 
      Top             =   240 
      Width           =   735 
   End 
   Begin VB.CheckBox Check_U  
      Caption         =   "U回原点方向:正" 
      Height          =   375 
      Left            =   120 
      TabIndex        =   3 
      Top             =   1560 
      Width           =   1695 
   End 
   Begin VB.CheckBox Check_Z  
      Caption         =   "Z回原点方向:正" 
      Height          =   375 
      Left            =   120 
      TabIndex        =   2 
      Top             =   1200 
      Width           =   1695 
   End 
   Begin VB.CheckBox Check_Y  
      Caption         =   "Y回原点方向:正" 
      Height          =   375 
      Left            =   120 
      TabIndex        =   1 
      Top             =   720 
      Width           =   1695 
   End 
   Begin VB.CheckBox Check_X  
      Caption         =   "X回原点方向:正" 
      Height          =   255 
      Left            =   120 
      TabIndex        =   0 
      Top             =   240 
      Width           =   1695 
   End 
   Begin VB.Label Label_Status  
      Alignment       =   2  'Center 
      BorderStyle     =   1  'Fixed Single 
      Caption         =   "Label1" 
      Height          =   255 
      Left            =   120 
      TabIndex        =   8 
      Top             =   2040 
      Width           =   3975 
   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. 多轴回原点操作 
' 
'!-关键函数: 
'    回原点函数 
'        d1000_home_move         //单轴 
' 
'    查询原点输入信号 
'        d1000_get_axis_status 
' 
' 
'#-注意事项: 
'查询原点信号:         因d1000_get_axis_status返回多个输入信号在 
'    同一个整数内,而原点状态为2位,故其状态查询为: 
' 
'        status = (d1000_get_axis_status( 0 )&0x04 )==0x04; 
' 
'此时: 
'        Status 的值只有0和1两种 
' 
' 
'    Writen by LEISAI-SUPPORT 
'    FAX: 0755 - 26402718 
'    TEL: 0755 - 26434329 
'EMAIL:     support@ leisai.com 
'HTTP:     www.leisai.com 
'******************************************** 
 
Private Sub Check_U_Click() 
    UpdateControl 
End Sub 
 
Private Sub Check_X_Click() 
    UpdateControl 
End Sub 
 
Private Sub Check_Y_Click() 
    UpdateControl 
End Sub 
 
Private Sub Check_Z_Click() 
    UpdateControl 
End Sub 
 
Private Sub Command_All_Click() 
    Const MAX_AXIS As Integer = 4 
    '配置参数 
    Dim axis(MAX_AXIS) As Integer 
    Dim start(MAX_AXIS) As Long 
    Dim speed(MAX_AXIS) As Long 
    Dim accel(MAX_AXIS) As Double 
     
    axis(0) = XCH 
    axis(1) = YCH 
    axis(2) = ZCH 
    axis(3) = UCH 
     
    start(0) = 1600 
    start(1) = 1600 
    start(2) = 1600 
    start(3) = 1600 
     
    If Check_X = 1 Then 
        speed(0) = 3200 
    Else 
        speed(0) = -3200 
    End If 
     
    If Check_Y = 1 Then 
        speed(1) = 6400 
    Else 
        speed(1) = -6400 
    End If 
     
    If Check_Z = 1 Then 
        speed(2) = 12800 
    Else 
        speed(2) = -12800 
    End If 
     
    If Check_U Then 
        speed(3) = 1600 
    Else 
        speed(3) = -1600 
    End If 
     
         
    accel(0) = accel(1) = accel(2) = accel(3) = 0.1 
 
    For i = 0 To 4 
        d1000_home_move axis(i), start(i), speed(i), accel(i) 
    Next 
   
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 Command_U_Click() 
    If Check_U = 1 Then 
        d1000_home_move UCH, 1600, 1600, 0.1 
    Else 
        d1000_home_move UCH, 1600, -1600, 0.1 
    End If 
End Sub 
 
Private Sub Command_X_Click() 
     
    If Check_X = 1 Then 
        d1000_home_move XCH, 1600, 6400, 0.1 
    Else 
        d1000_home_move XCH, 1600, -6400, 0.1 
    End If 
     
End Sub 
 
Private Sub Command_Y_Click() 
    If Check_Y = 1 Then 
        d1000_home_move YCH, 1600, 3200, 0.1 
    Else 
        d1000_home_move YCH, 1600, -3200, 0.1 
    End If 
 
End Sub 
 
Private Sub Command_Z_Click() 
    If Check_Z = 1 Then 
        d1000_home_move ZCH, 1600, 12800, 0.1 
    Else 
        d1000_home_move ZCH, 1600, -12800, 0.1 
    End If 
End Sub 
Private Sub Form_Load() 
    If d1000_board_init() <= 0 Then '控制卡初始化 
        MsgBox "未找到控制卡!", vbOKOnly, "警告" 
    End If 
     
    Check_X = Check_Y = Check_Z = Check_U = 1 
    UpdateControl 
 
End Sub 
 
Private Sub UpdateControl() 
 
    If Check_X = 1 Then 
        Check_X.Caption = "X回原点方向:正" 
    Else 
        Check_X.Caption = "X回原点方向:负" 
    End If 
     
    If Check_Y = 1 Then 
        Check_Y.Caption = "Y回原点方向:正" 
    Else 
        Check_Y.Caption = "Y回原点方向:负" 
    End If 
     
    If Check_Z = 1 Then 
        Check_Z.Caption = "Z回原点方向:正" 
    Else 
        Check_Z.Caption = "Z回原点方向:负" 
    End If 
     
    If Check_U = 1 Then 
        Check_U.Caption = "U回原点方向:正" 
    Else 
        Check_U.Caption = "U回原点方向:负" 
    End If 
     
End Sub 
 
Private Sub Form_Unload(Cancel As Integer) 
    d1000_board_close '再次强调,一定调用此函数 
End Sub 
 
Private Sub Timer1_Timer() 
 
    Const ORGIN As Integer = 4 '第二位为原点信号 
    Dim nStatus As Integer 
     
    nStatus = d1000_get_axis_status(XCH) And ORGIN 
     
    If nStatus <> ORGIN Then 
        Label_Status.Caption = "原点信号:1," 
    Else 
        Label_Status.Caption = "原点信号:0," 
    End If 
     
    nStatus = d1000_get_axis_status(YCH) And ORGIN 
    If nStatus <> ORGIN Then 
        Label_Status.Caption = Label_Status.Caption + "1," 
    Else 
        Label_Status.Caption = Label_Status.Caption + "0," 
    End If 
     
    nStatus = d1000_get_axis_status(ZCH) And ORGIN 
    If nStatus <> ORGIN Then 
        Label_Status.Caption = Label_Status.Caption + "1," 
    Else 
        Label_Status.Caption = Label_Status.Caption + "0," 
    End If 
     
    nStatus = d1000_get_axis_status(UCH) And ORGIN 
    If nStatus <> ORGIN Then 
        Label_Status.Caption = Label_Status.Caption + "1" 
    Else 
        Label_Status.Caption = Label_Status.Caption + "0" 
    End If 
       
End Sub