Modbus master

Here is where you can request new features or special features.

Modbus master

Postby valhallaCNC » Sat Dec 24, 2022 1:54 pm

I use modbus for my VFD via UCCNC and control panel using a pokeys57e I/O card. There is no easy way to monitor the connection state. Could a message box be added for a fault on any connection or even a LED that I could monitor ? , or a GetModbusStatus function. Currently I use a Heartbeat set up. I don't see anything in the manual about this. Did I miss something?
Thanks Joe
valhallaCNC
 
Posts: 65
Joined: Wed Jun 30, 2021 8:04 pm

Re: Modbus master

Postby dezsoe » Thu Dec 29, 2022 8:13 pm

What version do you use? (UCCNC and/or Modbusmaster.dll) The last some versions have functions to get the state of the plugin.
dezsoe
 
Posts: 2079
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Modbus master

Postby valhallaCNC » Fri Dec 30, 2022 12:17 am

Using UCCNNC 1.2113 & Modbusmaster.dll 1.5.0.0
Is this the one I need. Modbus master 1.5.3
- Fixed Informplugin function CheckAllConnections: with disabled connection/function the result was bad. Is there documentation on usage ?
Can modbusmaster 1.5.3 be used with my Version of UCCNC or do I need to upgrade ?

Thanks Joe
valhallaCNC
 
Posts: 65
Joined: Wed Jun 30, 2021 8:04 pm

Re: Modbus master

Postby dezsoe » Fri Dec 30, 2022 11:39 am

Yes, use the 1.5.3 version which is the most up to date version before UCCNC 1.2116. In 1.2116 there will be a new version of the ModbusMaster plugin which will not work on older versions.

Here is a sample macro to test the communication with the plugin:

Code: Select all
string plugin = "Modbusmaster.dll";
string pluginname = "Modbus master";

object Returnvalue;

// test0 - check if plugin is enabled

Returnvalue = exec.Informplugin(plugin, (object)null);

bool isrunning = false;

if (Returnvalue is bool) isrunning = (bool)Returnvalue;
if (!isrunning)
{
  exec.AddStatusmessage(pluginname + " plugin not enabled!");
  return;
}

if (!isConsole)
{
  isConsole = true;
  exec.Pluginshowup("Console.dll");
  Thread.Sleep(100);
}

// test 1 - get full modbus list

Console.WriteLine("");
Console.WriteLine("Returnvalue = exec.Informplugin(\"" + plugin + "\", (object)\"connstat\");");
Console.WriteLine("");

List<string> connstat;

Returnvalue = exec.Informplugin(plugin, (object)"connstat");
if (Returnvalue is List<string>)
{
  connstat = (List<string>)Returnvalue;
  for (int i = 0; i < connstat.Count; i++)
    Console.WriteLine(connstat[i]);
}

// test 2 - get modbus list for connection

Console.WriteLine("");
Console.WriteLine("Returnvalue = exec.Informplugin(\"" + plugin + "\", (object)\"connstat:arduinoip\");");
Console.WriteLine("");

Returnvalue = exec.Informplugin(plugin, (object)"connstat:arduinoip");
if (Returnvalue is List<string>)
{
  connstat = (List<string>)Returnvalue;
  for (int i = 0; i < connstat.Count; i++)
    Console.WriteLine(connstat[i]);
}

// test 2 - extract data from modbus status list

Console.WriteLine("");
Console.WriteLine("Returnvalue = exec.Informplugin(\"" + plugin + "\", (object)\"connstat\");");
Console.WriteLine("");

string[] connparams;

string connName = "";
bool connEnabled = false;
string funcName = "";
bool funcEnabled = false;
bool error = false;
string errorstr = "";

Returnvalue = exec.Informplugin(plugin, (object)"connstat");
if (Returnvalue is List<string>)
{
  connstat = (List<string>)Returnvalue;
  for (int i = 0; i < connstat.Count; i++)
  {
    connparams = connstat[i].Split('|');
    switch (connparams.Length)
    {
      case 5:
        connName = connparams[1];
        connEnabled = Convert.ToBoolean(connparams[2]);
        Console.WriteLine("Connection " + connName + (connEnabled ? " enabled" : " disabled"));
        break;
      case 6:
        if (connEnabled)
        {
          funcName = connparams[2];
          funcEnabled = Convert.ToBoolean(connparams[3]);
          Console.WriteLine("Function " + funcName + (funcEnabled ? " enabled" : " disabled"));
          if (connEnabled && funcEnabled)
          {
            error = (Convert.ToInt32(connparams[4]) != 0);
            errorstr = connparams[5];
            if (error)
              Console.WriteLine("!! Error in " + funcName + ": " + errorstr);
            else
              Console.WriteLine("Result of " + funcName + ": " + errorstr);
          }
        }
        break;
    }
  }
}

// test 3 - check all connections together

Console.WriteLine("");
Console.WriteLine("Returnvalue = exec.Informplugin(\"" + plugin + "\", (object)\"allconnstat\");");
Console.WriteLine("");

DateTime starttime = DateTime.Now;

bool isallok = false;

Returnvalue = exec.Informplugin(plugin, (object)"allconnstat");
if (Returnvalue is bool) isallok = (bool)Returnvalue;
if (isallok)
  Console.WriteLine("All connections are OK");
else
  Console.WriteLine("At least one connection/function has errors");

DateTime endtime = DateTime.Now;

AS3.Setfield((endtime-starttime).TotalMilliseconds, 21000);

#Events

static bool isConsole = false;

There are 2 more options that are not in the test macro: "SetResultRegisters" and "IsRunning". For IsRunning you'll get a bool which is true if the Modbus communication is started. Using the "SetResultRegisters:connectionname,allreg,errreg" you can set 2 counters for a given connection. The allreg and errreg are Modbus register numbers in the Modbus communication array. As you can find out the allreg will contain the counter for all communications for the connection and the errreg the number of failed communications.
dezsoe
 
Posts: 2079
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Modbus master

Postby valhallaCNC » Fri Dec 30, 2022 1:28 pm

Thank you...works great..
valhallaCNC
 
Posts: 65
Joined: Wed Jun 30, 2021 8:04 pm


Return to Feature Request

Who is online

Users browsing this forum: No registered users and 6 guests