Este é um exemplo de macro para funcionar com um dispositivo modbus:
' Macro To interface To ModIO/TC
'
' The Mach3 Modbus interface should be configured:
' ModIO Checkbox NOT checked
' First line of AutoPolling Input not checked - No inputs can go to Ports
' and Pins
' Second line of Inputs Checked, Slave = x, Start Regs = 1200, # Regs = 3
' First line of Autopolling Output not checked - no output Ports & Pins
' Second line of Output Slave = x, Start Regs = 1100, # Regs = 2
' This macro should be used with M990 in the Mach3 Init string. This is needed
' to synchronisethe Initiation flag values in ModIO and Mach3.
' M999 must be called after a ModIO reset too.
Option Explicit ' requires declarations
Dim tool As Integer
Dim ChangesCalled As Integer
Dim Dummy As Integer
Dim ChangesWere As Integer ' value before this request
Dim ChangerCount As Integer ' value returned from the ModIO
Dim ErrNo as Integer
Const ChangerCurrPos = 64 ' Inputs 1200 Current tool
Const ChangerCountReg = 65 ' 1201 Change done indicator - this is the
' same as 1101 when done
Const ChangerErrCode = 66 ' 1202 Error code reply if problems
Const ChangerReqPos = 64 ' Outputs 1100
Const ChangerInitReg = 65 ' 1101 initiates a change when made different
' to 1201
Const CallDRONo = 1080
' This just keeps count of the number of changes done
ChangesCalled = GetUserDRO (CallDRONo) ' what we think is current
ChangesCalled = ChangesCalled + 1
SetUserDRO CallDRONo, ChangesCalled ' remember new value in Mach3
' Now lets kick the ModIO/TC
tool = GetSelectedTool() ' what tool does user want
SetModOutput ChangerCurrPos, tool ' output requested tool number
ChangesWere = GetInput (ChangerCountReg) ' read current ChangerCountReg
SetModOutput ChangerInitReg, ChangesWere+1 ' initiate the turret change
ChangerCount = ChangesWere ' How many does it think is has done so far
While (ChangesWere = ChangerCount) And (GetInput (ChangerErrCode) = 0)
' not failed or finished
Sleep(50)
ChangerCount = GetInput (ChangerCountReg)
Wend ' loop until changer tells is it done something
If GetInput (ChangerErrCode) <> 0 Then
ErrNo = GetInput (ChangerErrCode)
Message "Toolchanger raised error " & ErrNo
Code "M0" ' chuck it all in.
' *** Must be a better solution here
Else
Message "Tool changed " & ChangesCalled & " times"
End If
SetCurrentTool GetInput (ChangerCurrPos)
SetModOutput ChangerCurrPos, 0 ' Clear tool number incase the Mach3 and
' ModIO initiate counters get out of step
' when we might get a spurious change
' end of Toolchanger macro
' *** Note M6End.M1S should be empty