Hello Guest it is April 19, 2024, 07:22:36 AM

Author Topic: MACH4 - Modbus  (Read 80743 times)

0 Members and 1 Guest are viewing this topic.

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: MACH4 - Modbus
« Reply #10 on: May 07, 2014, 11:14:02 AM »
I understand Simpson. I have attached a couple of screen shots I hope will help. Hopefully I will get to play with it some more later today.

Brett

This is helpful, thanks. What is mbi1? do you make that up or is it a fixed system var? If you make it up, where is that done? If it is a system var, is there a list of them somewhere?
Re: MACH4 - Modbus
« Reply #11 on: May 07, 2014, 11:16:56 AM »
The name is what you would like to name the register.. In Mach4 you refer to the registers by name not by number!

The rest of it is:
Slave ID
Register (we have all the tables so sometimes you need to drop the first number.. for example I am working on a Mitsubishi drive now and I had to remove the 40000 because we know it should be in table 4.

Here are some examples of how I read and write:

Function from my RB1 to jog the head up by setting the HeadJogDir and HeadJogOn:
Code: [Select]
function HeadUp()
    local inst= mc.mcGetInstance();
    --Get the hReg handle of the modbus analog register
    local HeadUp = mc.mcRegGetHandle(inst, "modbus0/HeadJogDir");
    local HeadOn = mc.mcRegGetHandle(inst, "modbus0/HeadJogOn");

    if (HeadUp ~= 0 and HeadOn ~= 0) then
        mc.mcRegSetValue(HeadUp, 0);
        mc.mcRegSetValue(HeadOn, 1);
    end
end

Reading the Hz from the inverter from the Hz register:
Code: [Select]
   local inst= mc.mcGetInstance();
    local Hz = 0;
    local HzReg = mc.mcRegGetHandle(inst, "modbus0/Hz");
    if (HzReg ~= 0) then
      Hz =  mc.mcRegGetValue(HzReg);
    end

You can also set it to be an input or an output on a register.. The register types are important.. you need to select the correct type (this is a modbus standard)
Hope that helps..
Brian
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: MACH4 - Modbus
« Reply #12 on: May 07, 2014, 11:37:14 AM »
OK Thanks everyone.  :-*  I have a few nuggets to chew on now.

First I will need to change the comm method per Steve's post.

Then create some vars per Brett's post.

Then try to read and right to them per Brian's post.

That should keep me busy for a while.

Re: MACH4 - Modbus
« Reply #13 on: May 07, 2014, 11:39:35 AM »
OK Thanks everyone.  :-*  I have a few nuggets to chew on now.

O gosh... What flavor? I if they are brown with yellow spots, if so I can help you. Don't use them and DON'T chew them!
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: MACH4 - Modbus
« Reply #14 on: May 07, 2014, 05:32:18 PM »
Getting 'Illegal argument error' in Mach4 Modbus diagnostic.

I do not see this error in any of the Modbus docs.

What is an 'argument'
Re: MACH4 - Modbus
« Reply #15 on: May 08, 2014, 08:34:18 AM »
What are you talking to for a device?
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com

Offline Illya

*
  •  11 11
    • View Profile
Re: MACH4 - Modbus
« Reply #16 on: May 08, 2014, 09:35:44 PM »
Hi Simpson
What device are you trying to connect to Modbus?
If you post a little more info I can try and help :)
I have 2 Allen Bradley Micrologix 1200 PLC's connect via 2 x RS232 connections
48 inputs 40 outputs

Illya

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: MACH4 - Modbus
« Reply #17 on: May 08, 2014, 11:25:00 PM »
An Illegal argument error means that the argument to the modbus function is out of range.  For example, each table can have 65535 registers but you put in 70001 by mistake.  That would give an illegal argument error.

Or,

Say your device docs give a register number for the Control and Status Register of 40010.  If you entered that for your modbus register in the config, you would get a illegal argument error.  Because 40010 really means table 4 (holding registers, register 10).  So entering 10 for the register is correct.

Also, if you enter a register number that your device does not have, then you will get that error. 

