Allen-Bradley
The Allen-Bradley connector communicates with Allen-Bradley programmable logic controllers (PLCs) using the EtherNet/IP protocol. After establishing a connection, the connector automatically discovers all tags at both the controller and program scope. You can then read and write tags individually or in groups, or subscribe to them for real-time updates.
This connector requires instance creation before you can interact with a PLC.
Tags and user-defined types
A tag is a PLC variable that represents a named piece of memory with a specific data type, such as DINT for a 32-bit integer, REAL for a floating-point number, or BOOL for a boolean. A user-defined type (UDT) is a structured tag that groups related values into a single unit, similar to an object. For example, a Recipe UDT can contain the members Name and TempSetPoint, which you address as Recipe.Name and Recipe.TempSetPoint. Reading a UDT returns an object with key-value pairs corresponding to its members.
The connector discovers all tags and their types when you call connect, letting you address every tag by its name.
Connection management
create
Creates a controller instance that represents the connection to a specific PLC. All other functions require this instance.
Parameters
ipAddress
The IP address of the target PLC on the network.
string
options
slot
The slot number of the CPU in the PLC chassis. Default 0.
integer
Example
# ipAddress
192.168.1.10
# options
slot: 2Output
Returns the name of the created instance.
connect
Connects to the PLC and discovers all controller-scoped and program-scoped tags to make them available for reading, writing, and subscribing. See Connection recovery for the behavior after an unexpected session loss.
Parameters
None.
Output
Returns true on a successful connection. Throws an error if the connection or tag discovery fails.
isConnected
Checks the current connection status.
Parameters
None.
Output
Returns true if connected, or false if disconnected.
disconnect
Disconnects from the PLC and clears all subscriptions and cached tag information.
Parameters
None.
Output
Returns true on a successful disconnection, including when no active connection exists. Throws an error if the disconnection fails.
delete
Removes the instance and its connection.
Irreversible action
Deleting an instance removes its configuration. To interact with the PLC again, you must trigger create and connect anew.
Parameters
None.
Output
Returns true upon removal.
Reading and writing
readTag
Reads the current value of a single tag. This function requires an active connection, and the tag must exist in the discovered tag list.
Parameters
tagName
The exact name of the tag to read, such as MotorSpeed or Program:MainProgram.MyData.Status.
string
Example
Output
Returns the raw value of the tag matching its PLC data type (such as 72.5 for a REAL tag). Throws an error if the tag does not exist or the read fails.
readTagGroup
Reads multiple tags in a single, optimized network request. This is more efficient than calling readTag repeatedly. The connector skips tags that do not exist in the discovered tag list and logs a warning.
Parameters
tagNames
An array of tag names to read.
array
Example
Output
Returns an object where each key is a tag name and each value is its current value. Returns an empty object if none of the requested tags exist:
writeTag
Writes a new value to a tag. The function handles both simple tags (numbers, booleans, strings) and UDTs. For a UDT, provide an object where keys map to the member names. Each member must exist as a discovered tag. A type mismatch throws an error.
Parameters
tagName
The name of the tag to target.
string
value
The value to write. Provide a primitive for simple tags or an object for UDTs.
any
Examples
Example 1: Simple tag
Example 2: UDT
Output
Returns true on a successful write. Throws an error if the tag is unknown, a type mismatch occurs, or the write fails.
writeTagGroup
Writes values to multiple tags in a single, optimized network request. The connector skips tags that do not exist in the discovered tag list and logs a warning.
Parameters
tags
An object where each key is a tag name and each value is the value to write.
object
Example
Output
Returns true when all writes complete. Throws an error if the operation fails.
getDiscoveredTags
Returns a list of all tags discovered during the connect phase. Use this for debugging or dynamically exploring a PLC.
Parameters
None.
Output
Returns an array of tag objects containing detailed schema information for each discovered tag:
Subscriptions
subscribe
Subscribes to one or more tags for real-time updates. When a tag value changes on the PLC, the PLC automatically pushes the new value to the platform. Register a listener using onData to handle incoming updates. The connector skips tags that are already subscribed or missing from the discovery list and logs a warning.
Parameters
tagNames
A single tag name or an array of tag names to subscribe to.
string or array
rate
How often the PLC sends updates, measured in milliseconds. Default 500.
integer
Example
Output
Returns nothing. Data arrives through the listener registered with onData. Throws an error if the PLC is not connected.
onData
Registers a callback that fires whenever new data arrives from a subscribed tag. You must subscribe to at least one tag for this listener to receive data.
Parameters
listener
Callback that fires on new data. Delivers an object containing tagName and value.
callback
Example
Output
Returns the string subscribed to confirm listener registration.
onError
Registers a callback that fires when a subscription error occurs, such as a lost PLC connection.
Parameters
listener
Callback that handles the subscription error. Delivers the error object.
callback
Example
Output
Returns the string subscribed to confirm listener registration.
Tips and tricks
Choosing between polling, subscribing, and group operations
Use readTag and writeTag for on-demand, request-response interactions. Use subscribe alongside onData for real-time monitoring and dashboards to let the PLC push changes automatically. When handling multiple tags simultaneously, use readTagGroup and writeTagGroup to bundle requests into a single network packet and reduce network traffic.
Connection recovery
If the PLC session closes unexpectedly, the connector clears all discovered tags and active subscriptions while logging a warning. Call connect again to re-establish the connection and rediscover the tags, then recreate your subscriptions.
Last updated
Was this helpful?