Using Sketch to trigger watchdog in PLC IDE

Thought this might be useful to others. It appears that all of the mbed class functions do work while using the Sketch feature of the PLC IDE.

I found that when changing the modbus mater parameters like "TimeOut". The master state hangs and needs a reboot. I am not sure if there is a watchdog feature on the PLC IDE side, but the mbed functions seems to work.

To recreate this "feature" you start with a good mb master state:

image

then change the "TimeOut" parameter and download.

image

and the master hangs:

image

Using this sketch you need to create a "Shared Output" variable "nbClientOK" and copy the statues to it on the PLC IDE side:

nbClientOK := sysMbTcpMState.clientOK;

Sketch:

// Enable usage of EtherClass, to set static IP address and other
#include <PortentaEthernet.h>
arduino::EthernetClass eth(&m_netInterface);

#define WATCHDOG_TIME_MS 8000

void setup()
{

    mbed::Watchdog::get_instance().start(WATCHDOG_TIME_MS);
    
	// Configure static IP address
	IPAddress ip(192, 168, 1, 1);
	IPAddress dns(8, 8, 8, 8);
	IPAddress gateway(192, 168, 1, 1);
	IPAddress subnet(255, 255, 255, 0);
	// If cable is not connected this will block the start of PLC with about 60s of timeout!
	eth.begin(ip, dns, gateway, subnet);

}

void loop()
{
    if (PLCOut.nbClientOK)  {
        mbed::Watchdog::get_instance().kick();
    }
    else {
        
    }
    
}
2 Likes