Enabling/disabling
You can enable or disable an ADS-over-MQTT route at runtime without having to restart the TwinCAT system. This allows you, for example, to enable the route only in the case of service and to assign this function to a key switch or link it to user inputs via the HMI.
Enabling/disabling is performed via an ADS interface in the TwinCAT System Service. You can use a special attribute in the route configuration file to define a default status that the route should have after a TwinCAT start.
Route configuration file
In the configuration file of an ADS-over-MQTT route, you can specify a default status that the route should have after a TwinCAT start. This attribute (“Disabled”) is specified at the <Mqtt> node. If assigned the value “true”, the ADS-over-MQTT route is not established automatically after TwinCAT is started and must be established via the ADS interface.
<?xml version="1.0"?>
<TcConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.beckhoff.com/schemas/2015/12/TcConfig">
<RemoteConnections>
<Mqtt Disabled="true">
<Name>MyBroker</Name>
<Address Port="1883">myMessageBrokerAddress</Address>
<Topic>VirtualAmsNetwork1</Topic>
</Mqtt>
</RemoteConnections>
</TcConfig>
ADS interface
The ADS interface is defined as follows.
ADS-Kommando: AdsWriteRequest
ADS-Port: 10000
IndexGroup: 808
IndexOffset: siehe unten
Data: Identifizierung der Route, siehe unten
The IndexOffset indicates whether you want to enable/disable a route permanently or temporarily. In this case, “permanent” means that the enabled/disabled state is retained even after a TwinCAT restart. The following options are available:
IndexOffset | Name | Description |
---|---|---|
1 | ADS_ROUTE_DISABLE | Disables the route permanently. |
2 | ADS_ROUTE_ENABLE | Enables the route permanently. |
3 | ADS_ROUTE_DISABLE_TMP | Disables the route temporarily. |
4 | ADS_ROUTE_ENABLE_TMP | Enables the route temporarily. |
The data area of the AdsWriteRequest specifies which ADS-over-MQTT route is to be addressed. This is done via definition in a string. The format is as follows and corresponds to a composition of the <Address> and <Topic> nodes of the configuration file. The keyword “MQTT” is fixed here.
MQTT:<Address>:<Topic>
Alternatively, you can also add a <name> node to the configuration file, which you can then use for referencing. The name used here must be unique across all ADS routes. In the example above, you would then use the following string in the data area of the AdsWriteRequest:
MQTT:MyBroker
PLC example
A corresponding example is available for download.