Hello Guest it is October 15, 2019, 03:42:51 PM

Author Topic: AddressingTCP Modbus registers in VB  (Read 3335 times)

0 Members and 1 Guest are viewing this topic.

AddressingTCP Modbus registers in VB
« on: December 25, 2014, 08:01:24 PM »

    This is the first of what I'm sure will be many questions about how to get an Automation Direct DL06 to run the tool changer and spindle on a machine retrofit I'm working on.
The tool changer is a 16 station carousel run by what I presume is a stepper motor (the ID plate is worn off and Matsuura USA is still trying to source the wiring diagram for the machine) and 4 pneumatic solenoids. Originally I planned to use the m6 start macro written by the guys over at Machmotion. (see bellow) The macro is designed with the DL06 in mind and also comes with a ladder program which can be downloaded and written strait to the dl06. However, the addresses listed in the macro for current tool and max tool were all wrong. The octal address in the DL06 for max tool is V1206 while the modbus address translates to 646. I confirmed this address in the mach3 modbus test window. The addresses listed in the Macro don't match up at all. But, even when I changed the addresses in the macro to the appropriate addresses, I still can't seem to get the M6 macro to communicate with the DL06. My question is this, what is the protocol for accessing and writing to modbus tcp locations in VB? I'm talking both discrete input contact locations and reading complete word data like analog input or current tool value.

    Ive spent the last few days reading all I can about modbus tcp in mach3, watching all the relevant videos on the artsoft tutorial page and reading forum posts pertaining to using DL06s. After seeing what some of you guys are doing with them, I'm pretty excited to learn all I can about them.  I'm an oil field welder by trade, so most of these concepts are fairly foreign to me. Thanks for any and all help!

This is the m6 start macro

Dim Num As Integer
Dim Number As Integer

Sub Main

TimeOut = 20 '20 Seconds

Finished = 1600
CurTool = 1605
MaxTool = 1606    

StartVal = 1500
ComTool = 1505

CurrentTool = GetUserDRO(CurTool)

MaxToolNum = GetUserDRO(MaxTool) ''From PLC
CommandedTool = GetSelectedTool()  ''Get selected tool

If CurrentTool = CommandedTool Then ''current tool equals commanded tool
SetCurrentTool( CommandedTool )
End If

If CommandedTool <> Current_Tool Then ''The current tool must be different than commanded tool

   If CommandedTool > MaxToolNum Or CommandedTool < 1 Then ''Make sure the tool number is correct
      r = MsgBox("Incorrect Tool Number.",1, "ERROR")
   End If

   Code("G00 G53 X " & GetOEMDRO(1200) & "Y" & GetOEMDRO(1201) & "Z" & GetOEMDRO(1202)) ''Move to correct location
   While IsMoving
      Sleep 10

   SetUserDRO(ComTool, CommandedTool)   ''Send Commanded Tool to the PLC
   SetUserDRO(StartVal, (GetUserDRO(StartVal) + 32768)) ''Turn on
   Sleep 500
   SetUserDRO(StartVal, (GetUserDRO(StartVal) - 32767)) ''Turn off
   While (GetUserDRO(Finished) And 32768)
   Sleep 100
   i = i + 1
   If i > (TimeOut*10) Then ''Time out in 20 seconds
      r = MsgBox("Tool Change is not Complete.",1, "Timeout Error")
      Sleep 100
   End If

   CurrentTool = GetUserDRO(CurTool)
   If CurrentTool = CommandedTool Then ''Does the current tool from the PLC match the commanded tool?
      SetCurrentTool( CommandedTool ) ''If so, update tool number
      r = MsgBox("Tool Change Failure.",1, "Error") ''Else somethine went wrong
   End If

End If ''Tool commanded position is different than current position

End Sub

Re: AddressingTCP Modbus registers in VB
« Reply #1 on: December 26, 2014, 01:48:41 AM »
I should also have mentioned, the only means of communication between the pc and plc is an ECOM module.
Re: AddressingTCP Modbus registers in VB
« Reply #2 on: December 26, 2014, 09:34:00 PM »
Well, I think I may have found a way around the problem. I had read that the registers can be called via VB through the command GetMasterInput(0-1023) where 0-1023 is the local address listed as Local(VAR) in the TCP modbus setup page. However, I couldn't seem to get that to work. Instead, I am using a brain to write the register values to a DRO and then reading from that DRO via the command GetUserDRO(###). So far this seems to be working. The only drawback is that you can't really access bit of word through a DRO/brain setup.