关于MODBUS制作MPG手轮的疑问。
本帖最后由 王涛 于 2016-11-16 23:15 编辑关于Mach3 modbus有两种方式一种是通过Plug-in方式,这种方式要开发插件读取Modbus设备的数据,这种方式可以掌控整个Mach3的所有变量。这里不做说明。现在要说的是另外的一种方式——即非插件方式的自动查询方式(Autopoller)。这种方式会定时发送数据请求报文。Modbus设备把数据准备好给mach3读取。下图就是mach3 modbus 非插件方式的设设置。这种设置下地址进行了从映射
上图就是这种映射只要和modbus设备通信正常后就能轻松的通过TEST MODBUS得到modbus设备的数据。或是用vb来调试
列如:A=GetInput(64) MsgBox"A="&A就能得到数据。
这里是一个modbus手轮的宏程序。
' Macropump developed for Peach Hill MPG Set
' Based on Hofmann MODIO Panel
' Objective to give Remote Pendant based, Axis, Step, Feed Over ride, Via Analogue inputs 1,2 &3
' Step and Direction from Mechanical MPG Using I/P 6 &7
' In addition Digital I/Ps for E-Stop,Digital Dig 0 normally closed push button
' Digital 1 & 2 via center off 3 pos switchJog On/Off, and Shuttle Off/On
' Jog mode thru Analog In 1
' Jog step val thru Analog In 2
' Jog speed over ride thru Analog In 3
' E-Stop via Port 0 Pin 0 no Software required
MPGAxis = Getinput ( 64 ) 'analog input 1 on ModIO
Select Case MPGAxis
Case <85
'do nothing
State = 0
Case < 277
If GetOEMLED ( 14 ) = 0 Then 'If not set to continuous Jog Mode
DoOEMButton ( 276 ) 'Set jog to Continuous
End If
State = 1
Case <490
If GetOEMLED ( 15 ) = 0 Then 'If not set to Step Jog Mode
DoOEMButton ( 275 ) 'Set jog to Continuous
End If
State = 2
Case <707
If GetOEMLED ( 57 ) = 0 Then 'If not set to MPG Jog Mode
DoOEMButton ( 306 ) 'Set jog to MPG
End If
If GetOEMLED ( 59 ) = 0 Then
DoOEMButton ( 185 ) 'Set MPG to Jog X
End If
State = 3
Case <919
If GetOEMLED ( 57 ) = 0 Then 'If not set to MPG Jog Mode
DoOEMButton ( 306 ) 'Set jog to MPG
End If
If GetOEMLED ( 60 ) = 0 Then
DoOEMButton ( 186 ) 'Set MPG to Jog Y
End If
State = 4
Case >919
If GetOEMLED ( 57 ) = 0 Then 'If not set to MPG Jog Mode
DoOEMButton ( 306 ) 'Set jog to MPG
End If
If GetOEMLED ( 61 ) = 0 Then
DoOEMButton ( 187 ) 'Set MPG to Jog Z
End If
State = 5
End Select
' Logic for setting Jog Ammounts thru Analog In 2
JOGInc = Getinput ( 65 ) 'analog input 2 on ModIO
Select Case JOGInc
Case <256
If GetOEMLED ( 57 ) <> 0 Then 'If is set Jog Step
DoOEMButton ( 265 ) 'Set Step to 1mm
End If
Case <714
If GetOEMLED ( 57 ) <> 0 Then 'If is set Jog Step
DoOEMButton ( 266 ) 'Set Step to 0.1mm
End If
Case >714
If GetOEMLED ( 57 ) <> 0 Then 'If is set Jog Step
DoOEMButton ( 267 ) 'Set Step to 0.01mm
End If
End Select
' Setting Feedrate Over rate from Analogue 3
Option Explicit
Dim fro As Integer
Const Input3Sig = 18
fro = GetInput ( 66 )
fro = (fro * 195.0)/1024.0
SetDRO 21, FRO+5
'
Rem DRO display On ModIO
'
Option Explicit
Dim Display As String
Dim SVal As String
Dim iCount As Integer
Dim iBase As Integer
Dim strMode (6) As String
'
Const slave = 6 ' Default config
Const NoAxesToDisplay = 4
If GetLED (1) Then strMode (0) = " inch" Else strMode (0) = " mm"'Added extra space
If getOEMLED (16) Then strMode (1) ="<m/c>" Else strMode (1)=" "'coord sys Extra Space
If GetOEMLED (83) Then strMode (2) =" " Else strMode (2) = " NoJog"
If GetLED (0) Then strMode (3) = " EStop" Else strMode (3) = " "
strMode (4) = " "
strMode (5) = " "
Display =""
For iCount = 0 To NoAxesToDisplay - 1
SVal = Right (" " & Format (GetDro (iCount), "+0.0000;-0.0000"), 11)
If iCount < 3 Then 'X, Y, Z
iBase = Asc ("X")
Else 'A, B, C
iBase = Asc ("A") - 3
End If
Display = Display & " " & Chr (iBase + iCount) & SVal & " " & StrMode (iCount)
Next iCount
SetModIOString (slave, 0, 0, Display)
这个程序接收来自MODBUS的三个寄存器的输入用来改变(Jog mode thru Analog In 1
' Jog step val thru Analog In 2' Jog speed over ride thru Analog In 3)。和DRO的输出给MODBUS手轮显示坐标值。
那么问题来了这个宏并没有对手轮的脉冲计算和处理。MPG电子手轮的脉冲从哪里输入,映射的是Encoder 1 Encoder 2(67、68 )中的那一个????
这个值是如何传到mach3 里的MPG1count计算器的???
在C:\Mach3\Brains目录下有一个文件是ModIOMPG.brn这个文件里面有过对MPG1count++进行过处理可是它所对应的Modbus地址不对。它的是零地址,而且在brian里激活这个ModIOMPG.brn好像也没有什么反应。 我个人认为,modbus不适合高速设备,比如编码器,手轮,伺服。 这里上传一个mach3空白的插件给大家,有了这个插件可以做二次开发。开发自己的控制板自己的modbus控制卡总之mach3的所以变量都可以引用,然后通过串口,usb等输出给控制卡。在控制卡上可以做自己的控制算法。把产生的.dll文件放在MACH3的plugs文件夹里激活它。就可以了。
页:
[1]