Hello Guest it is April 20, 2024, 01:01:48 AM

Author Topic: Arduino, Mach4 and ModbusIP.  (Read 11373 times)

0 Members and 1 Guest are viewing this topic.

Re: Arduino, Mach4 and ModbusIP.
« Reply #10 on: May 13, 2018, 03:13:27 AM »
Cool concept. Seems like something is either wrong with the arduino library or I don't know what I'm doing or something else. I'm not able to use 0, 8 or 16 as a reg value. I didn't go any further to check 24 but maybe...They just don't work. The Modbus plugin doesn't recognize the 8th "coil" input either. Neither does wireshark.

Code: [Select]
#include <ModbusIP_ENC28J60.h>

ModbusIP mb;
long ts;

int i = 0;
int regs[] = {1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17}; // values 0, 8 and 16 don't work for registers????
int pins[] = {2, 3, 4, 5, 6, 7, 8, 9, 14, 15, 16, 17, 18, 19};

void setup() {
  for(i = 0; i < sizeof(pins)/sizeof(pins[0]); i++)
    pinMode(pins[i], INPUT);
   
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
  byte ip[] = { 192, 168, 1, 210 }; 
  mb.config(mac, ip);

  for(i = 0; i < sizeof(regs)/sizeof(regs[0]); i++)
    mb.addCoil(regs[i]);  //create reg
   
  ts = millis();
}

void loop() {
  mb.task(); // MB comms
 
  if (millis() > ts + 200) { 
    ts = millis();
   
    for(i = 0; i < sizeof(regs)/sizeof(regs[0]); i++)
      mb.Coil(regs[i], digitalRead(pins[i]));  //update reg val
  }
}


Re: Arduino, Mach4 and ModbusIP.
« Reply #11 on: July 17, 2019, 12:14:19 AM »
Hi Tim,

Thank you for sharing your progress on Arduino, Modbus, and Mach4. I am building a relatively gantry-type robot, for robotic welding. To achieve this, I need to define M codes (or any equivalent), to control multiple parameters of the welding machine from within the lines of G code. For instance, to increase arc voltage or wire feed speed, or accessing a memory slot in the welding machine, between lines of G code.

I wonder if you could help me understand how to define M codes to perform Modbus TCP communication. The relevant information from the welding machine manufacturer is here https://resources.userdoc.kemppi.com/manuals/a7-mig-welder-integration-om-en.pdf

At the moment, I understand that it is possible to configure the Modbus TCP protocol on Mach4. I just haven't figured out how to relate this to M codes.

Thank you in advance for any insights you may be able to share with me. Or publicly on the forum, that would be even better I guess.

Cheers

Sergio

Re: Arduino, Mach4 and ModbusIP.
« Reply #12 on: July 17, 2019, 01:41:40 PM »
To Everyone who has read this thread, I no longer work in the CNC field and now only Dabble a little bit with my machine at home. I haven't played with the Modbus stuff for years and so really have not kept up with how Mach4 works with Modbus. I hope that someone else who works in CNC more often can take the thread and help people or link another thread that would be more helpful.

I hope you find what you need somewhere here :)

-Tim
Re: Arduino, Mach4 and ModbusIP.
« Reply #13 on: July 29, 2019, 06:28:57 PM »
Hi Tim,

Thank you for sharing your progress on Arduino, Modbus, and Mach4. I am building a relatively gantry-type robot, for robotic welding. To achieve this, I need to define M codes (or any equivalent), to control multiple parameters of the welding machine from within the lines of G code. For instance, to increase arc voltage or wire feed speed, or accessing a memory slot in the welding machine, between lines of G code.

I wonder if you could help me understand how to define M codes to perform Modbus TCP communication. The relevant information from the welding machine manufacturer is here https://resources.userdoc.kemppi.com/manuals/a7-mig-welder-integration-om-en.pdf

At the moment, I understand that it is possible to configure the Modbus TCP protocol on Mach4. I just haven't figured out how to relate this to M codes.

Thank you in advance for any insights you may be able to share with me. Or publicly on the forum, that would be even better I guess.

Cheers

Sergio

Once you map the Modbus IO in the Mach4 inputs/outputs mapping then you can just use the LUA scripting API to monitor or set the state of the IO. The third post down by ChaoticOne here: https://www.machsupport.com/forum/index.php?topic=27158.0 shows images on how to map the IO.

You can find documentation on the Mach4 LUA scripting located in the installation directory of Mach4 (Docs Folder Mach4CoreAPI.chm).