
Public Class MianForm
    Public g_CheckManual As Boolean
    Public MaxAxi As Int32 = 4  '最大轴号
    Public m_StopFlag As Boolean = False  '停止标志
    Public Const INPA_AXISREG As Int32 = &H3F '63

    '基本运动界面的参数数组
    Public StartV(MaxAxi - 1) As Single
    Public Speed(MaxAxi - 1) As Single
    Public Acc(MaxAxi - 1) As Single
    Public Dec(MaxAxi - 1) As Single
    Public Gear(MaxAxi - 1) As Single 'Gear也是浮点类型

    '插补参数
    Public InpStartv As Single
    Public InpSpeedv As Single
    Public InpAcc As Single
    Public InpDec As Single
    Public InpAddMode As Int32

    '加减速类型
    Public m_addMode As Int32

    '复合运动界面的参数数组
    Public StartV1(MaxAxi - 1) As Single
    Public Speed1(MaxAxi - 1) As Single
    Public TAcc(MaxAxi - 1) As Single
    Public TDec(MaxAxi - 1) As Single
    Public VAcc(MaxAxi - 1) As Single
    '实时状态的参数数组
    Public TPulse(MaxAxi - 1) As Single
    '顺时针／逆时针
    Public m_dir As Int32
    '梯形／Ｓ型
    Public m_style As Int32
    '相对运动／绝对运动
    Public m_relative As Int32

    '位置锁存界面参数刷新
    '计数器模式
    Public m_counter As Int32
    '有效电平
    Public m_effective As Int32
    '锁存位置控件数组
    Public TlockPos As New ArrayList

    '同步／步进界面参数
    '寄存器类型
    Public m_reg As Int32
    '关系运算符
    Public m_relation As Int32
    '主轴运行状态
    Public m_mainAxiKeep As Int32
    '信号随动状态
    Public m_SignalStatus As Int32
    '主动轴运行状态
    Public m_mainAxiStatus As Int32
    '脉冲
    Public m_SpePulse(MaxAxi - 1) As Int32

    'IO检测的参数设置
    Public TInput As New ArrayList
    Public TOutput As New ArrayList

    '实时速度，实时逻辑位置，实时目标位置的控件数组
    Public TLogPos, TActPos, TSpeed As New ArrayList
    '限位信号，停止信号，错误停止信息的控件数组
    Public TLmt1, TLmt2, TStop0, TStop1, TStop2, TStopData As New ArrayList

    '保存原始param设置
    Dim m_pulseMode() As Int32 = {1, 1, 1, 1} '1为脉冲+脉冲模式
    Dim m_limitZ() As Int32 = {0, 0, 0, 0}    '正负限位默认有效且用0来表示有效
    Dim m_limitF() As Int32 = {0, 0, 0, 0}    '同上
    Dim m_stop0() As Int32 = {0, 0, 0, 0}     'stop0默认无效 - 0
    Dim m_stop1() As Int32 = {0, 0, 0, 0}     'stop1默认无效
    Dim m_effectiveParam() As Int32 = {0, 0, 0, 0} '0为低调评有效
    Dim m_hardStopEffect As Int32 = -1
    Dim m_hardStoplogic As Int32 = 0

    '设置减速度标志
    Public Shared m_decFlag As Int32 = 0
    '初始化界面
    Private Sub MianForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '初始化卡
        Init_Board()

        '获取库函数版本号
        Dim LibVer As Int32
        LibVer = adt8949_get_lib_version()
        ToolStripStatusLabel3.Text &= CStr(LibVer >> 16)
        ToolStripStatusLabel3.Text &= "."
        ToolStripStatusLabel3.Text &= CStr(LibVer And &HFFFF)

        '获取固件版本
        LibVer = adt8949_get_firmware_ver(gCardIndex)
        ToolStripStatusLabel1.Text &= CStr((LibVer And &H7000000) >> 24)
        ToolStripStatusLabel1.Text &= "."
        ToolStripStatusLabel1.Text &= CStr((LibVer And &HFF0000) >> 16)
        ToolStripStatusLabel1.Text &= "."
        ToolStripStatusLabel1.Text &= CStr(LibVer And &HFFFF)



        '默认选中联动
        Pmove.Checked = True
        '默认为运动类型1
        AddMode1.Checked = True
        m_addMode = 1

        '默认四个运动轴都被选中
        CheckAll.Checked = True
        CheckAll.Text = "Choose ALL"
        CheckAxisX.Checked = True
        CheckAxisY.Checked = True
        CheckAxisZ.Checked = True
        CheckAxisA.Checked = True

        '简单运动界面圆弧方向默认为顺时针
        ArcDir1.Checked = True
        m_dir = 0

        '将回零按钮设置为不可用
        Return0.Enabled = False

        '初始化输入输入空间数组
        Dim InPutContol() As Object = {INO, IN1, IN2, IN3, IN4, IN5, IN6, IN7, IN8, IN9, IN10, IN11, IN12, IN13, IN14, IN15, IN16, IN17, IN18, IN19, IN20, IN21, IN22, IN23, IN24, IN25, IN26, IN27, IN28, IN29, IN30, IN31, IN32, IN33, IN34, IN35, IN36, IN37, IN38, IN39, IN40, IN41, IN42, IN43, IN44, IN45, IN46, IN47}

        Dim OutPutContol() As Object = {OUT0, OUT1, OUT2, OUT3, OUT4, OUT5, OUT6, OUT7, OUT8, OUT9, OUT10, OUT11, OUT12, OUT13, OUT14, OUT15, OUT16, OUT17, OUT18, OUT19, OUT20, OUT21, OUT22, OUT23, OUT24, OUT25, OUT26, OUT27, OUT28, OUT29, OUT30, OUT31}

        Dim i As Int32

        For i = 0 To 47

            TInput.Add(InPutContol(i))

        Next i

        'MessageBox.Show(TInput.Capacity)

        For i = 0 To 31

            TOutput.Add(OutPutContol(i))

        Next i


    End Sub

    '卡的初始化函数
    Private Sub Init_Board()

        Dim count, i As Integer

        count = Init_Card()

        If count < 1 Then

            MsgBox("no installation of adt8949 card ")
            ToolStripStatusLabel2.Text &= "0"

        Else

            MsgBox("8949G1 Number：" + CStr(count))

            For i = 0 To count - 1

                CardIndex.Items.Insert(i, CStr(i))

            Next i

            ToolStripStatusLabel2.Text &= CStr(count)

            CardIndex.Text = 0

        End If

    End Sub

    '设置全选和反选
    Private Sub CheckAll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckAll.CheckedChanged

        If CheckAll.Checked = True Then
            CheckAll.Text = "No Choose"
            CheckAxisX.Checked = True
            CheckAxisY.Checked = True
            CheckAxisZ.Checked = True
            CheckAxisA.Checked = True

        Else
            CheckAll.Text = "Choose ALL"
            CheckAxisX.Checked = False
            CheckAxisY.Checked = False
            CheckAxisZ.Checked = False
            CheckAxisA.Checked = False

        End If

    End Sub


    '基本运动界面启动按钮响应函数
    Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click
        If Pmove.Checked Then  'pmove响应
            Motion_Pmove()
        End If

        If Cmove.Checked Then  '连续运动响应
            Motion_Cmove()
        End If

        If AbsPmove.Checked Then '绝对位置联动
            Motion_AbsPmove()
        End If

    End Sub
    Private Sub Motion_AbsPmove()
        '刷新各运动参数
        RefreshPara()

        If CheckAxisX.Checked = True Then
            '设置速度
            Setup_Speed(1, StartV(0), Speed(0), Acc(0), Dec(0), m_addMode)
            '设置目标脉冲
            adt8949_abs_pmove(gCardIndex, 1, TPulse(0))
        End If

        If CheckAxisY.Checked = True Then
            '设置速度
            Setup_Speed(2, StartV(1), Speed(1), Acc(1), Dec(1), m_addMode)
            '设置目标脉冲
            adt8949_abs_pmove(gCardIndex, 2, TPulse(1))
        End If

        If CheckAxisZ.Checked = True Then
            '设置速度
            Setup_Speed(3, StartV(2), Speed(2), Acc(2), Dec(2), m_addMode)
            '设置目标脉冲
            adt8949_abs_pmove(gCardIndex, 3, TPulse(2))
        End If

        If CheckAxisA.Checked = True Then
            '设置速度
            Setup_Speed(4, StartV(3), Speed(3), Acc(3), Dec(3), m_addMode)
            '设置目标脉冲
            adt8949_abs_pmove(gCardIndex, 4, TPulse(3))
        End If
    End Sub

    '联动响应函数
    Private Sub Motion_Pmove()

        '刷新各运动参数
        RefreshPara()
        EnableAllButton(0)
        m_StopFlag = False

        If CheckAxisX.Checked = True Then
            '设置速度
            Setup_Speed(1, StartV(0), Speed(0), Acc(0), Dec(0), m_addMode)
            '设置目标脉冲
            adt8949_pmove(gCardIndex, 1, TPulse(0))
        End If

        If CheckAxisY.Checked = True Then
            '设置速度
            Setup_Speed(2, StartV(1), Speed(1), Acc(1), Dec(1), m_addMode)
            '设置目标脉冲
            adt8949_pmove(gCardIndex, 2, TPulse(1))
        End If

        If CheckAxisZ.Checked = True Then
            '设置速度
            Setup_Speed(3, StartV(2), Speed(2), Acc(2), Dec(2), m_addMode)
            '设置目标脉冲
            adt8949_pmove(gCardIndex, 3, TPulse(2))
        End If

        If CheckAxisA.Checked = True Then
            '设置速度
            Setup_Speed(4, StartV(3), Speed(3), Acc(3), Dec(3), m_addMode)
            '设置目标脉冲
            adt8949_pmove(gCardIndex, 4, TPulse(3))
        End If

        'Dim statusX, statusY, statusZ, statusA As Int32
        Dim m_speedX, m_speedY, m_speedZ, m_speedA As Single
        While True

            DoEvents()
            sleep(1)
            adt8949_get_speed(gCardIndex, 1, m_speedX)
            adt8949_get_speed(gCardIndex, 2, m_speedY)
            adt8949_get_speed(gCardIndex, 3, m_speedZ)
            adt8949_get_speed(gCardIndex, 4, m_speedA)
            If m_speedX = 0 And m_speedY = 0 And m_speedZ = 0 And m_speedA = 0 Then
                Exit While
            End If
            If m_StopFlag = True Then
                Exit While
            End If
        End While

        EnableAllButton(1)
    End Sub

    '连续运动响应函数
    Private Sub Motion_Cmove()

        m_StopFlag = 1

        '刷新各运动参数
        RefreshPara()
        If CheckAxisX.Checked = False And CheckAxisY.Checked = False And CheckAxisZ.Checked = False And CheckAxisA.Checked = False Then
            MsgBox("Please choose axis")
            Exit Sub
        End If
        EnableAllButton(1)

        If CheckAxisX.Checked = True Then
            '设置速度
            Setup_Speed(1, StartV(0), Speed(0), Acc(0), Dec(0), m_addMode)
            '设置目标脉冲
            adt8949_continue_move(gCardIndex, 1, 0)
        End If

        If CheckAxisY.Checked = True Then
            '设置速度
            Setup_Speed(2, StartV(1), Speed(1), Acc(1), Dec(1), m_addMode)
            '设置目标脉冲
            adt8949_continue_move(gCardIndex, 2, 0)
        End If

        If CheckAxisZ.Checked = True Then
            '设置速度
            Setup_Speed(3, StartV(2), Speed(2), Acc(2), Dec(2), m_addMode)
            '设置目标脉冲
            adt8949_continue_move(gCardIndex, 3, 0)
        End If

        If CheckAxisA.Checked = True Then
            '设置速度
            Setup_Speed(4, StartV(3), Speed(3), Acc(3), Dec(3), m_addMode)
            '设置目标脉冲
            adt8949_continue_move(gCardIndex, 4, 0)
        End If

        'Dim status1 As Int32, status2 As Int32, status3 As Int32, status4 As Int32

        'While 1


        'End While
    End Sub

    '直线插补响应函数
    Private Sub Motion_LineInp()
        m_StopFlag = False

        '刷新各运动参数
        RefreshPara()
        Setup_Speed(INPA_AXISREG, InpStartv, InpSpeedv, InpAcc, InpDec, m_addMode)
        If CheckAxisX.Checked = False And CheckAxisY.Checked = False And CheckAxisZ.Checked = False And CheckAxisA.Checked = False Then
            MsgBox("Please choose axis")
            Exit Sub
        End If

        '单轴插补
        If CheckAxisX.Checked And CheckAxisY.Checked = False And CheckAxisZ.Checked = False And CheckAxisA.Checked = False Then
            adt8949_inp_move4(gCardIndex, 0, TPulse(0), 0, 0, 0)
        End If

        If CheckAxisX.Checked = False And CheckAxisY.Checked And CheckAxisZ.Checked = False And CheckAxisA.Checked = False Then
            adt8949_inp_move4(gCardIndex, 0, 0, TPulse(1), 0, 0)
        End If

        If CheckAxisX.Checked = False And CheckAxisY.Checked = False And CheckAxisZ.Checked And CheckAxisA.Checked = False Then
            adt8949_inp_move4(gCardIndex, 0, 0, 0, TPulse(2), 0)
        End If

        If CheckAxisX.Checked = False And CheckAxisY.Checked = False And CheckAxisZ.Checked = False And CheckAxisA.Checked Then
            adt8949_inp_move4(gCardIndex, 0, 0, 0, 0, TPulse(3))
        End If

        '两轴插补
        If CheckAxisX.Checked And CheckAxisY.Checked And CheckAxisZ.Checked = False And CheckAxisA.Checked = False Then
            adt8949_inp_move4(gCardIndex, 0, TPulse(0), TPulse(1), 0, 0)
        End If

        If CheckAxisX.Checked And CheckAxisY.Checked = False And CheckAxisZ.Checked And CheckAxisA.Checked = False Then
            adt8949_inp_move4(gCardIndex, 0, TPulse(0), 0, TPulse(2), 0)
        End If

        If CheckAxisX.Checked And CheckAxisY.Checked = False And CheckAxisZ.Checked = False And CheckAxisA.Checked Then
            adt8949_inp_move4(gCardIndex, 0, TPulse(0), 0, 0, TPulse(3))
        End If

        If CheckAxisX.Checked = False And CheckAxisY.Checked And CheckAxisZ.Checked And CheckAxisA.Checked = False Then
            adt8949_inp_move4(gCardIndex, 0, 0, TPulse(1), TPulse(2), 0)
        End If

        If CheckAxisX.Checked = False And CheckAxisY.Checked And CheckAxisZ.Checked = False And CheckAxisA.Checked Then
            adt8949_inp_move4(gCardIndex, 0, 0, TPulse(1), 0, TPulse(3))
        End If

        If CheckAxisX.Checked = False And CheckAxisY.Checked = False And CheckAxisZ.Checked And CheckAxisA.Checked Then
            adt8949_inp_move4(gCardIndex, 0, 0, 0, TPulse(2), TPulse(3))
        End If

        '三轴插补
        If CheckAxisX.Checked And CheckAxisY.Checked And CheckAxisZ.Checked And CheckAxisA.Checked = False Then
            adt8949_inp_move4(gCardIndex, 0, TPulse(0), TPulse(1), TPulse(2), 0)
        End If

        If CheckAxisX.Checked And CheckAxisY.Checked = False And CheckAxisZ.Checked And CheckAxisA.Checked Then
            adt8949_inp_move4(gCardIndex, 0, TPulse(0), 0, TPulse(2), TPulse(3))
        End If

        If CheckAxisX.Checked And CheckAxisY.Checked And CheckAxisZ.Checked = False And CheckAxisA.Checked Then
            adt8949_inp_move4(gCardIndex, 0, TPulse(0), TPulse(1), 0, TPulse(3))
        End If

        If CheckAxisX.Checked = False And CheckAxisY.Checked And CheckAxisZ.Checked And CheckAxisA.Checked Then
            adt8949_inp_move4(gCardIndex, 0, 0, TPulse(1), TPulse(2), TPulse(3))
        End If

        '四轴插补
        If CheckAxisX.Checked And CheckAxisY.Checked And CheckAxisZ.Checked And CheckAxisA.Checked Then
            adt8949_inp_move4(gCardIndex, 0, TPulse(0), TPulse(1), TPulse(2), TPulse(3))
        End If

        EnableAllButton(0)
        Dim m_inpStatus As Int32 = -1

        While 1
            DoEvents()
            sleep(1)
            adt8949_get_inp_status(gCardIndex, m_inpStatus)
            If m_inpStatus = 0 Then
                EnableAllButton(1)
                Exit While
            End If

            If m_StopFlag = True Then
                Exit While
            End If

        End While

    End Sub

    Public Sub EnableAllButton(ByVal mode As Int32)
        If mode = 0 Then
            Start.Enabled = False
            InpMove.Enabled = False
            InpArc.Enabled = False
            InpTime.Enabled = False
            InpNurbs.Enabled = False
            If TabControl1.TabIndex = 1 Then
                Return0.Enabled = False
            End If

        End If
        If mode = 1 Then
            Start.Enabled = True
            InpMove.Enabled = True
            InpArc.Enabled = True
            InpTime.Enabled = True
            InpNurbs.Enabled = True
            If TabControl1.TabIndex = 1 Then
                Return0.Enabled = True
            End If

        End If

    End Sub

    '圆弧插补响应函数
    Private Sub Motion_ArcInp()

        m_StopFlag = False

        '刷新各运动参数
        RefreshPara()
        EnableAllButton(0)
        '不能用S曲线加减速
        If m_addMode = 0 Then
            MsgBox("Cannot use s mode")
            Exit Sub
        End If
        Setup_Speed(INPA_AXISREG, InpStartv, InpSpeedv, InpAcc, InpDec, m_addMode)

        Dim mPulse As Single() = {0, 0, 10, 10} 'vb.net的数组做形参形式
        Dim mCenter As Single() = {10, 10, 10, 10}


        If ArcDir1.Checked Then '顺时针 
            adt8949_inp_arc2(gCardIndex, 0, 3, mPulse, mCenter, 1)
        Else '逆时针
            adt8949_inp_arc2(INPA_AXISREG, 0, 3, mPulse, mCenter, 0)
        End If

        Dim mInpStatus As Int32 = -1
        While 1
            DoEvents()
            sleep(1)
            adt8949_get_inp_status(gCardIndex, mInpStatus)

            If mInpStatus = 0 Then
                Exit While
            End If

            If m_StopFlag = True Then
                Exit While
            End If


        End While
        EnableAllButton(1)

    End Sub


    '将控件与数组关联起来，提高程序的可读性
    Private Sub Get_ControlArray()
        TLogPos.Add(LogPosX)
        TLogPos.Add(LogPosY)
        TLogPos.Add(LogPosZ)
        TLogPos.Add(LogPosA)

        TActPos.Add(ActPosX)
        TActPos.Add(ActPosY)
        TActPos.Add(ActPosZ)
        TActPos.Add(ActPosA)

        TSpeed.Add(RunSpeedX)
        TSpeed.Add(RunSpeedY)
        TSpeed.Add(RunSpeedZ)
        TSpeed.Add(RunSpeedA)

        TLmt1.Add(LNT1X)
        TLmt1.Add(LNT1Y)
        TLmt1.Add(LNT1Z)
        TLmt1.Add(LNT1A)

        TLmt2.Add(LNT2X)
        TLmt2.Add(LNT2Y)
        TLmt2.Add(LNT2Z)
        TLmt2.Add(LNT2A)

        TStop0.Add(Stop0X)
        TStop0.Add(Stop0Y)
        TStop0.Add(Stop0Z)
        TStop0.Add(Stop0A)

        TStop1.Add(Stop1X)
        TStop1.Add(Stop1Y)
        TStop1.Add(Stop1Z)
        TStop1.Add(Stop1A)

        TStopData.Add(StopInfoX)
        TStopData.Add(StopInfoY)
        TStopData.Add(StopInfoZ)
        TStopData.Add(StopInfoA)
    End Sub

    '设置计时器
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Dim i, speed, Logpos, ActPos, ErroInfo As Int32

        Get_ControlArray()

        'If adt8949_read_bit(gCardIndex, 4, ) Then
        For i = 1 To MaxAxi

            Get_CurrentInf(i, Logpos, ActPos, speed)
            '逻辑位置
            TLogPos(i - 1).Text = Convert.ToString(Logpos)
            '实际位置
            TActPos(i - 1).Text = Convert.ToString(ActPos)
            '实时运行速度
            TSpeed(i - 1).Text = Convert.ToString(speed)
            '获取错误停止信息
            adt8949_get_stopdata(gCardIndex, i, ErroInfo)
            TStopData(i - 1).Text = Convert.ToString(ErroInfo)

        Next
        '正限位检测
        i = 4
        Dim j As Int32 = 0
        While i <= 10
            If adt8949_read_bit(gCardIndex, i) = 0 Then
                TLmt1(j).checked = True
            Else
                TLmt1(j).checked = False
            End If

            i += 2
            j += 1

        End While

        '负限位检测
        i = 5
        j = 0
        While i <= 11
            If adt8949_read_bit(gCardIndex, i) = 0 Then
                TLmt2(j).checked = True
            Else
                TLmt2(j).checked = False
            End If
            i += 2
            j += 1
        End While

        '检测stop0信号
        i = 12
        j = 0
        While i <= 15
            If adt8949_read_bit(gCardIndex, i) = 0 Then
                TStop0(j).checked = True
            Else
                TStop0(j).checked = False
            End If
            i += 1
            j += 1

        End While

        '检测Stop1信号
        i = 44
        j = 0
        While i < 47
            If adt8949_read_bit(gCardIndex, i) = 0 Then
                TStop1(j).checked = True
            Else
                TStop1(j).checked = False
            End If
            i += 1
            j += 1
        End While

    End Sub

    '位置清零响应函数
    Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click

        Dim i As Int32

        For i = 1 To MaxAxi
            '逻辑位置清零
            Setup_Pos(i, 0, 0)
            '实际位置清零
            Setup_Pos(i, 0, 1)
        Next

    End Sub

    '立即停止响应函数
    Private Sub BtnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStop.Click
        Dim i As Int32

        m_StopFlag = True

        For i = 1 To MaxAxi
            '立即停止
            StopRun(i, 0)
        Next

    End Sub

    '减速停止响应函数
    Private Sub BtnDecStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDecStop.Click

        m_StopFlag = True

        Dim i As Int32

        For i = 1 To MaxAxi
            '减速停止
            StopRun(i, 1)
        Next

    End Sub

    '刷新基本运动界面的参数，在每次运动时，先刷新参数到对应的数组，方便操作和程序的移植性
    Private Sub RefreshPara()

        '初始速度刷新
        StartV(0) = StartV_X.Text
        StartV(1) = StartV_Y.Text
        StartV(2) = StartV_Z.Text
        StartV(3) = StartV_A.Text

        '驱动速度刷新
        Speed(0) = Speed_X.Text
        Speed(1) = Speed_Y.Text
        Speed(2) = Speed_Z.Text
        Speed(3) = Speed_A.Text

        '加速度刷新
        Acc(0) = Acc_X.Text
        Acc(1) = Acc_Y.Text
        Acc(2) = Acc_Z.Text
        Acc(3) = Acc_A.Text

        '减速度刷新
        Dec(0) = Dec_X.Text
        Dec(1) = Dec_Y.Text
        Dec(2) = Dec_Z.Text
        Dec(3) = Dec_A.Text

        '目标脉冲刷新
        TPulse(0) = PulseX.Text
        TPulse(1) = PulseY.Text
        TPulse(2) = PulseZ.Text
        TPulse(3) = PulseA.Text

        '刷新齿轮比
        Gear(0) = GearX.Text
        Gear(1) = GearY.Text
        Gear(2) = GearZ.Text
        Gear(3) = GearA.Text

        '刷新插补参数
        InpStartv = Inp_Startv.Text
        InpSpeedv = Inp_Speedv.Text
        InpAcc = Inp_Acc.Text
        InpDec = Inp_Dec.Text

        '刷新运动类型
        If AddMode1.Checked Then
            m_addMode = 1
        End If

        If AddMode2.Checked = True Then
            m_addMode = 0
        End If

        If AddMode3.Checked Then
            m_addMode = 2
        End If

        If AddMode4.Checked Then
            m_addMode = 3
        End If

        '设定齿轮比
        Dim i As Int32 = 0
        For i = 1 To 4
            adt8949_set_gear(gCardIndex, i, Gear(i - 1))
        Next


        '***********************************刷新被选中的轴****************************************************

        '定义数组大小为4个元素
        'ReDim m_SelectInfo.selectAxi(MaxAxi - 1)

        'If CheckAxiX.Checked = True Then
        'm_SelectInfo.AxiNo += 1

        'm_SelectInfo.selectAxi(m_SelectInfo.AxiNo - 1) = 1
        'End If

        'If CheckAxiY.Checked = True Then
        ' m_SelectInfo.AxiNo += 1
        '
        ' m_SelectInfo.selectAxi(m_SelectInfo.AxiNo - 1) = 2
        'End If

        'If CheckAxiZ.Checked = True Then
        'm_SelectInfo.AxiNo += 1
        'm_SelectInfo.selectAxi(m_SelectInfo.AxiNo - 1) = 3
        'End If
        '
        ' If CheckAxiA.Checked = True Then
        'm_SelectInfo.AxiNo += 1
        'm_SelectInfo.selectAxi(m_SelectInfo.AxiNo - 1) = 4
        'End If

        ''获取最小轴号信息
        'm_SelectInfo.MinAxi = 100
        'Dim i As Int32

        'For i = 0 To m_SelectInfo.AxiNo - 1
        'If m_SelectInfo.selectAxi(i) < m_SelectInfo.MinAxi Then
        'm_SelectInfo.MinAxi = m_SelectInfo.selectAxi(i)
        'End If
        'Next

    End Sub

    '位置锁存界面参数刷新
    Private Sub RefreshPara1ock()

        '锁存位置控件数组
        TlockPos.Add(LLockPosX)
        TlockPos.Add(LLockPosY)
        TlockPos.Add(LLockPosZ)
        TlockPos.Add(LLockPosA)

        '逻辑／实数计数器
        If RLLog.Checked Then
            m_counter = 0
        End If

        If RLAct.Checked Then
            m_counter = 1
        End If

        '低电平／高电平
        If RLLow.Checked Then
            m_effective = 0
        End If

        If RLHigh.Checked Then
            m_effective = 1
        End If

    End Sub

    '锁存模式设置按钮响应
    Private Sub BtnLockMode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLockMode.Click
        RefreshPara1ock()

        If RLSignalX.Checked Then
            adt8949_set_lock_position(gCardIndex, 1, m_effective, 1)
        End If

        If RLSignalY.Checked Then
            adt8949_set_lock_position(gCardIndex, 2, m_effective, 1)
        End If

        If RLSignalZ.Checked Then
            adt8949_set_lock_position(gCardIndex, 3, m_effective, 1)
        End If

        If RLSignalA.Checked Then
            adt8949_set_lock_position(gCardIndex, 4, m_effective, 1)
        End If

    End Sub

    '锁存位置按钮响应
    Private Sub BtnLockPos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLockPos.Click
        Dim Status, pos, i As Int32

        If RLSignalX.Checked Then
            adt8949_get_lock_status(gCardIndex, 1, 1, Status)
            i = 1
        End If

        If RLSignalY.Checked Then
            adt8949_get_lock_status(gCardIndex, 2, 1, Status)
            i = 2
        End If

        If RLSignalZ.Checked Then
            adt8949_get_lock_status(gCardIndex, 3, 1, Status)
            i = 3
        End If

        If RLSignalA.Checked Then
            adt8949_get_lock_status(gCardIndex, 4, 1, Status)
            i = 4
        End If

        Dim m_logOrAct As Int32 = -1
        If RLLog.Checked Then
            m_logOrAct = &H10
        Else
            m_logOrAct = &H11
        End If

        If Status Then
            adt8949_get_lock_position(gCardIndex, i, m_logOrAct, pos)
            TlockPos(i).Text = Convert.ToString(pos)
        End If

    End Sub

    Private Sub SaveParam()
        '脉冲模式保存
        If PulseAndPulseX.Checked Then
            m_pulseMode(0) = 0
        Else
            m_pulseMode(0) = 1
        End If

        If PulseAndPulseY.Checked Then
            m_pulseMode(1) = 0
        Else
            m_pulseMode(1) = 1
        End If

        If PulseAndPulseZ.Checked Then
            m_pulseMode(2) = 0
        Else
            m_pulseMode(2) = 1
        End If

        If PulseAndPulseA.Checked Then
            m_pulseMode(3) = 0
        Else
            m_pulseMode(3) = 1
        End If

        '正限位设置
        If RadioButton9.Checked Then
            m_limitZ(0) = 1
        Else
            m_limitZ(0) = 1
        End If

        If RadioButton10.Checked Then
            m_limitZ(1) = 1
        Else
            m_limitZ(1) = 0
        End If

        If RadioButton12.Checked Then
            m_limitZ(2) = 1
        Else
            m_limitZ(2) = 0
        End If

        If RadioButton14.Checked Then
            m_limitZ(3) = 1
        Else
            m_limitZ(3) = 0
        End If


        '负限位设置
        If RadioButton16.Checked Then
            m_limitF(0) = 1
        Else
            m_limitF(0) = 0
        End If

        If RadioButton18.Checked Then
            m_limitF(1) = 1
        Else
            m_limitF(1) = 0
        End If

        If RadioButton20.Checked Then
            m_limitF(2) = 1
        Else
            m_limitF(2) = 0
        End If

        If RadioButton22.Checked Then
            m_limitF(3) = 1
        Else
            m_limitF(3) = 0
        End If


        'stop0保存
        If RadioButton25.Checked Then
            m_stop0(0) = 1
        Else
            m_stop0(0) = 0
        End If


        If RadioButton27.Checked Then
            m_stop0(1) = 1
        Else
            m_stop0(1) = 0
        End If

        If RadioButton29.Checked Then
            m_stop0(2) = 1
        Else
            m_stop0(2) = 0
        End If

        If RadioButton31.Checked Then
            m_stop0(3) = 1
        Else
            m_stop0(3) = 0
        End If


        'stop1保存
        If RadioButton33.Checked Then
            m_stop1(0) = 1
        Else
            m_stop1(0) = 0
        End If

        If RadioButton35.Checked Then
            m_stop1(1) = 1
        Else
            m_stop1(1) = 0
        End If

        If RadioButton37.Checked Then
            m_stop1(2) = 1
        Else
            m_stop1(2) = 0
        End If

        If RadioButton39.Checked Then
            m_stop1(3) = 1
        Else
            m_stop1(3) = 0
        End If


        '电平保存
        If RadioButton40.Checked Then
            m_effectiveParam(0) = 1
        Else
            m_effectiveParam(0) = 0
        End If

        If RadioButton42.Checked Then
            m_effectiveParam(1) = 1
        Else
            m_effectiveParam(1) = 0
        End If

        If RadioButton44.Checked Then
            m_effectiveParam(2) = 1
        Else
            m_effectiveParam(2) = 0
        End If

        If RadioButton46.Checked Then
            m_effectiveParam(3) = 1
        Else
            m_effectiveParam(3) = 0
        End If


        '急停信号设置
        If RadioButton50.Checked Then
            m_hardStopEffect = -1
        End If
        If RadioButton48.Checked Then
            m_hardStoplogic = 1
        Else
            m_hardStoplogic = 0
        End If

    End Sub


    '参数设置按钮响应函数
    Private Sub BtnSure_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSure.Click
        '刷新参数
        SaveParam()

        Dim i As Int32

        For i = 0 To MaxAxi - 1

            '脉冲输出方式设定
            adt8949_set_pulse_mode(gCardIndex, i + 1, m_pulseMode(i), 0, 0)
            '正负限位模式设定
            adt8949_set_limit_mode(gCardIndex, i + 1, m_limitZ(i), m_limitF(i), m_effectiveParam(i))

            'stop0信号模式设定
            adt8949_set_stop0_mode(gCardIndex, i + 1, m_stop0(i), m_effectiveParam(i), 1)

            'stop1信号模式设定
            adt8949_set_stop1_mode(gCardIndex, i + 1, m_stop1(i), m_effectiveParam(i), 1)

            'stop2信号模式设定
            '伺服到位信号模式设定
            '伺服报警信号模式设定
            '可变环型信号模式设定
            'comp+寄存器做软件限制的设定
            'comp-寄存器做软件限制的设定
            'comp+/-寄存器比较对象的设定
            'comp+寄存器的设定
            'comp-寄存器的设定
            '输入信号滤波功能设置
            '输入信号滤波时间常数设置

        Next

        '设置硬件停止
        If RadioButton50.Checked Then
            For i = 0 To 18
                adt8949_set_emergency_stop_mode(gCardIndex, i, m_hardStoplogic)
            Next
            For i = 36 To 47
                adt8949_set_emergency_stop_mode(gCardIndex, i, m_hardStoplogic)
            Next
        Else
            adt8949_set_emergency_stop_mode(gCardIndex, -1, m_hardStoplogic)
        End If


        MsgBox("set succeed！")

    End Sub

    '刷新IO检测界面的参数
    Private Sub RefreshParaIO()

        Dim InPutContol() As Object = {INO, IN1, IN2, IN3, IN4, IN5, IN6, IN7, IN8, IN9, IN10, IN11, IN12, IN13, IN14, IN15, IN16, IN17, IN18, IN19, IN20, IN21, IN22, IN23, IN24, IN25, IN26, IN27, IN28, IN29, IN30, IN31, IN32, IN33, IN34, IN35, IN36, IN37, IN38, IN39, IN40, IN41, IN42, IN43, IN44, IN45, IN46, IN47}

        Dim OutPutContol() As Object = {OUT0, OUT1, OUT2, OUT3, OUT4, OUT5, OUT6, OUT7, OUT8, OUT9, OUT10, OUT11, OUT12, OUT13, OUT14, OUT15, OUT16, OUT17, OUT18, OUT19, OUT20, OUT21, OUT22, OUT23, OUT24, OUT25, OUT26, OUT27, OUT28, OUT29, OUT30, OUT31}

        Dim i As Int32

        For i = 0 To 47

            TInput.Add(InPutContol(i))

        Next

        For i = 0 To 31

            TOutput.Add(OutPutContol(i))

        Next

    End Sub

    '输出全关按钮响应函数
    Private Sub BtnAllClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAllClose.Click

        'RefreshParaIO()

        Dim i As Int32

        For i = 0 To 31

            TOutput(i).Checked = False

            adt8949_write_bit(gCardIndex, i, 0)

        Next i

    End Sub

    '输出全开按钮响应函数
    Private Sub BtnAllOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAllOpen.Click

        'RefreshParaIO()

        Dim i As Int32

        For i = 0 To 31

            TOutput(i).Checked = True

            adt8949_write_bit(gCardIndex, i, 1)

        Next i

    End Sub

    '     输入检测
    'ADT-8948卡有35个输入点（0～34）
    '本程序以低电平为有信号输入
    Private Sub CheckInput()

        'RefreshParaIO()

        Dim Value As Integer
        Dim i As Int32

        For i = 0 To 47

            Value = adt8949_read_bit(0, i)                         '读取输入点

            If Value = 0 Then                              '高电平

                TInput(i).Checked = True

            ElseIf Value = 1 Then                          '低电平

                TInput(i).Checked = False

            End If

        Next i


    End Sub

    '         输出单点
    'ADT-8948卡有32个输出点（0～31）
    '本程序为按键按下时为高电平，弹起时为低电平
    Private Sub CheckOut()

        'RefreshParaIO()

        Dim i As Int32
        For i = 0 To 31

            If TOutput(i).Checked = 1 Then                              '按下时输出高电平

                adt8949_write_bit(gCardIndex, i, 1)

            Else

                adt8949_write_bit(gCardIndex, i, 0)                              '弹起时输出低电平

            End If

        Next i

    End Sub

    'ＩＯ检测定时器
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        CheckInput()
        CheckOut()
    End Sub

    Private Sub TabPage6_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabPage5.Enter
        Timer2.Enabled = True
        Timer1.Enabled = False
    End Sub

    Private Sub TabPage6_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabPage5.Leave
        Timer2.Enabled = False
        Timer1.Enabled = True
    End Sub

    Private Sub CardIndex_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

        gCardIndex = CardIndex.SelectedIndex
        'MsgBox(gCardIndex.ToString)

        'MsgBox(CardIndex.SelectedItem.ToString)
        'MsgBox(CardIndex.GetItemText(CardIndex.SelectedItem))

    End Sub

    Private Sub relative_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Motion_ArcInp()
    End Sub

    Private Sub InpMove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InpMove.Click
        Motion_LineInp()
    End Sub

    Private Sub InpArc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InpArc.Click
        Motion_ArcInp()
    End Sub

    Private Sub InpTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InpTime.Click
        '确保预处理段数为0
        adt8949_set_precount(gCardIndex, 0)

        '刷新运动参数
        'RefreshPara()

        EnableAllButton(0)

        m_StopFlag = False

        '一轴时间插补  '这里统一做成 100ms
        Dim i, m_ret As Int32


        For i = 0 To 10
            adt8949_set_precount(gCardIndex, 0)
            m_ret = adt8949_time_move4(gCardIndex, 0, 10, 10, 0, 0, 100)
        Next

        Dim mInpStatus As Int32 = -1

        While True
            DoEvents()
            sleep(1)
            adt8949_get_inp_status(gCardIndex, mInpStatus)
            If mInpStatus = 0 Then
                Exit While
            End If
            If m_StopFlag = True Then
                Exit While
            End If
        End While

        EnableAllButton(1)

    End Sub

    Private Sub InpNurbs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InpNurbs.Click
        'RefreshPara()
        'EnableAllButton(0)
        'm_StopFlag = False

        'Dim conp(7, 4) As Single
        'Dim weight() As Single = {1, 1, 1, 1, 1, 1, 1}
        'Dim node() As Single = {0, 0, 0, 0, 0.2F, 0.5F, 0.8F, 1, 1, 1, 1}

        'conp(0, 0) = 0 : conp(0, 1) = 0 : conp(0, 2) = 0 : conp(0, 3) = 0

        'conp(1, 0) = 83.3333F : conp(1, 1) = 60 : conp(1, 2) = 0 : conp(1, 3) = 0

        'conp(2, 0) = 333.3333F : conp(2, 1) = 240 : conp(2, 2) = 0 : conp(2, 3) = 0

        'conp(3, 0) = 0 : conp(3, 1) = -660 : conp(3, 2) = 0 : conp(3, 3) = 0

        'conp(4, 0) = -333.3333F : conp(4, 1) = 240 : conp(4, 2) = 0 : conp(4, 3) = 0

        'conp(5, 0) = -83.3333F : conp(5, 1) = 60 : conp(5, 2) = 0 : conp(5, 3) = 0

        'conp(6, 0) = 0 : conp(6, 1) = 0 : conp(6, 2) = 0 : conp(6, 3) = 0


        '这里只做xy轴的nurbs插补
        'adt8949_inp_NURBS(gCardIndex, 0, 3, conp, weight, node, 11)

        'Dim m_inpStatus As Int32
        'While True
        'DoEvents()
        'sleep(1)
        'adt8949_get_inp_status(gCardIndex, m_inpStatus)
        'If m_inpStatus = 0 Then
        'Exit While
        'End If
        'If m_StopFlag = True Then
        'Exit While
        'End If
        'End While

        'EnableAllButton(1)

    End Sub

    Private Sub Return0_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Return0.Click
        m_StopFlag = False
        If CHECK_X.Checked = False And CHECK_Y.Checked = False And CHECK_Z.Checked = False And CHECK_A.Checked = False Then
            MsgBox("Please choose axis")
            Exit Sub
        End If

        '先刷新下参数，stop0, lmt, stop1, dir
        Dim stop0() As Int32 = {1, 1, 1, 1}
        Dim lmt() As Int32 = {1, 1, 1, 1}
        Dim stop1() As Int32 = {1, 1, 1, 1}
        Dim dir() As Int32 = {1, 1, 1, 1}



        'stop0 电平
        If LOW_STOP0_X.Checked Then
            stop0(0) = 0
        Else
            stop0(0) = 1
        End If

        If LOW_STOP0_Y.Checked Then
            stop0(1) = 0
        Else
            stop0(1) = 1
        End If

        If LOW_STOP0_Z.Checked Then
            stop0(2) = 0
        Else
            stop0(2) = 1
        End If

        If LOW_STOP0_A.Checked Then
            stop0(3) = 0
        Else
            stop0(3) = 1
        End If

        '限位电平
        If LOW_LMT_X.Checked Then
            lmt(0) = 0
        Else
            lmt(0) = 1
        End If

        If LOW_LMT_Y.Checked Then
            lmt(1) = 0
        Else
            lmt(1) = 1
        End If

        If LOW_LMT_Z.Checked Then
            lmt(2) = 0
        Else
            lmt(2) = 1
        End If

        If LOW_LMT_A.Checked Then
            lmt(3) = 0
        Else
            lmt(3) = 1
        End If

        'stop1电平
        If LOW_STOP1_X.Checked Then
            stop1(0) = 0
        ElseIf HIGH_STOP1_X.Checked Then
            stop1(0) = 1
        Else
            stop1(0) = -1
        End If

        If LOW_STOP1_Y.Checked Then
            stop1(0) = 0
        ElseIf HIGH_STOP1_Y.Checked Then
            stop1(0) = 1
        Else
            stop1(0) = -1
        End If

        If LOW_STOP1_Z.Checked Then
            stop1(0) = 0
        ElseIf HIGH_STOP1_Z.Checked Then
            stop1(0) = 1
        Else
            stop1(0) = -1
        End If

        If LOW_STOP1_A.Checked Then
            stop1(0) = 0
        ElseIf HIGH_STOP1_A.Checked Then
            stop1(0) = 1
        Else
            stop1(0) = -1
        End If


        '方向
        If DIR1_X.Checked Then
            dir(0) = 0
        Else
            dir(0) = 1
        End If

        If DIR1_Y.Checked Then
            dir(1) = 0
        Else
            dir(1) = 1
        End If

        If DIR1_Z.Checked Then
            dir(2) = 0
        Else
            dir(2) = 1
        End If

        If DIR1_A.Checked Then
            dir(3) = 0
        Else
            dir(3) = 1
        End If

        Dim m_ret As Int32
        Dim SuccessFlag() As Int32 = {1, 1, 1, 1}
        Dim FailFlag() As Int32 = {1, 1, 1, 1}

        '设置回零参数
        If CHECK_X.Checked Then
            m_ret = adt8949_SetHomeMode_Ex(gCardIndex, 1, dir(0), stop0(0), lmt(0), stop1(0), BRANGE_X.Text, ZRANGE_X.Text, OFFSET_X.Text)
            m_ret = adt8949_SetHomeSpeed_Ex(gCardIndex, 1, StartvX.Text, SEARCHV_X.Text, HOMEV_X.Text, AccX.Text, ZSPEED_X.Text)
            m_ret = adt8949_HomeProcess_Ex(gCardIndex, 1, Gear_X.Text)
            SuccessFlag(0) = 0
            FailFlag(0) = 0
        End If

        If CHECK_Y.Checked Then
            m_ret = adt8949_SetHomeMode_Ex(gCardIndex, 2, dir(1), stop0(1), lmt(1), stop1(1), BRANGE_Y.Text, ZRANGE_Y.Text, OFFSET_Y.Text)
            m_ret = adt8949_SetHomeSpeed_Ex(gCardIndex, 2, StartvY.Text, SEARCHV_Y.Text, HOMEV_Y.Text, AccY.Text, ZSPEED_Y.Text)
            m_ret = adt8949_HomeProcess_Ex(gCardIndex, 2, Gear_Y.Text)
            SuccessFlag(1) = 0
            FailFlag(1) = 0
        End If

        If CHECK_Z.Checked Then
            m_ret = adt8949_SetHomeMode_Ex(gCardIndex, 3, dir(2), stop0(2), lmt(2), stop1(2), BRANGE_Z.Text, ZRANGE_Z.Text, OFFSET_Z.Text)
            m_ret = adt8949_SetHomeSpeed_Ex(gCardIndex, 3, StartvZ.Text, SEARCHV_Z.Text, HOMEV_Z.Text, AccZ.Text, ZSPEED_Z.Text)
            m_ret = adt8949_HomeProcess_Ex(gCardIndex, 3, Gear_Z.Text)
            SuccessFlag(2) = 0
            FailFlag(2) = 0
        End If

        If CHECK_A.Checked Then
            m_ret = adt8949_SetHomeMode_Ex(gCardIndex, 4, dir(3), stop0(3), lmt(3), stop1(3), BRANGE_A.Text, ZRANGE_A.Text, OFFSET_Z.Text)
            m_ret = adt8949_SetHomeSpeed_Ex(gCardIndex, 4, StartvZ.Text, SEARCHV_Z.Text, HOMEV_Z.Text, AccZ.Text, ZSPEED_Z.Text)
            m_ret = adt8949_HomeProcess_Ex(gCardIndex, 4, Gear_A.Text)
            SuccessFlag(3) = 0
            FailFlag(3) = 0
        End If

        '获取回零状态
        Dim m_zeroStatus As Int32 = -1

        While True
            sleep(1)
            DoEvents()
            If m_StopFlag = True Then
                Exit While
            End If
            If CHECK_X.Checked Then
                m_ret = adt8949_GetHomeStatus_Ex(gCardIndex, 1)
                If m_ret > 10 And m_ret < 0 Then
                    ZeroStatusX.Text = CStr(m_ret)
                    FailFlag(0) = 1
                ElseIf m_ret = 0 Then
                    SuccessFlag(0) = 1
                    ZeroStatusX.Text = "Succeed"
                End If
                ZeroStatusX.Text = CStr(m_ret)
            End If

            If CHECK_Y.Checked Then
                m_ret = adt8949_GetHomeStatus_Ex(gCardIndex, 2)
                If m_ret > 10 And m_ret < 0 Then
                    ZeroStatusX.Text = CStr(m_ret)
                    FailFlag(1) = 1
                ElseIf m_ret = 0 Then
                    SuccessFlag(1) = 1
                    ZeroStatusX.Text = "Succeed"
                End If
                ZeroStatusY.Text = CStr(m_ret)
            End If

            If CHECK_Z.Checked Then
                m_ret = adt8949_GetHomeStatus_Ex(gCardIndex, 3)
                If m_ret > 10 And m_ret < 0 Then
                    ZeroStatusX.Text = CStr(m_ret)
                    FailFlag(2) = 1
                ElseIf m_ret = 0 Then
                    SuccessFlag(2) = 1
                    ZeroStatusX.Text = "Succeed"
                End If
                ZeroStatusZ.Text = CStr(m_ret)
            End If

            If CHECK_A.Checked Then
                m_ret = adt8949_GetHomeStatus_Ex(gCardIndex, 4)
                If m_ret > 10 And m_ret < 0 Then
                    ZeroStatusX.Text = CStr(m_ret)
                    FailFlag(3) = 1
                ElseIf m_ret = 0 Then
                    SuccessFlag(3) = 1
                    ZeroStatusX.Text = "Succeed"
                End If
                ZeroStatusA.Text = CStr(m_ret)
            End If

            If SuccessFlag(0) And SuccessFlag(1) And SuccessFlag(2) And SuccessFlag(3) Then
                MsgBox("Succeed")
                Exit Sub
            End If

            If FailFlag(0) And FailFlag(1) And FailFlag(2) And FailFlag(3) Then
                MsgBox("Failed")
                Exit Sub
            End If

        End While
    End Sub

    Private Sub restoreParam_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles restoreParam.Click
        '界面上改变
        PulseAndDirX.Checked = True
        PulseAndDirY.Checked = True
        PulseAndDirZ.Checked = True
        PulseAndDirA.Checked = True

        RadioButton9.Checked = True
        RadioButton10.Checked = True
        RadioButton12.Checked = True
        RadioButton14.Checked = True

        RadioButton16.Checked = True
        RadioButton18.Checked = True
        RadioButton20.Checked = True
        RadioButton22.Checked = True

        RadioButton24.Checked = True
        RadioButton26.Checked = True
        RadioButton28.Checked = True
        RadioButton30.Checked = True

        RadioButton32.Checked = True
        RadioButton34.Checked = True
        RadioButton36.Checked = True
        RadioButton38.Checked = True

        '硬件急停
        RadioButton50.Checked = True
        RadioButton48.Checked = True

        '刷新参数
        SaveParam()


        '逻辑上改变
        Dim i As Int32 = 0
        For i = 0 To 4
            '设置脉冲模式
            adt8949_set_pulse_mode(gCardIndex, i, m_pulseMode(i), 0, 0)
            '设置限位模式
            adt8949_set_limit_mode(gCardIndex, i, m_limitZ(i), m_limitF(i), m_effectiveParam(i))
            '设置stop0模式
            adt8949_set_stop0_mode(gCardIndex, i, m_stop0(i), m_effectiveParam(i), 1)
            '设置stop1模式
            adt8949_set_stop1_mode(gCardIndex, i, m_stop1(i), m_effectiveParam(i), 1)
        Next

        '设置硬件停止
        If RadioButton51.Checked Then
            adt8949_set_emergency_stop_mode(gCardIndex, 16, RadioButton48.Checked)
        Else
            adt8949_set_emergency_stop_mode(gCardIndex, -1, RadioButton48.Checked)
        End If

    End Sub

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        If TabControl1.SelectedTab.Name = "TabPage2" Then
            Return0.Enabled = True
        Else
            Return0.Enabled = False
        End If

        If TabControl1.SelectedIndex = 4 Then
            Timer2.Interval = 100

            Timer2.Enabled = True
            'Timer2.Start()
        End If
        gCardIndex = TabControl1.SelectedIndex
    End Sub

    Private Sub Check_Dec1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Check_Dec1.CheckedChanged
        If Check_Dec1.Checked Then
            m_decFlag = 1
        Else
            m_decFlag = 0
        End If
    End Sub

    Private Sub TabPage1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabPage1.Click

    End Sub
End Class
