正运动技术
正运动技术
精准24码全年无错版
EN
精准24码全年无错版
精准24码全年无错版

协助伙伴成功,是我们的价值所在

The value of Zmotion is to bring customers more success!

首页 / 支持与服务 / 技术分享

Technical support

技术分享

运动控制卡应用开发教程之VB6.0

  今天,正运动小助手为大家分析一下应用VB6.0开发一个总线初始化的运动控制应用。

  我们主要从VB6.0的项目新建、函数库引用和PC函数使用方面讲起,最后通过项目实战——总线初始化例程讲解,来让大家熟悉它的项目开发。

  在正式学习之前,我们先了解一下正运动技术的运动控制卡ECI2418和ECI2618。这两款产品分别是4轴,6轴运动控制卡。

  

  1.png

  

  ECI2418支持4轴脉冲输入与编码器反馈,板载24点输入,16点输出,2AD,2DA,支持手轮接口,其中特定输出口支持高速PWM控制。

  

  2.png

  

  ECI2618支持6轴脉冲输入与编码器反馈,板载24点输入,16点输出,2AD,2DA,支持手轮接口,其中特定输出口支持高速PWM控制。

  

  3.png

  

  ECI2418,ECI2618均使用同一套API函数,均支持C、C++、C#、LabVIEW、Python、Delphi等开发语言,支持VC6.0、VB6.0、Qt、.Net等平台,支持Windows、Linux、WinCE、iMac等操作系统。

  

  以下是VB6.0

  开发流程

   一 新建EXE工程,加载函数库。

  

   (一)新建工程

  打开Microsoft Visual Basic菜单,在“文件”→“新建工程”,选择新建“标准EXE”工程。

  新建工程自带一个起始窗口,可以通过菜单“工程”→“属性”更改起始窗口。

   (二)加载PC函数库

  VB6.0需要对添加的dll文件进行加载,否则系统找不到函数所引用的函数库源,加载步骤如下。

  1.找到厂家提供的光盘资料中的VB6.0资料。

  

  4.png

  

  2.将VB6.0压缩包解压,找到其中的dll库文件

  

  5.png

  

  3.将dll文件zmotion.dll以及zauxdll.dll一起复制放入系统文件夹C:\Windows\System32中。假如编程系统是64位系统,也要把上述文件复制到C:\Windows\SysWOW64中。

  

  6.png

  

  4.通过“开始”菜单→“Windows系统”→“命令提示符”或者在“开始”菜单搜索“cmd”打开命令提示符窗口,使用如下指令:

   regsvr32 C:\ Windows\ SysWOW64\ zmotion.dll

   regsvr32 C:\ Windows\ system32\ zmotion.dll

  regsvr32命令用于注册COM组件,是Windows系统提供的用来向系统注册控件或者卸载控件的命令,以命令行方式运行。Zmotion.dll加载后,才可以调用zauxdll的函数。

  

  8.png

  

  可以将该条指令复制到记事本上,然后把txt文件另存为bat文件来运行。另外,一些自己下载vb6.0的额外部件也可以用该方法加载,加载后能在菜单“工程”→“引用”,“工程”→“部件”中找到对应文件,本例程使用函数库无需加载部件或引用。

   (三)函数库使用

  将zauxdll.bas与工程文件放入同一文件夹,方便管理。

  

  9.png

  

  在工程资源管理器中右键添加模块,或者在菜单“工程”→“添加模块”功能中将zauxdll.bas添加入工程。

  

  10.png

  

  这样就做好使用正运动PC函数库的准备了。

   二 查看PC函数手册,了解其用法。

  

   (一)PC函数手册也在光盘资料里面。

  具体路径如下:

  

  11.png

  

   (二)PC编程。

  一般先根据控制器连接方式选择对应的连接函数连接控制器,返回控制器句柄。接着用返回的控制器句柄,实现对控制器的控制,大部分函数都有对控制器的指向。通常有:

  Public g_handle As Long

  控制器句柄是连接控制器的重要标志。

   (三)通过网口连接控制器,获取句柄。

  通过网口 iret = ZAux_OpenEth(“127.0.0.1”, g_handle)或者串口 iret = ZAux_OpenCom(1, g_handle)连接控制器,获取控制器句柄 g_handle

  

  12.png

  

   (四)下载总线初始化bas文件

  下载总线初始化 bas文件到控制器 iret = ZAux_BasDown(g_handle, sFilePath, 1),sFilePath是对应总线初始化的文件地址,利用 CommonDialog对话框操作部件,获取对象文件地址。

  

  13.png

  

  总线初始化文件是基于ZDevelop编写的EtherCAT和RTEX初始化程序,通过ZAux_BasDown方式下载到控制器以直接运行。

  

  14.png

  

   (五)EtherCAT数据字典读写

  EtherCAT数据字典读写 ZAux_BusCmd_SDORead ZAux_BusCmd_SDOWrite

  

  15.png

  16.png

  

  其中对象字典编号、对象字典子编号、数据类型是十进制输入,手册上是十六进制表示,使用时注意转换。

   (六)位置环增益与速度环增益调整

  松下A6B系列EtherCAT总线驱动器中:

  位置环增益对应数据字典为 3100H-00H(第一位置环增益)和 3105H-00H(第二位置环增益);

  速度环增益对应数据字典为 3101H-00H(第一速度环增益)和 3106H-00H(第二速度环增益);

  自动选择增益参数的标志位为 3002H-00H

  具体请参考光盘资料(P315~P318):技术资料→ECAT通讯规格篇→MINAS_A6B系列→EtherCAT通讯/选择类型。

  

  17.png

  

  本篇文章使用第一位置环增益和第一速度环增益,通过实时自动增益调谐设置选择是否改变增益参数。

   三 项目实战之连续插补运动例程讲解

  

   (一)界面讲解

  

  18.png

  

   (二)例程简易流程图

  

  19.png

  

  //相关函数

  // 建立与控制器的网口通讯

  iret = ZAux_OpenEth(m_ipaddress, g_handle)     '网口连接控制器

  //定时器刷新

  ret = ZAux_Direct_GetAxisEnable(g_handle, m_axisnum, i_AxisPara(0))

  ret = ZAux_Direct_GetAxisStatus(g_handle, m_axisnum, i_AxisPara(1))

  ……

  //下载初始化bas文件到控制器

  iret = ZAux_BasDown(g_handle, sFilePath, 1)     '下载到ROM

  //轴使能

  iret = ZAux_Direct_SetAxisEnable(g_handle, m_axisnum, 0)     ‘轴使能关闭

  iret = ZAux_Direct_SetAxisEnable(g_handle, m_axisnum, 1)     '轴使能打开

  //正转

  iret = ZAux_Direct_Single_Vmove(g_handle, m_axisnum, 1)

  //反转

  iret = ZAux_Direct_Single_Vmove(g_handle, m_axisnum, -1)

  //相对运动

  iret = ZAux_Direct_Single_Move(g_handle, m_axisnum, Val(T_Move_s))

  //绝对运动

  iret = ZAux_Direct_Single_MoveAbs(g_handle, m_axisnum, Val(T_Move_s))

  //停止

  iret = ZAux_Direct_Single_Cancel(g_handle, m_axisnum, 2)

  //运动增益读写

  iret =ZAux_BusCmd_SDORead(g_handle, 0, T_SdoNode, Val(CLng("&H" & "3100")), 0, 3, m_sdo_data2_1)

  iret =ZAux_BusCmd_SDORead(g_handle, 0, T_SdoNode, Val(CLng("&H" & "3101")), 0, 3, m_sdo_data2_2)

  // IO信号读写

  iret = ZAux_Direct_GetIn(g_handle, i , IN_status)

  iret = ZAux_Direct_GetOp(g_handle, i , OP_status)

  iret = ZAux_Direct_SetOp(g_handle, i , OP_status)

   (三)模块程序

  1.初始化变量

  Public g_handle As Long     '当前使用的卡句柄

  Public iret As Long     '函数返回值

  Public g_basflag As Boolean     '//BAS文件加载标志位

  Public g_InitStatus As Integer     '//总线初始化完成状态 0-失败 1-成功 -1-初始化未完成

  Public Bus_type As Single     '//BAS文件中变量判断总线类型,也作为BAS文件是否下载成功判断

  Public if_home As Boolean

  Public m_axisnum As Integer

  2.控制器连接

  Private Sub T_OpenCom_Click() '串口连接

          If g_handle <> 0 Then '断开前面的连接

                  ZAux_Close (g_handle)

                   g_handle= 0

          End If

           iret= ZAux_OpenCom(Val(T_ComId.Text), g_handle)

          If (g_handle <> 0) Then

                   Form1.Caption = "已连接"

                   Timer1.Enabled = True

                  T_AxisId_Change

                  Dim ret As Integer

                   iret= ZAux_Direct_GetUserVar(g_handle, "BUS_TYPE", Bus_type)

                  '读取BAS文件中的变量判断是否有加载BAS文件

                   If (iret= 0 And Bus_type <> -1) Then

                   g_basflag= True'//文件已经加载

      End If

      Else

                   Form1.Caption = "未连接"

                  MsgBox "控制器链接失败,请检测IP地址!", vbOKOnly, "警告"

      End If

  End Sub

  Private Sub T_IpAddress_DropDown() '下拉搜索IP

          Dim Buffer As String * 10240

          T_IpAddress.Clear

          T_IpAddress.AddItem ("127.0.0.1")

           iret= ZAux_SearchEthlist(Buffer, 10230, 200) '搜索IP地址列表

          Dim Ip_List() As String

           Ip_List= Split(Buffer, " ")

           For i= 0 To UBound(Ip_List)

              T_IpAddress.AddItem (Ip_List(i))

          Next

  End Sub

  Private Sub T_OpenEth_Click() '以太网连接

          Dim m_ipaddress As String

           m_ipaddress= T_IpAddress.Text

          If g_handle <> 0 Then '断开前面的连接

              ZAux_Close (g_handle)

               g_handle= 0

      End If

       iret= ZAux_OpenEth(m_ipaddress, g_handle)'网口连接控制器

      If (g_handle <> 0) Then

           Form1.Caption= "已连接"

           Timer1.Enabled = True

          T_AxisId_Change

           iret = ZAux_Direct_GetUserVar(g_handle, "BUS_TYPE", Bus_type)

          '读取BAS文件中的变量判断是否有加载BAS文件

           If (iret= 0 And Bus_type <> -1) Then

           g_basflag = True'//文件已经加载

      End If

      Else

           Form1.Caption = "未连接"

          MsgBox "控制器链接失败,请检测IP地址!", vbOKOnly, "警告"

      End If

  End Sub

  Private Sub T_PciId_DropDown() '下拉搜索PCI

          Dim m_maxpci As Integer

           T_PciId.Clear

           m_maxpci= ZAux_GetMaxPciCards()

           For i= 0 To m_maxpci - 1

          T_PciId.AddItem (i.ToString())

          Next

  End Sub

  Private Sub T_OpenPci_Click()

          Dim m_cardid As Integer

          If g_handle <> 0 Then '断开前面的连接

              ZAux_Close (g_handle)

               g_handle= 0

          End If

           m_cardid= Val(PCIADDRESS.Text)

           iret= ZAux_OpenPci(m_cardid, g_handle)'PCI方式连接

          If g_handle <> 0 Then

               Form1.Caption= "已连接"

               Timer1.Enabled = True

              T_AxisId_Change

              Dim ret As Integer

               iret= ZAux_Direct_GetUserVar(g_handle, "BUS_TYPE", Bus_type)

              '读取BAS文件中的变量判断是否有加载BAS文件

               If (iret = 0 And Bus_type <> -1) Then

               g_basflag= True'//文件已经加载

      End If

      Else

              MsgBox "连接失败,请检查PCI", vbOKOnly, "提示"

              Form1.Caption = "未连接"

      End If

  End Sub

  Private Sub T_Close_Click()

          '断开链接

          If (g_handle <> 0) Then

               Timer1.Enabled = False

              ZAux_Close (g_handle)

               g_handle= 0

               Form1.Caption= "未连接"

          End If

  End Sub

  3.总线初始化

  Private Sub T_DownLoad_Click() '下载文件到控制器

          If (g_handle = 0) Then

              MsgBox "未链接到控制器!", vbOKOnly, "提示"

          Else

           WithCommonDialog1

              .Filename = "Basic1"

              .InitDir = App.Path

              .CancelError = True

              .Filter = "文件(*.bas)|*.bas"

           End With

          Me.CommonDialog1.ShowOpen

          sFilePath = Me.CommonDialog1.Filename

          T_BasFile.Text = sFilePath

          iret = ZAux_BasDown(g_handle, sFilePath, 1) '//下载到ROM

          If (iret <> 0) Then

              MsgBox "文件下载失败!", vbOKOnly, "提示"

              Else

              MsgBox "下载成功!", vbOKOnly, "提示"

          End If

      End If

  End Sub

  '重新初始化总线,下载ROM时程序会自动初始化一次

   PrivateSub T_BusInit_Click()

   If(g_handle = 0) Then

      MsgBox "未链接到控制器!", vbOKOnly, "提示"

   Else

       If(g_basflag And(g_InitStatus <> -1)) Then '-1:可能正在执行初始化

          g_InitStatus = -1

          Dim Buffer As String * 10240

          T_BusStatus.Text = "初始化未完成"

          '任务1重新运行BAS中的初始化函数

          iret = ZAux_Execute(g_handle, "RUNTASK 1,Ecat_Init", Buffer, 0)

       Else

              MsgBox "Bas文件未加载!", vbOKOnly, "提示"

       End If

   End If

   EndSub

  4.轴运动

  Private Sub T_SetEnable_Click()     '//切换使能

           If (g_handle= 0) Then

              MsgBox "未链接到控制器!", vbOKOnly, "提示"

          Else

               If (T_EnableStatus.Text= "on") Then

                  iret = ZAux_Direct_SetAxisEnable(g_handle, m_axisnum, 0)

              Else

               iret= ZAux_Direct_SetAxisEnable(g_handle, m_axisnum, 1)

              End If

      End If

  End Sub

  Private Sub T_ClearAlm_Click()     '//清除轴报警

           If (g_handle = 0) Then

              MsgBox "未链接到控制器!", vbOKOnly, "提示"

          Else

               iret= ZAux_BusCmd_DriveClear(g_handle, m_axisnum, 0)

          End If

  End Sub

  Private Sub T_FwdMove_Click() '正转

           If (g_handle = 0) Then

              MsgBox "未链接到控制器!", vbOKOnly, "提示"

          Else

              iret= ZAux_Direct_SetUnits(g_handle,m_axisnum,Val(T_Units.Text))

              iret= ZAux_Direct_SetSpeed(g_handle,m_axisnum,Val(T_Speed.Text))

              iret= ZAux_Direct_SetAccel(g_handle,m_axisnum,Val(T_Accel.Text))

              iret= ZAux_Direct_Single_Vmove(g_handle,m_axisnum,1)

      End If

  End Sub

  Private Sub T_RevMove_Click()    '反转

           If (g_handle = 0) Then

              MsgBox "未链接到控制器!", vbOKOnly, "提示"

          Else

              iret= ZAux_Direct_SetUnits(g_handle,m_axisnum,Val(T_Units.Text))

              iret= ZAux_Direct_SetSpeed(g_handle,m_axisnum,Val(T_Speed.Text))

              iret= ZAux_Direct_SetAccel(g_handle,m_axisnum,Val(T_Accel.Text))

              iret= ZAux_Direct_Single_Vmove(g_handle,m_axisnum,-1)

          End If

  End Sub

  Private Sub T_Move_Click()     '运动

       If (g_handle = 0) Then

          MsgBox "未链接到控制器!", vbOKOnly, "提示"

      Else

          iret= ZAux_Direct_SetUnits(g_handle,m_axisnum,Val(T_Units.Text))

          iret= ZAux_Direct_SetSpeed(g_handle,m_axisnum,Val(T_Speed.Text))

          iret= ZAux_Direct_SetAccel(g_handle,m_axisnum,Val(T_Accel.Text))

          If T_moveType(0).value = True Then

      iret= ZAux_Direct_Single_Move(g_handle, m_axisnum,Val(T_Move_s))

          ElseIf T_moveType(1).value = True Then

          iret= ZAux_Direct_Single_MoveAbs(g_handle,m_axisnum,Val(T_Move_s))

          End If

      End If

  End Sub

  Private Sub T_Move_Click() '运动

       If (g_handle = 0) Then

              MsgBox "未链接到控制器!", vbOKOnly, "提示"

          Else

               iret= ZAux_Direct_SetUnits(g_handle,m_axisnum,Val(T_Units.Text))

               iret= ZAux_Direct_SetSpeed(g_handle,m_axisnum,Val(T_Speed.Text))

               iret= ZAux_Direct_SetAccel(g_handle,m_axisnum,Val(T_Accel.Text))

           If T_moveType(0).value = True Then

               iret= ZAux_Direct_Single_Move(g_handle,m_axisnum, Val(T_Move_s))

               ElseIf T_moveType(1).value = True Then

           iret= ZAux_Direct_Single_MoveAbs(g_handle,m_axisnum,Val(T_Move_s))

          End If

      End If

  End Sub

  Private Sub T_Stop_Click() '停止

   If (g_handle = 0) Then

  MsgBox "未链接到控制器!", vbOKOnly, "提示"

  Else

   iret= ZAux_Direct_Single_Cancel(g_handle, m_axisnum, 2)

  End If

  End Sub

  5.总线回零

  Private Sub T_StartHome_Click() '驱动器自身回零

               If (g_handle = 0) Then

                  MsgBox "未链接到控制器!", vbOKOnly, "提示"

              Else

                   If (Bus_type= 0) Then

                  iret= ZAux_Direct_SetSpeed(g_handle,m_axisnum,Val(T_HomeSp1.Text))

                  iret= ZAux_Direct_SetCreep(g_handle,m_axisnum,Val(T_HomeSp2.Text))

                  iret= ZAux_BusCmd_SetDatumOffpos(g_handle,m_axisnum, _

                  Val(T_HomeOffpos.Text))

                  iret= ZAux_BusCmd_Datum(g_handle,m_axisnum,Val(T_HomeMode.Text))

              Else

                  MsgBox "rtex不支持!", vbOKOnly, "提示"

              End If

      End If

  End Sub

  Private Sub T_StopHome_Click() '停止

          T_Stop_Click

  End Sub

  6.总线数据交互

  Private Sub T_EcatWrite_Click() 'ETHERCAT写

   If (g_handle = 0) Then

          MsgBox "未链接到控制器!", vbOKOnly, "提示"

  Else

           If (Bus_type = 0) Then

              Dim m_sdo_node0 As Long

              Dim m_sdo_index0 As Long

              Dim m_sdo_sub0 As Long

              Dim m_sdo_type0 As Long

              Dim m_sdo_data0 As Long

               m_sdo_node0 = Val(T_SdoNode0.Text)

               m_sdo_index0= Val(T_SdoIndex0.Text)

               m_sdo_sub0= Val(T_SdoSub0.Text)

               m_sdo_type0= T_SdoType0.ListIndex + 1

               m_sdo_data0= Val(T_SdoData0.Text)

              iret= ZAux_BusCmd_SDOWrite(g_handle,0, _

              m_sdo_node0,m_sdo_index0,m_sdo_sub0,m_sdo_type0,m_sdo_data0)

      If (iret <> 0) Then

              MsgBox "写入失败!", vbOKOnly, "提示"

      End If

      Else

              MsgBox "非ETHERCAT模块!", vbOKOnly, "提示"

      End If

  End If

  End Sub

  Private Sub T_EcatRead_Click() 'ETHERCAT读取

  If (g_handle = 0) Then

          MsgBox "未链接到控制器!", vbOKOnly, "提示"

  Else

          If (Bus_type = 0) Then

              Dim m_sdo_node1 As Long

              Dim m_sdo_index1 As Long

              Dim m_sdo_sub1 As Long

              Dim m_sdo_type1 As Long

              Dim m_sdo_data1 As Long

              m_sdo_node1 = Val(T_SdoNode1.Text)

              m_sdo_index1 = Val(T_SdoIndex1.Text)

              m_sdo_sub1 = Val(T_SdoSub1.Text)

              m_sdo_type1 = T_SdoType1.ListIndex + 1

              m_sdo_data1 = 0

              iret=ZAux_BusCmd_SDORead(g_handle,0, _

              m_sdo_node1, m_sdo_index1, m_sdo_sub1, m_sdo_type1, m_sdo_data1)

          If (iret <> 0) Then

              MsgBox "读取失败!", vbOKOnly, "提示"

          Else

              T_SdoData1.Text = Str(m_sdo_data1)

          End If

          Else

              MsgBox "非ETHERCAT模块!", vbOKOnly, "提示"

          End If

  End If

  End Sub

  Private Sub auto_gain_check_Click() '自动增益标志设置

      If (Bus_type = 0) Then

          If auto_gain_check.value = 0 Then

  iret=ZAux_BusCmd_SDOWrite(g_handle,0, Val(T_SdoNode2.Text), Val(CLng("&H" & "3002")), 0, 3, 0)

              Else

                  iret= ZAux_BusCmd_SDOWrite(g_handle, 0, Val(T_SdoNode2.Text), Val(CLng("&H" & "3002")), 0, 3, 1)

                 End If

          Else

              MsgBox "非ETHERCAT模块!", vbOKOnly, "提示"

          End If

  End Sub

  Private Sub T_ECAT_W_Click() '速度环、位置环增益写

      If (g_handle = 0) Then

                  MsgBox "未链接到控制器!", vbOKOnly, "提示"

          Else

              If (Bus_type = 0) Then

                  iret = ZAux_BusCmd_SDOWrite(g_handle,0, Val(T_SdoNode2.Text), Val(CLng("&H"&"3100")), 0, 3, Val(T_PostGain_W.Text)) '位置环增益写

          iret = iret + ZAux_BusCmd_SDOWrite(g_handle, 0, Val(T_SdoNode2.Text), Val(CLng("&H" & "3101")), 0, 3, Val(T_VeloGain_W.Text)) '速度环增益写

              If (iret <> 0) Then

                      MsgBox "写入失败!", vbOKOnly, "提示"

                  End If

              Else

                  MsgBox "非ETHERCAT模块!", vbOKOnly, "提示"

          End If

      End If

  End Sub

  Private Sub T_ECAT_R_Click() '速度环、位置环增益读

      If (g_handle = 0) Then

              MsgBox "未链接到控制器!", vbOKOnly, "提示"

      Else

          If (Bus_type = 0) Then

              iret = ZAux_BusCmd_SDORead(g_handle, 0, Val(T_SdoNode3.Text), Val(CLng("&H" & "3100")), 0, 3, m_sdo_data2_1) '位置环增益读

      iret = iret + ZAux_BusCmd_SDORead(g_handle, 0, Val(T_SdoNode3.Text), Val(CLng("&H" & "3101")), 0, 3, m_sdo_data2_2) '速度环增益读

          If (iret <> 0) Then

              MsgBox "写入失败!", vbOKOnly, "提示"

          Else

              T_PostGain_R = Str(m_sdo_data2_1)

              T_VeloGain_R = Str(m_sdo_data2_2)

          End If

          Else

              MsgBox "非ETHERCAT模块!", vbOKOnly, "提示"

          End If

      End If

  End Sub

  7.IO口操作

  Sub IN_OP_read()         'IO口读取

          Dim IN_status As Long

          Dim OP_status As Long

          Dim in_page As Long

          Dim op_page As Long

          in_page = T_IN_page.ListIndex

          op_page = T_OP_page.ListIndex

          Dim i

          For i = 0 To 7

              iret = ZAux_Direct_GetIn(g_handle, i + in_page * 8, IN_status)

              iret = ZAux_Direct_GetOp(g_handle, i + op_page * 8, OP_status)

              T_IN_Check(i).value = IN_status

              T_IN_Check(i).Caption = Str(i + in_page * 8)

              T_OP_Check(i).value = OP_status

              T_OP_Check(i).Caption = Str(i + op_page * 8)

          Next

  End Sub

  Private Sub T_OP_Check_Click(Index As Integer) '输出口使能

          Dim OP_status As Long

          Dim op_page As Long

          op_page = T_OP_page.ListIndex

          OP_status = T_OP_Check(Index).value

          iret = ZAux_Direct_SetOp(g_handle, Index + op_page * 8, OP_status)

  End Sub

  8.参数刷新

  1)在主窗体

  Private Sub Form_Load() '窗体加载时运行

          g_handle = 0

          g_basflag = False

          g_InitStatus = -1

          Bus_type = -1

          if_home = False

          m_axisnum = 0

          T_IN_page.ListIndex = 0 '初始化IO列表初值

          T_OP_page.ListIndex = 0

  End Sub

  Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

          End '关闭主窗体时关闭程序

  End Sub

  Private Sub Form_Unload(Cancel As Integer)

          '断开链接

          If (g_handle <> 0) Then

              Timer1.Enabled = False

              ZAux_Close (g_handle)

              g_handle = 0

          End If

              Dim myForm As Form

          For Each myForm In Forms

              Unload myForm

              Set myForm = Nothing

  Private Sub T_morePara_Click()

      Form2.Show

  End Sub

  Private Sub Timer1_Timer()

          Dim ret As Long

          Dim f_AxisPara(10) As Single

          Dim i_AxisPara(10) As Long

      If g_handle <> 0 Then

              ret = 0

              m_axisnum = Val(T_AxisId.Text)

  ret = ZAux_Direct_GetAxisEnable(g_handle, m_axisnum, i_AxisPara(0))

  ret = ret + ZAux_Direct_GetMpos(g_handle, m_axisnum, f_AxisPara(0))

  ret = ret + ZAux_Direct_GetDpos(g_handle, m_axisnum, f_AxisPara(1))

  ret = ret + ZAux_Direct_GetAxisStatus(g_handle, m_axisnum, i_AxisPara(1))

  ret = ret + ZAux_Direct_GetIfIdle(g_handle, m_axisnum, i_AxisPara(2))

          If (ret = 0) Then

              If i_AxisPara(0) = 0 Then

                  T_EnableStatus.Text = "off"

              Else

                  T_EnableStatus.Text = "on"

              End If

              T_Dpos.Text = Str(f_AxisPara(0))

              T_Mpos.Text = Str(f_AxisPara(1))

              Call re_transfro(i_AxisPara(1), i_AxisPara(2))

              End If

          If (((i_AxisPara(1) And 64) = 64) And (if_home = False)) Then '//第6位是否被置1

              T_HomeStatus.Text = "回零中"

              if_home = True

          ElseIf ((i_AxisPara(1) = 0) And if_home) Then

              Dim homestatus As Long

              homestatus = 0

              ret = ZAux_BusCmd_GetHomeStatus(g_handle, m_axisnum, homestatus)

          If homestatus = 1 Then

                  T_HomeStatus.Text = "回零完成"

          Else

                  T_HomeStatus.Text = "回零未完成"

          End If

                  if_home = False

          End If

      If (g_basflag And g_InitStatus = -1) Then '//已经加载文件并且正在初始化 读取状态

              Dim tempstatus As Single

              Dim m_BusNodeNum As Long

              Dim m_BusAxisNum As Single

              tempstatus = -1

              m_BusNodeNum = 0

              m_BusAxisNum = 0

  ret = ZAux_Direct_GetUserVar(g_handle, "BUS_TYPE", Bus_type)

  '//读取BAS文件中的变量判断总线类型

  ret = ret + ZAux_Direct_GetUserVar(g_handle, "Bus_InitStatus", tempstatus) '//读取BAS文件中的变量判断总线初始化完成状态

  ret = ret + ZAux_BusCmd_GetNodeNum(g_handle, 0, m_BusNodeNum)

  '//读取槽位0上节点个数。

  ret = ret + ZAux_Direct_GetUserVar(g_handle, "Bus_TotalAxisnum", m_BusAxisNum)

  '//读取BAS文件中的变量判断扫描的总轴数

                  g_InitStatus = tempstatus

  '//初始化完成刷新状态

                  If (ret = 0 And g_InitStatus <> -1) Then

                      If g_InitStatus = 1 Then

                          T_BusStatus.Text = "初始化成功"

                      Else

                          T_BusStatus.Text = "初始化失败"

                      End If

                      T_NodeNum.Text = Str(m_BusNodeNum)

                      T_AxisNum.Text = Str(m_BusAxisNum)

                  End If

              End If

                  Call IN_OP_read

              End If

      End Sub

  Sub re_transfro(axisStatues, axisIdle)

      Dim axisStatues_str As String

      Dim axisIdle_str As String

      axisStatues_str = ""

      If axisStatues = 0 Then

          axisStatues_str = "正常;"

      Else

          Dim quo As Long

          Dim mod_tr(24) As Long

          Dim i As Long

          quo = axisStatues

      For i = 0 To 23

          mod_tr(i) = quo Mod 2

          quo = quo \ 2

      Next

      If mod_tr(1) Then axisStatues_str = axisStatues_str + "随动误差超限告警;"

      If mod_tr(2) Then axisStatues_str = axisStatues_str + "与远程通讯出错;"

      If mod_tr(3) Then axisStatues_str = axisStatues_str + "远程驱动器报错;"

      If mod_tr(4) Then axisStatues_str = axisStatues_str + "正向硬限位;"

      If mod_tr(5) Then axisStatues_str = axisStatues_str + "反向硬限位;"

      If mod_tr(6) Then axisStatues_str = axisStatues_str + "找原点;"

      If mod_tr(7) Then axisStatues_str = axisStatues_str + "hold速度保持信号输入;"

      If mod_tr(8) Then axisStatues_str = axisStatues_str + "随动误差超限出错;"

      If mod_tr(9) Then axisStatues_str = axisStatues_str + "超过正向软限位;"

      If mod_tr(10) Then axisStatues_str = axisStatues_str + "超过负向软限位;"

      If mod_tr(11) Then axisStatues_str = axisStatues_str + "CANCEL执行中;"

      If mod_tr(12) Then axisStatues_str = axisStatues_str + "脉冲频率超过最大速度;"

      If mod_tr(14) Then axisStatues_str = axisStatues_str + "机械手指令坐标错误;"

      If mod_tr(18) Then axisStatues_str = axisStatues_str + "电源异常;"

      If mod_tr(21) Then axisStatues_str = axisStatues_str + "运动中触发特殊运动指令失败;"

      If mod_tr(22) Then axisStatues_str = axisStatues_str + "告警信号输入;"

      If mod_tr(23) Then axisStatues_str = axisStatues_str + "轴进入暂停状态;"

  End If

      If axisIdle = 0 Then

          axisIdle_str = "运动中"

      Else

      axisIdle_str = "运动结束"

      End If

          T_AxisStatus.Caption = axisStatues_str

          T_Idle.Text = axisIdle_str

      End Sub

      Private Sub T_AxisId_Change() '修改轴参数

      If (g_handle = 0) Then

              MsgBox "未链接到控制器!", vbOKOnly, "提示"

      Else

              Dim f_AxisPara(10) As Single

              Dim m_atype As Long

              m_atype = 0

              m_axisnum = Val(T_AxisId.Text)

              iret = ZAux_Direct_GetUnits(g_handle, m_axisnum, f_AxisPara(0))

              iret = iret + ZAux_Direct_GetSpeed(g_handle, m_axisnum, f_AxisPara(1))

              iret = iret + ZAux_Direct_GetAccel(g_handle, m_axisnum, f_AxisPara(2))

              iret = iret + ZAux_Direct_GetDecel(g_handle, m_axisnum, f_AxisPara(3))

              iret = iret + ZAux_Direct_GetAtype(g_handle, m_axisnum, m_atype)

      If (iret = 0) Then

              T_Atype.Text = Str(m_atype)

              T_Units.Text = Str(f_AxisPara(0))

              T_Speed.Text = Str(f_AxisPara(1))

              T_Accel.Text = Str(f_AxisPara(2))

              T_Decel.Text = Str(f_AxisPara(3))

          End If

      End If

     End Sub

  2)在子窗体

  Private d_AxisPara(73) As Variant '变体类型,使数组包含single和long型

  Private d_AxisNum As Long

  Public g_handle As Long

  Public Sub para_reflash() '读取参数

  Dim ret As Long

      Dim paraS(3) As Single

          ret = 0

          d_AxisNum = Val(S_Axisnum.Text)

          g_handle = Form1.g_handle

      If (g_handle <> 0) Then

  ret = ZAux_Direct_GetAtype(g_handle, d_AxisNum, d_AxisPara(0))

  ret = ZAux_Direct_GetUnits(g_handle, d_AxisNum, d_AxisPara(1))

  ret = ZAux_Direct_GetAccel(g_handle, d_AxisNum, d_AxisPara(2))

  ret = ZAux_Direct_GetDecel(g_handle, d_AxisNum, d_AxisPara(3))

  ret = ZAux_Direct_GetSpeed(g_handle, d_AxisNum, d_AxisPara(4))

  ret = ZAux_Direct_GetCreep(g_handle, d_AxisNum, d_AxisPara(5))

  ret = ZAux_Direct_GetLspeed(g_handle, d_AxisNum, d_AxisPara(6))

  ret = ZAux_Direct_GetMerge(g_handle, d_AxisNum, d_AxisPara(7))

  ret = ZAux_Direct_GetSramp(g_handle, d_AxisNum, d_AxisPara(8))

  ret = ZAux_Direct_GetEndMove(g_handle, d_AxisNum, d_AxisPara(11))

  ret = ZAux_Direct_GetFsLimit(g_handle, d_AxisNum, d_AxisPara(12))

  ret = ZAux_Direct_GetRsLimit(g_handle, d_AxisNum, d_AxisPara(13))

  ret = ZAux_Direct_GetDatumIn(g_handle, d_AxisNum, d_AxisPara(14))

  ret = ZAux_Direct_GetFwdIn(g_handle, d_AxisNum, d_AxisPara(15))

  ret = ZAux_Direct_GetRevIn(g_handle, d_AxisNum, d_AxisPara(16))

  ret = ZAux_Direct_GetAllAxisInfo(g_handle, d_AxisNum, d_AxisPara(17), d_AxisPara(9), d_AxisPara(10), d_AxisPara(25))

  ret = ZAux_Direct_GetLoaded(g_handle, d_AxisNum, d_AxisPara(18))

  ret = ZAux_Direct_GetMspeed(g_handle, d_AxisNum, d_AxisPara(19))

  ret = ZAux_Direct_GetMtype(g_handle, d_AxisNum, d_AxisPara(20))

  'ret = ZAux_Direct_GetNtype(g_handle, d_AxisNum, d_AxisPara(21))

  ret = ZAux_Direct_GetRemain(g_handle, d_AxisNum, d_AxisPara(22))

  ret = ZAux_Direct_GetVectorBuffered(g_handle, d_AxisNum, d_AxisPara(23))

  ret = ZAux_Direct_GetVpSpeed(g_handle, d_AxisNum, d_AxisPara(24))

  ret = ZAux_Direct_GetMoveCurmark(g_handle, d_AxisNum, d_AxisPara(27))

  d_AxisPara(26) = d_AxisPara(27)'读取运动标号与当前运动标号相同

  ret = ZAux_Direct_GetAxisStopReason(g_handle, d_AxisNum, d_AxisPara(28))

  ret = ZAux_Direct_GetMovesBuffered(g_handle, d_AxisNum, d_AxisPara(29))

  ret = ZAux_Direct_GetAxisAddress(g_handle, d_AxisNum, d_AxisPara(30))

  ret = ZAux_Direct_GetAxisEnable(g_handle, d_AxisNum, d_AxisPara(31))

  ret = ZAux_Direct_GetForceSpeed(g_handle, d_AxisNum, d_AxisPara(32))

  ret = ZAux_Direct_GetStartMoveSpeed(g_handle, d_AxisNum, d_AxisPara(33))

  ret = ZAux_Direct_GetEndMoveSpeed(g_handle, d_AxisNum, d_AxisPara(34))

  ret = ZAux_Direct_GetFastDec(g_handle, d_AxisNum, d_AxisPara(35))

  ret = ZAux_Direct_GetAddax(g_handle, d_AxisNum, d_AxisPara(36))

  ret = ZAux_Direct_GetLinkax(g_handle, d_AxisNum, d_AxisPara(37))

  ret = ZAux_Direct_GetCornerMode(g_handle, d_AxisNum, d_AxisPara(38))

  ret = ZAux_Direct_GetDecelAngle(g_handle, d_AxisNum, d_AxisPara(39))

  ret = ZAux_Direct_GetStopAngle(g_handle, d_AxisNum, d_AxisPara(40))

  ret = ZAux_Direct_GetFullSpRadius(g_handle, d_AxisNum, d_AxisPara(41))

  d_AxisPara(42) = d_AxisPara(32) '限速值取SP速度

  ret = ZAux_Direct_GetZsmooth(g_handle, d_AxisNum, d_AxisPara(43))

  ret = ZAux_Direct_GetVectorBuffered(g_handle, d_AxisNum, d_AxisPara(44))

  ret = ZAux_Direct_GetEndMoveBuffer(g_handle, d_AxisNum, d_AxisPara(45))

  ret = ZAux_Direct_GetHomeWait(g_handle, d_AxisNum, d_AxisPara(46))

  ret = ZAux_Direct_GetFastJog(g_handle, d_AxisNum, d_AxisPara(47))

  ret = ZAux_Direct_GetFwdJog(g_handle, d_AxisNum, d_AxisPara(48))

  ret = ZAux_Direct_GetRevJog(g_handle, d_AxisNum, d_AxisPara(49))

  ret = ZAux_Direct_GetJogSpeed(g_handle, d_AxisNum, d_AxisPara(50))

  ret = ZAux_Direct_GetFholdIn(g_handle, d_AxisNum, d_AxisPara(51))

  ret = ZAux_Direct_GetFhspeed(g_handle, d_AxisNum, d_AxisPara(52))

  ret = ZAux_Direct_GetEncoder(g_handle, d_AxisNum, d_AxisPara(53))

  ret = ZAux_Direct_GetMark(g_handle, d_AxisNum, d_AxisPara(57))

  ret = ZAux_Direct_GetMarkB(g_handle, d_AxisNum, d_AxisPara(58))

  ret = ZAux_Direct_GetRegPos(g_handle, d_AxisNum, d_AxisPara(61))

  ret = ZAux_Direct_GetRegPosB(g_handle, d_AxisNum, d_AxisPara(62))

  ret = ZAux_Direct_GetAlmIn(g_handle, d_AxisNum, d_AxisPara(65))

  ret = ZAux_Direct_GetRepOption(g_handle, d_AxisNum, d_AxisPara(66))

  ret = ZAux_Direct_GetRepDist(g_handle, d_AxisNum, d_AxisPara(67))

  ret = ZAux_Direct_GetInvertStep(g_handle, d_AxisNum, d_AxisPara(68))

  ret = ZAux_Direct_GetMaxSpeed(g_handle, d_AxisNum, d_AxisPara(69))

  ret = ZAux_Direct_GetDAC(g_handle, d_AxisNum, d_AxisPara(71))

  ret = ZAux_Direct_GetErrormask(g_handle, d_AxisNum, d_AxisPara(72))

      End If

      End Sub

          Public Sub para_reset() '写入参数

          Dim ret As Long

          ret = 0

          d_AxisNum = Val(S_Axisnum.Text)

          g_handle = Form1.g_handle

      If (g_handle <> 0) Then

          Dim i

          For i = 0 To 72

              d_AxisPara(i) = Val(S_Axispara(i))

      Next

  ret = ZAux_Direct_SetAtype(g_handle, d_AxisNum, d_AxisPara(0))

  ret = ZAux_Direct_SetUnits(g_handle, d_AxisNum, d_AxisPara(1))

  ret = ZAux_Direct_SetAccel(g_handle, d_AxisNum, d_AxisPara(2))

  ret = ZAux_Direct_SetDecel(g_handle, d_AxisNum, d_AxisPara(3))

  ret = ZAux_Direct_SetSpeed(g_handle, d_AxisNum, d_AxisPara(4))

  ret = ZAux_Direct_SetCreep(g_handle, d_AxisNum, d_AxisPara(5))

  ret = ZAux_Direct_SetLspeed(g_handle, d_AxisNum, d_AxisPara(6))

  ret = ZAux_Direct_SetMerge(g_handle, d_AxisNum, d_AxisPara(7))

  ret = ZAux_Direct_SetSramp(g_handle, d_AxisNum, d_AxisPara(8))

  ret = ZAux_Direct_SetDpos(g_handle, d_AxisNum, d_AxisPara(9))

  ret = ZAux_Direct_SetMpos(g_handle, d_AxisNum, d_AxisPara(10))

  ret = ZAux_Direct_SetFsLimit(g_handle, d_AxisNum, d_AxisPara(12))

  ret = ZAux_Direct_SetRsLimit(g_handle, d_AxisNum, d_AxisPara(13))

  ret = ZAux_Direct_SetDatumIn(g_handle, d_AxisNum, d_AxisPara(14))

  ret = ZAux_Direct_SetFwdIn(g_handle, d_AxisNum, d_AxisPara(15))

  ret = ZAux_Direct_SetRevIn(g_handle, d_AxisNum, d_AxisPara(16))

  ret = ZAux_Direct_SetMovemark(g_handle, d_AxisNum, d_AxisPara(26))

  ret = ZAux_Direct_SetAxisAddress(g_handle, d_AxisNum, d_AxisPara(30))

  ret = ZAux_Direct_SetAxisEnable(g_handle, d_AxisNum, d_AxisPara(31))

  ret = ZAux_Direct_SetForceSpeed(g_handle, d_AxisNum, d_AxisPara(32))

  ret = ZAux_Direct_SetStartMoveSpeed(g_handle, d_AxisNum, d_AxisPara(33))

  ret = ZAux_Direct_SetEndMoveSpeed(g_handle, d_AxisNum, d_AxisPara(34))

  ret = ZAux_Direct_SetFastDec(g_handle, d_AxisNum, d_AxisPara(35))

  ret = ZAux_Direct_SetCornerMode(g_handle, d_AxisNum, d_AxisPara(38))

  ret = ZAux_Direct_SetDecelAngle(g_handle, d_AxisNum, d_AxisPara(39))

  ret = ZAux_Direct_SetStopAngle(g_handle, d_AxisNum, d_AxisPara(40))

  ret = ZAux_Direct_SetFullSpRadius(g_handle, d_AxisNum, d_AxisPara(41))

  ret = ZAux_Direct_SetZsmooth(g_handle, d_AxisNum, d_AxisPara(43))

  ret = ZAux_Direct_SetHomeWait(g_handle, d_AxisNum, d_AxisPara(46))

  ret = ZAux_Direct_SetFastJog(g_handle, d_AxisNum, d_AxisPara(47))

  ret = ZAux_Direct_SetFwdJog(g_handle, d_AxisNum, d_AxisPara(48))

  ret = ZAux_Direct_SetRevJog(g_handle, d_AxisNum, d_AxisPara(49))

  ret = ZAux_Direct_SetJogSpeed(g_handle, d_AxisNum, d_AxisPara(50))

  ret = ZAux_Direct_SetFholdIn(g_handle, d_AxisNum, d_AxisPara(51))

  ret = ZAux_Direct_SetFhspeed(g_handle, d_AxisNum, d_AxisPara(52))

  ret = ZAux_Direct_SetAlmIn( g_handle, d_AxisNum, d_AxisPara(65))

  ret = ZAux_Direct_SetRepOption(g_handle, d_AxisNum, d_AxisPara(66))

  ret = ZAux_Direct_SetRepDist(g_handle, d_AxisNum, d_AxisPara(67))

  ret = ZAux_Direct_SetInvertStep(g_handle, d_AxisNum, d_AxisPara(68))

  ret = ZAux_Direct_SetMaxSpeed(g_handle, d_AxisNum, d_AxisPara(69))

  ret = ZAux_Direct_SetDAC(g_handle, d_AxisNum, d_AxisPara(71))

  ret = ZAux_Direct_SetErrormask(g_handle, d_AxisNum, d_AxisPara(72))

      End If

  End Sub

  Private Sub Form_Load()

      S_Axisnum.Text = Form1.T_AxisId.Text

      S_reflash.value = 1

      Timer1.Enabled = True

  End Sub

  Private Sub Form_Unload(Cancel As Integer)

      Timer1.Enabled = False

  End Sub

  Private Sub S_Setpara_Click()

      If Form1.g_handle = 0 Then

          MsgBox "未链接到控制器!", vbOKOnly, "提示"

      Else

          Call para_reset

          S_reflash.value = 1

      End If

  End Sub

  Private Sub Timer1_Timer()'刷新

          Dim i

      If Form1.g_handle <> 0 And S_reflash.value = 1 Then

          Call para_reflash

          For i = 0 To 72

          S_Axispara(i).Text = Str(d_AxisPara(i))

      Next

  Else

          For i = 0 To 72

              S_Axispara(i).Text = "*"

          Next

      End If

  End Sub

          Private Sub S_Axispara_Click(Index As Integer) '准备改参数时停止刷新

          S_reflash.value = 0

  End Sub

  

  (四)编译运行演示

  1.EtherCAT连接

  连接控制器后点击“下载BAS文件到ROW”按钮,打开对应文件夹,选择“ECAT初始化”文件。

  20.png

  21.png

  22.png

  

  通过轴数量和节点数量可以看出,以及检测到驱动器并连接成功,接下来通过控制运动现象来确认驱动器受控制。

  2.测试使能

  23.png

  24.png

  

  使能状态off

  25.png

  26.png

  

  使能状态on

  轴使能正常。

  3.运动测试

  通过ZDevelop软件连接对应控制器时,可以通过“视图”→“示波器”调出示波器观察。

  正反转运动:

  27.png

  28.png

  

  定点运动:

  29.png

  30.png

  

  4.数字字典测试

  在EtherCAT通讯中,数据字典3002h-00h表示运动控制中位置环增益和速度环增益是否自动改变。1-自动,0-手动。

  

  31.png

  

  本次,正运动技术的应用开发之VB6.0就分享到这里,更多精彩内容请关注“正运动小助手”公众号。

  本文由正运动小助手原创,欢迎大家转载,共同学习,一起提高中国智能制造水平。文章版权归正运动技术所有,如有转载请注明文章来源。

32.png

  

邮箱留言

Copyright © 2013 精准24码全年无错版 Design by Zmotion 版权所有   粤ICP备13037187号    Powered by 运动控制器-运动控制卡

在线咨询