# $ Functions: Devices - TwinCAT

Note: The following $ Functions are available only if the TwinCAT plugin is installed. See the Optional Communications Plugins topic for more information.

Cognex Designer publishes the following $ functions for TwinCAT connections, allowing you to read, write or refresh TwinCAT PLC variables synchronously. These functions are executed directly by the TwinCAT client device.

    $Devices.TwinCATDevice.ReadMulti(paths : String[]) : Object[]
Arguments | paths: An array of strings, specifying the PLC variable path(s) where the read operation(s) will be performed. Tip: This argument also supports paths that correspond to array variables on a TwinCAT device.
Returns | An array of objects containing the values read on the PLC that correspond to the paths argument.
Description | Reads the PLC variables specified with the paths argument.

    $Devices.TwinCATDevice.RefreshVariableTable()
Arguments | N/A
Returns | N/A
Description | Unsubscribes the tags connected to the device, then refreshes the TwinCAT symbol loader before re-subscribing the same tags.

    $Devices.TwinCATDevice.WriteMulti(paths : String[], values : Object[])
Arguments | paths: An array of strings, specifying the PLC variable path(s) where the write operation(s) will be performed. Tip: This argument also supports paths that correspond to array variables on a TwinCAT device. values: An array of objects, specifying the value(s) to write during the operation.
Returns | N/A
Description | Writes the data specified with the values argument to the PLC variable(s) specified with the paths argument. Note: This function also supports updating an array of variables on the PLC.

Note:

When deciding on whether to use tags or $ functions to modify PLC variables, consider the following:

- When using tags to read/write PLC variables, the read/write operations are performed asynchronously in Cognex Designer, in line with the Update Rate property of the tags (this property is available in the Properties window after selecting the tag in the Tag Manager once its Selected Path cell is properly configured). This means that read/write requests are queued in a background thread, and are performed only when a thread becomes available. If you want to perform multiple PLC variable read/write operations synchronously while a Task is running, use the available TwinCAT $ functions instead of tags.
- When using tags, you can read/write one PLC variable at a time (the one that is bound to the selected tag). On the other hand, the published TwinCAT $ functions allow you to read/write multiple PLC variables simultaneously as well, as they also support reading/writing an array of PLC variables.
- Both the ReadMulti and WriteMulti $ functions use the TwinCAT ADS-sum command to read/write several variables with a single command.
- Using an array tag that has a configured Selected Path to the corresponding PLC array variable will not update that variable on the PLC, and will result in an error in the Output window. Such PLC array variable updates are only supported by the WriteMulti $ function.