Hello Guest it is April 24, 2024, 10:28:02 AM

Author Topic: Modbus Programming guidance needed  (Read 4214 times)

0 Members and 1 Guest are viewing this topic.

Modbus Programming guidance needed
« on: November 23, 2020, 11:51:01 AM »
I am in need of information about programming the MODBUS.  I am unable to find documentation or examples that would allow me to setup a separate DRO on the machine that is connected to my MACH 4 computer via MODBUS.  The scripting manual ends at section 5.7 called MODBUS with no detail.  I have found some info but most is in German and I don't speak German.

I just want to update a Write parameter on the MODBUS DRO display whenever the XYZ and RPM values change on the MACH 4 screen.

If anyone could point me in the right direction, it would be very much appreciated.

Bob

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Modbus Programming guidance needed
« Reply #1 on: November 25, 2020, 11:37:12 AM »
I am interested in a little better info on modbus also.
I am only going to be bringing info into Mach4 but it is hard to find much in the way of how.
Re: Modbus Programming guidance needed
« Reply #2 on: November 25, 2020, 06:47:02 PM »
"me too"

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Modbus Programming guidance needed
« Reply #3 on: November 26, 2020, 04:52:34 PM »
MODBUS is going to be VERY device specific.  All of the device manufacturers use different terminologies and even give register information differently.  MODBUS, for the record, is always base 1 and decimal.  THAT is the standard.  But some device manufacturers give register information in base 0 and hex!!!  So yeah, it can be very confusing and there is no manual besides the ones from the manufacturers.  However, here is a nice writeup on the MODBUS protocol itself.  Having a good understanding of what MODBUS is supposed to be can help you untangle the mess of device documentation out there. 

https://www.modbusdriver.com/doc/libmbusmaster/modbus.html

The Mach 4 MODBUS plugin just maps I/O or registers to the device.  That is basically ALL it does.  There really isn't any MODBUS "programming" as in some special MODBUS script.  The MODBUS plugin just maps Mach resources (registers and I/O) to the device.  Then you can use any LUA scripting as you would with any other Mach resources from any other plugin. 

Steve

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Modbus Programming guidance needed
« Reply #4 on: November 26, 2020, 04:56:34 PM »
Oh, there is a nice MODBUS PLC simulator that is a great learning/test tool. 

https://sourceforge.net/projects/modrssim2/

Steve
Re: Modbus Programming guidance needed
« Reply #5 on: November 29, 2020, 03:27:03 PM »
I know MODBUS and how it works.  What I am asking for is more information about how MACH uses MODBUS and how to take the DRO value and send it to a register in the MODBUS.  Take a look at page 33 of the Scripting Manual in your Documents folder.    The document ENDS with the heading for section "5.7 Modbus". 

It's like AttSoft just said: "WTF, this is too hard, lets just let the user figure it out."  Is it really too much to ask for the document to be finished?  Is it a quality product if the documentation just ends mid sentence? 

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Modbus Programming guidance needed
« Reply #6 on: November 30, 2020, 12:10:36 AM »
The Mach 4 MODBUS plugin just maps I/O or registers to the device.  That is basically ALL it does.  There really isn't any MODBUS "programming" as in some special MODBUS script.  The MODBUS plugin just maps Mach resources (registers and I/O) to the device.  Then you can use any LUA scripting as you would with any other Mach resources from any other plugin. 

I have no idea who wrote that scripting manual and why a MODBUS header was even included.  Maybe the author thought there was some MODBUS specific scripting, included the header, and then forgot to remove it after they found out there wasn't any MODBUS specific scripting?  I didn't write the scripting manual.  But I did write the MODBUS plugin so believe me when I tell you that there is no MODBUS specific scripting.  :)

In fact, you can do what you want with no scripting at all.

1. Setup the MODBUS plugin to have a function that writes to a holding (most likely) register.  (Function 6, write single register).  You will need to know the address of this register on your MODBUS device.  You will also have to give a name for the Mach register that will be mapped to this MODBUS function.  Writing a value of 123456 to this Mach register will use the Function 6 to write 123456 to the holding register you specified. 

2. Drop a DRO on the screen.  Then scroll to the "Register" property and find your MODBUS plugin register that you created. 

3. When you type a value in the DRO, your holding register will be updated. 

ALL Mach registers can be used in this manner.  The only thing different here is that there is a MODBUS device baking the register.

Now, if you want something more fancy that this, like preloading the register with a value, you will have to do some non MODBUS specific scripting that the scripting manual most likely covers (sections 3.2.1 and 4.3 look pertinent).

I believe the rest of the manual documents things VERY well.  I think that section 5.7 was left in there by mistake.  We all make mistakes. 

Steve
Re: Modbus Programming guidance needed
« Reply #7 on: December 09, 2020, 11:07:50 AM »
Just to throw my 2 cents in.  I use modbus communications with a Click PLC from automation direct on something like 6 or 7 machines in our shop.  It is extremely easy to use.  I send information to and form Mach4 and the Click PLC quite often.  Like Steve said, sometimes you will have to add some script to update certain registers but a lot of it is plug and play. 
For example, I send my Spindle RPM from an encoder to the PLC to make sure the operators CANNOT press the tool release button unless the spindle is under 15rpm.  I don't allow the Tool Drawbar to activate unless the RPM is less than 15. 
I handle about 90% of my I/O with the PLC and just let Mach4 tell the PLC it wants an output on and the PLC will take care of the rest.  Or I can let the PLC tell Mach4 that an Input is active so Mach can do something with it.
Chad Byrd
Re: Modbus Programming guidance needed
« Reply #8 on: January 02, 2021, 04:35:21 PM »
Sounds like you have figured out exactly what I’m trying to accomplish.  I’m trying to use Modbus plugin in Mach4 to write to a coil in a Click PLC to turn on my spindle. I think I worked through the Mach 4 Modbus setup correctly, and also I assigned the “Spindle on” output to the Modbus function I created. When I push cycle start the spindle turns on as expected. I rejoice. Exactly 1 minute later, the coil on the plc turns off.  When I check the Mach 4 Modbus diagnostic tool, it says the Modbus connection is good, everything is highlighted green and “ok”.  Is my PLC rejecting the “write coil”or should Mach 4 be constantly updating the write coil function? Any insight would be much appreciated.
Re: Modbus Programming guidance needed
« Reply #9 on: January 02, 2021, 04:57:47 PM »
You can check the state of the coil in the mod is diagnostics. Be sure it is still being turned on.
Make sure that something isn’t forcing the coil off on the PLC ladder side as well 
Chad Byrd