時(shí)間:2020-11-27 16:07:32來源:正運(yùn)動(dòng)技術(shù)
今天,正運(yùn)動(dòng)小助手為大家分析一下應(yīng)用VB6.0開發(fā)一個(gè)總線初始化的運(yùn)動(dòng)控制應(yīng)用。
我們主要從VB6.0的項(xiàng)目新建、函數(shù)庫引用和PC函數(shù)使用方面講起,最后通過項(xiàng)目實(shí)戰(zhàn)——總線初始化例程講解,來讓大家熟悉它的項(xiàng)目開發(fā)。
在正式學(xué)習(xí)之前,我們先了解一下正運(yùn)動(dòng)技術(shù)的運(yùn)動(dòng)控制卡ECI2418和ECI2618。這兩款產(chǎn)品分別是4軸,6軸運(yùn)動(dòng)控制卡。
ECI2418支持4軸脈沖輸入與編碼器反饋,板載24點(diǎn)輸入,16點(diǎn)輸出,2AD,2DA,支持手輪接口,其中特定輸出口支持高速PWM控制。
ECI2618支持6軸脈沖輸入與編碼器反饋,板載24點(diǎn)輸入,16點(diǎn)輸出,2AD,2DA,支持手輪接口,其中特定輸出口支持高速PWM控制。
ECI2418,ECI2618均使用同一套API函數(shù),均支持C、C++、C#、LabVIEW、Python、Delphi等開發(fā)語言,支持VC6.0、VB6.0、Qt、.Net等平臺(tái),支持Windows、Linux、WinCE、iMac等操作系統(tǒng)。
以下是VB6.0
開發(fā)流程
一 新建EXE工程,加載函數(shù)庫。
(一)新建工程
打開Microsoft Visual Basic菜單,在“文件”→“新建工程”,選擇新建“標(biāo)準(zhǔn)EXE”工程。
新建工程自帶一個(gè)起始窗口,可以通過菜單“工程”→“屬性”更改起始窗口。
(二)加載PC函數(shù)庫
VB6.0需要對(duì)添加的dll文件進(jìn)行加載,否則系統(tǒng)找不到函數(shù)所引用的函數(shù)庫源,加載步驟如下。
1.找到廠家提供的光盤資料中的VB6.0資料。
2.將VB6.0壓縮包解壓,找到其中的dll庫文件
3.將dll文件zmotion.dll以及zauxdll.dll一起復(fù)制放入系統(tǒng)文件夾C:\Windows\System32中。假如編程系統(tǒng)是64位系統(tǒng),也要把上述文件復(fù)制到C:\Windows\SysWOW64中。
4.通過“開始”菜單→“Windows系統(tǒng)”→“命令提示符”或者在“開始”菜單搜索“cmd”打開命令提示符窗口,使用如下指令:
regsvr32 C:\ Windows\ SysWOW64\ zmotion.dll
regsvr32 C:\
Windows\
system32\
zmotion.dll
regsvr32命令用于注冊(cè)COM組件,是Windows系統(tǒng)提供的用來向系統(tǒng)注冊(cè)控件或者卸載控件的命令,以命令行方式運(yùn)行。Zmotion.dll加載后,才可以調(diào)用zauxdll的函數(shù)。
可以將該條指令復(fù)制到記事本上,然后把txt文件另存為bat文件來運(yùn)行。另外,一些自己下載vb6.0的額外部件也可以用該方法加載,加載后能在菜單“工程”→“引用”,“工程”→“部件”中找到對(duì)應(yīng)文件,本例程使用函數(shù)庫無需加載部件或引用。
(三)函數(shù)庫使用
將zauxdll.bas與工程文件放入同一文件夾,方便管理。
在工程資源管理器中右鍵添加模塊,或者在菜單“工程”→“添加模塊”功能中將zauxdll.bas添加入工程。
這樣就做好使用正運(yùn)動(dòng)PC函數(shù)庫的準(zhǔn)備了。
二 查看PC函數(shù)手冊(cè),了解其用法。
(一)PC函數(shù)手冊(cè)也在光盤資料里面。
具體路徑如下:
(二)PC編程。
一般先根據(jù)控制器連接方式選擇對(duì)應(yīng)的連接函數(shù)連接控制器,返回控制器句柄。接著用返回的控制器句柄,實(shí)現(xiàn)對(duì)控制器的控制,大部分函數(shù)都有對(duì)控制器的指向。通常有:
Public g_handle As Long
控制器句柄是連接控制器的重要標(biāo)志。
(三)通過網(wǎng)口連接控制器,獲取句柄。
通過網(wǎng)口 iret = ZAux_OpenEth(“127.0.0.1”, g_handle)或者串口 iret = ZAux_OpenCom(1, g_handle)連接控制器,獲取控制器句柄 g_handle。
(四)下載總線初始化bas文件
下載總線初始化 bas文件到控制器 iret = ZAux_BasDown(g_handle, sFilePath, 1),sFilePath是對(duì)應(yīng)總線初始化的文件地址,利用 CommonDialog對(duì)話框操作部件,獲取對(duì)象文件地址。
總線初始化文件是基于ZDevelop編寫的EtherCAT和RTEX初始化程序,通過ZAux_BasDown方式下載到控制器以直接運(yùn)行。
(五)EtherCAT數(shù)據(jù)字典讀寫
EtherCAT數(shù)據(jù)字典讀寫 ZAux_BusCmd_SDORead和 ZAux_BusCmd_SDOWrite。
其中對(duì)象字典編號(hào)、對(duì)象字典子編號(hào)、數(shù)據(jù)類型是十進(jìn)制輸入,手冊(cè)上是十六進(jìn)制表示,使用時(shí)注意轉(zhuǎn)換。
(六)位置環(huán)增益與速度環(huán)增益調(diào)整
松下A6B系列EtherCAT總線驅(qū)動(dòng)器中:
位置環(huán)增益對(duì)應(yīng)數(shù)據(jù)字典為 3100H-00H(第一位置環(huán)增益)和 3105H-00H(第二位置環(huán)增益);
速度環(huán)增益對(duì)應(yīng)數(shù)據(jù)字典為 3101H-00H(第一速度環(huán)增益)和 3106H-00H(第二速度環(huán)增益);
自動(dòng)選擇增益參數(shù)的標(biāo)志位為 3002H-00H。
具體請(qǐng)參考光盤資料(P315~P318):技術(shù)資料→ECAT通訊規(guī)格篇→MINAS_A6B系列→EtherCAT通訊/選擇類型。
本篇文章使用第一位置環(huán)增益和第一速度環(huán)增益,通過實(shí)時(shí)自動(dòng)增益調(diào)諧設(shè)置選擇是否改變?cè)鲆鎱?shù)。
三 項(xiàng)目實(shí)戰(zhàn)之連續(xù)插補(bǔ)運(yùn)動(dòng)例程講解
(一)界面講解
(二)例程簡(jiǎn)易流程圖
//相關(guān)函數(shù)
// 建立與控制器的網(wǎng)口通訊
iret = ZAux_OpenEth(m_ipaddress, g_handle) '網(wǎng)口連接控制器
//定時(shí)器刷新
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) ‘軸使能關(guān)閉
iret = ZAux_Direct_SetAxisEnable(g_handle, m_axisnum, 1) '軸使能打開
//正轉(zhuǎn)
iret = ZAux_Direct_Single_Vmove(g_handle, m_axisnum, 1)
//反轉(zhuǎn)
iret = ZAux_Direct_Single_Vmove(g_handle, m_axisnum, -1)
//相對(duì)運(yùn)動(dòng)
iret = ZAux_Direct_Single_Move(g_handle, m_axisnum, Val(T_Move_s))
//絕對(duì)運(yùn)動(dòng)
iret = ZAux_Direct_Single_MoveAbs(g_handle, m_axisnum, Val(T_Move_s))
//停止
iret = ZAux_Direct_Single_Cancel(g_handle, m_axisnum, 2)
//運(yùn)動(dòng)增益讀寫
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信號(hào)讀寫
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 '當(dāng)前使用的卡句柄
Public iret As Long '函數(shù)返回值
Public g_basflag As Boolean '//BAS文件加載標(biāo)志位
Public g_InitStatus As Integer '//總線初始化完成狀態(tài) 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'//文件已經(jīng)加載
End If
Else
Form1.Caption = "未連接"
MsgBox "控制器鏈接失敗,請(qǐng)檢測(cè)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() '以太網(wǎng)連接
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)'網(wǎng)口連接控制器
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'//文件已經(jīng)加載
End If
Else
Form1.Caption = "未連接"
MsgBox "控制器鏈接失敗,請(qǐng)檢測(cè)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'//文件已經(jīng)加載
End If
Else
MsgBox "連接失敗,請(qǐng)檢查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時(shí)程序會(huì)自動(dòng)初始化一次
PrivateSub T_BusInit_Click()
If(g_handle = 0) Then
MsgBox "未鏈接到控制器!", vbOKOnly, "提示"
Else
If(g_basflag And(g_InitStatus <> -1)) Then '-1:可能正在執(zhí)行初始化
g_InitStatus = -1
Dim Buffer As String * 10240
T_BusStatus.Text = "初始化未完成"
'任務(wù)1重新運(yùn)行BAS中的初始化函數(shù)
iret = ZAux_Execute(g_handle, "RUNTASK 1,Ecat_Init", Buffer, 0)
Else
MsgBox "Bas文件未加載!", vbOKOnly, "提示"
End If
End If
EndSub
4.軸運(yùn)動(dòng)
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() '//清除軸報(bào)警
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() '正轉(zhuǎn)
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() '反轉(zhuǎn)
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() '運(yùn)動(dòng)
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() '運(yùn)動(dòng)
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() '驅(qū)動(dòng)器自身回零
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.總線數(shù)據(jù)交互
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() '自動(dòng)增益標(biāo)志設(shè)置
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() '速度環(huán)、位置環(huán)增益寫
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)) '位置環(huán)增益寫
iret = iret + ZAux_BusCmd_SDOWrite(g_handle, 0, Val(T_SdoNode2.Text), Val(CLng("&H" & "3101")), 0, 3, Val(T_VeloGain_W.Text)) '速度環(huán)增益寫
If (iret <> 0) Then
MsgBox "寫入失敗!", vbOKOnly, "提示"
End If
Else
MsgBox "非ETHERCAT模塊!", vbOKOnly, "提示"
End If
End If
End Sub
Private Sub T_ECAT_R_Click() '速度環(huán)、位置環(huán)增益讀
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) '位置環(huán)增益讀
iret = iret + ZAux_BusCmd_SDORead(g_handle, 0, Val(T_SdoNode3.Text), Val(CLng("&H" & "3101")), 0, 3, m_sdo_data2_2) '速度環(huán)增益讀
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.參數(shù)刷新
1)在主窗體
Private Sub Form_Load() '窗體加載時(shí)運(yùn)行
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 '關(guān)閉主窗體時(shí)關(guān)閉程序
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 '//已經(jīng)加載文件并且正在初始化 讀取狀態(tài)
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文件中的變量判斷總線初始化完成狀態(tài)
ret = ret + ZAux_BusCmd_GetNodeNum(g_handle, 0, m_BusNodeNum)
'//讀取槽位0上節(jié)點(diǎn)個(gè)數(shù)。
ret = ret + ZAux_Direct_GetUserVar(g_handle, "Bus_TotalAxisnum", m_BusAxisNum)
'//讀取BAS文件中的變量判斷掃描的總軸數(shù)
g_InitStatus = tempstatus
'//初始化完成刷新狀態(tài)
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 + "隨動(dòng)誤差超限告警;"
If mod_tr(2) Then axisStatues_str = axisStatues_str + "與遠(yuǎn)程通訊出錯(cuò);"
If mod_tr(3) Then axisStatues_str = axisStatues_str + "遠(yuǎn)程驅(qū)動(dòng)器報(bào)錯(cuò);"
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 + "找原點(diǎn);"
If mod_tr(7) Then axisStatues_str = axisStatues_str + "hold速度保持信號(hào)輸入;"
If mod_tr(8) Then axisStatues_str = axisStatues_str + "隨動(dòng)誤差超限出錯(cuò);"
If mod_tr(9) Then axisStatues_str = axisStatues_str + "超過正向軟限位;"
If mod_tr(10) Then axisStatues_str = axisStatues_str + "超過負(fù)向軟限位;"
If mod_tr(11) Then axisStatues_str = axisStatues_str + "CANCEL執(zhí)行中;"
If mod_tr(12) Then axisStatues_str = axisStatues_str + "脈沖頻率超過最大速度;"
If mod_tr(14) Then axisStatues_str = axisStatues_str + "機(jī)械手指令坐標(biāo)錯(cuò)誤;"
If mod_tr(18) Then axisStatues_str = axisStatues_str + "電源異常;"
If mod_tr(21) Then axisStatues_str = axisStatues_str + "運(yùn)動(dòng)中觸發(fā)特殊運(yùn)動(dòng)指令失敗;"
If mod_tr(22) Then axisStatues_str = axisStatues_str + "告警信號(hào)輸入;"
If mod_tr(23) Then axisStatues_str = axisStatues_str + "軸進(jìn)入暫停狀態(tài);"
End If
If axisIdle = 0 Then
axisIdle_str = "運(yùn)動(dòng)中"
Else
axisIdle_str = "運(yùn)動(dòng)結(jié)束"
End If
T_AxisStatus.Caption = axisStatues_str
T_Idle.Text = axisIdle_str
End Sub
Private Sub T_AxisId_Change() '修改軸參數(shù)
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 '變體類型,使數(shù)組包含single和long型
Private d_AxisNum As Long
Public g_handle As Long
Public Sub para_reflash() '讀取參數(shù)
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)'讀取運(yùn)動(dòng)標(biāo)號(hào)與當(dāng)前運(yùn)動(dòng)標(biāo)號(hào)相同
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() '寫入?yún)?shù)
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) '準(zhǔn)備改參數(shù)時(shí)停止刷新
S_reflash.value = 0
End Sub
(四)編譯運(yùn)行演示
1.EtherCAT連接
連接控制器后點(diǎn)擊“下載BAS文件到ROW”按鈕,打開對(duì)應(yīng)文件夾,選擇“ECAT初始化”文件。
通過軸數(shù)量和節(jié)點(diǎn)數(shù)量可以看出,以及檢測(cè)到驅(qū)動(dòng)器并連接成功,接下來通過控制運(yùn)動(dòng)現(xiàn)象來確認(rèn)驅(qū)動(dòng)器受控制。
2.測(cè)試使能
使能狀態(tài)off
使能狀態(tài)on
軸使能正常。
3.運(yùn)動(dòng)測(cè)試
通過ZDevelop軟件連接對(duì)應(yīng)控制器時(shí),可以通過“視圖”→“示波器”調(diào)出示波器觀察。
正反轉(zhuǎn)運(yùn)動(dòng):
定點(diǎn)運(yùn)動(dòng):
4.數(shù)字字典測(cè)試
在EtherCAT通訊中,數(shù)據(jù)字典3002h-00h表示運(yùn)動(dòng)控制中位置環(huán)增益和速度環(huán)增益是否自動(dòng)改變。1-自動(dòng),0-手動(dòng)。
本次,正運(yùn)動(dòng)技術(shù)的應(yīng)用開發(fā)之VB6.0就分享到這里,更多精彩內(nèi)容請(qǐng)關(guān)注“正運(yùn)動(dòng)小助手”公眾號(hào)。
本文由正運(yùn)動(dòng)小助手原創(chuàng),歡迎大家轉(zhuǎn)載,共同學(xué)習(xí),一起提高中國智能制造水平。文章版權(quán)歸正運(yùn)動(dòng)技術(shù)所有,如有轉(zhuǎn)載請(qǐng)注明文章來源。
中國傳動(dòng)網(wǎng)版權(quán)與免責(zé)聲明:凡本網(wǎng)注明[來源:中國傳動(dòng)網(wǎng)]的所有文字、圖片、音視和視頻文件,版權(quán)均為中國傳動(dòng)網(wǎng)(m.u63ivq3.com)獨(dú)家所有。如需轉(zhuǎn)載請(qǐng)與0755-82949061聯(lián)系。任何媒體、網(wǎng)站或個(gè)人轉(zhuǎn)載使用時(shí)須注明來源“中國傳動(dòng)網(wǎng)”,違反者本網(wǎng)將追究其法律責(zé)任。
本網(wǎng)轉(zhuǎn)載并注明其他來源的稿件,均來自互聯(lián)網(wǎng)或業(yè)內(nèi)投稿人士,版權(quán)屬于原版權(quán)人。轉(zhuǎn)載請(qǐng)保留稿件來源及作者,禁止擅自篡改,違者自負(fù)版權(quán)法律責(zé)任。
產(chǎn)品新聞
更多>新品發(fā)布:CD300系列總線型伺服驅(qū)動(dòng)器
2024-10-31
2024-10-31
2024-10-31
新勢(shì)能 新期待|維智B1L直線伺服驅(qū)動(dòng)器
2024-10-31
纖薄之間,化繁為簡(jiǎn)|合信全新simple系...
2024-10-29
2024-10-18
推薦專題
更多>