It is important to note that the modbus plugin uses the Modicon convention for registers.  Your device may give an address like "holding register 0".  That is NOT the Modicon convention.  So you must add one to the address to get the correct register, 1 in this case.

In the next update, I have added bit packing for register reads and writes.  I thought it was in the plugin that you guys had but it was not.  Somehow I botched the update and lost that functionality.  Anyway, the next update will include bit packing and also fixes the RS485 enable stickiness.

Hopefully I can get time to do some example docs for modbus in the near future.  But in the mean time, have a look at this modbus device simulator: http://www.plcsimulator.org/.  It is a really neat little program that emulates a TCP modbus device.  You simply run the program and then configure the modbus plugin to connect to 127.0.0.1, port 502.  You can then experiment with the different features of the modbus plugin and get the feel for how it works. 

Steve

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: MACH4 - Modbus
« Reply #18 on: May 09, 2014, 08:28:36 AM »
Thanks for the replies. It is good to know someone has it working.

I'll attempt to answer and also speculate on what I think might be happening.

1) Hardware: my 4th axis motor controller and also the ATC controller  use Arduino MEGA development boards. These have an AtMEL processor and run C code (or Arduino's variant). These connect to the PC via USB and use a USB-> Serial chip and the appropriate driver to emulate a COM port at the PC side. They can be connected to a TTL-> RS232 converter and comm thru the actual physical serial port as well, but I have been using the virtual COM with MACH3 for a couple of years without issue.

2) Software: all of the Modbus functions are done by the AtMEL processor. The Modbus code is pubic and needed only some minor tweaking to work with MACH3. Options for MACH4 are to modify the code to use the structure described by Steve -or- there are also version of the public code that adhere to Modicon.

Problem:

I have a question about something Steve posted and I will ask about that separately, but the problem seems to be that MACH4 is not polling the slave. The reason I say this is that the board has indicators on the TX/RX lines and when I hook up to MACH3, I see the polling taking place because the LEDs are flashing. In the MACH3 'diag' moving the speed slider changes the flash rate and the correct (changing) test data is being read from the Processor.

MACH4 behavior:

The device is recognized and MACH4 reports 'Modbus0 OK' and displays a polling frequency. However, the LED on the board will flash once when exiting the config, but there is no continued flashing which indicates that MACH4 is not polling the device. I thought this might be an incompatibility with the virtual COM so I connected via TCP and the behavior is the same.

What is interesting is that MACH4 seems to think it is talking to the Modbus, based on it reporting 'Modbus OK' and posting a frequency. However, the board is not indicating that it is receiving anything on RX.

What is confusing to me is that MACH4 seems to definitely think it is talking to something, but there is silence on the other side.

My BAD: I am transitioning to a newer and much faster processor on the Arduino DUE board so I have a numch of those available to mess with. The only MEGA board I have in-house is running my 4th axis, so I can't pull that one out to play with. The newer DUE board works differently, has different libraries and the serial hardware on the board is different. I had to change the code for the DUO but it works fine with MACH3, however, it is still something of an unknown, so I have ordered a MEGA board to test with as I am much more familiar with that device.  Hopefully it will be here today.

  

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: MACH4 - Modbus
« Reply #19 on: May 09, 2014, 08:33:05 AM »
Hi Simpson
What device are you trying to connect to Modbus?
If you post a little more info I can try and help :)
I have 2 Allen Bradley Micrologix 1200 PLC's connect via 2 x RS232 connections
48 inputs 40 outputs

Illya

Thanks for the reply. If I could use a PLC, it would be Miller Time!  It sounds like you are going in thru the RS232 Hardware. I can do that, but have not tried that yet. I am going thru a virtual COM port for the serial interface. This works fine with MACH3 and I thought it might be the problem with MACH4, so I went in thru TCP and the behavior did not change. I can also go in thru the physical RS232 port, but I'd just need to throw together a test rig and I have decided to back up a notch and work with a processor that I am more familiar with and eliminate an 'unknown' from the mix.  Hopefully will be here today.