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.