Easy-to-use Unofficial LabVIEW TwinCAT Toolkit for communicating with Beckhoff PLCs via ADS. Features include invoking RPC methods, reading/writing PLC variables (including all standard types, pointers, references, time, strings, wide strings, structs composed of the aforementioned, nested structs, and multi-dimensional arrays of the aforementioned datatypes), introspective capabilities (retrieve symbol and type information), the ability to build your own low-level VIs via extensions, and more.
Read PLC Type.vi
Read Multiple.vi
and Write Multiple.vi
REFERENCE TO
types greater than 4 or 8 bytes (depending on the bitness of the machine).VIs included in the API:
You may notice that the Connect.vi
is slow in connection. This is normal.
The VI is simply caching the symbols and types in LabVIEW rather than keeping them in a .NET collection. The reason for this is that lookup times on the .NET Ads-XYZ-Collection are very slow. The further I moved away from making calls to any of Beckhoff's .NET libraries the faster operations became. The penalty for doing this is a slow connection.
Because of the caching system, online changes are currently not supported.
You do not need to disconnect before disposal. Dispose.vi
VI will disconnect for you.
Operations involving UNION
s and INTERFACE
types are not yet supported.
To read and write to pointers simply add the dereferencing symbol to your symbol name e.g. pValue^
.
First calls to an operation (Reading/Writing a symbol or Invoking a Method) will be slow.
Typical first call times for my RYZEN 3600X system with 1 isolated core are ~5ms for ARRAY[0..999] OF LREAL
and ~40ms for ARRAY[0..999] OF ST_STRUCT
where ST_STRUCT
is:
TYPE ST_STRUCT :
STRUCT
bVar : BOOL;
dtVar : DT;
fVar : LREAL;
END_STRUCT
END_TYPE
Subsequent calls resulted in read/write/method invoking times of 1-2ms for ARRAY[0..999] OF LREAL
and ~20ms for ARRAY[0..999] OF ST_STRUCT
. The task cycle time was 1ms.
When sending numbers, arrays of numbers or structs with numbers, enums, etc. The numbers will be coerced to the type defined in the PLC for that variable/parameter. This is by design. LabVIEW is a graphical language so switching between Single Precision Float and Doubles is an absolute pain.
LabVIEW Arrays don't need to be the same size as the PLC arrays to write them. Write what you need, the rest will be filled in with defaults.
Online change is not supported. However, you can update variables on the PLC without needing to disconnect on the LabVIEW side via Login with Download
, Restart TwinCAT System
and Activate TwinCAT Configuration
. All symbols will automatically be reloaded into memory.
NOTE: Any reads or writes running during this process will produce errors, just ignore these errors until reconnection is complete. They will stop once that happens.
Don't forget to close the Registration Refnum after you're done. User Events references are automatically closed on disposal.
JKI's Caraya Unit Test Framework is used for unit testing.
To run unit tests simply activate the PLC project located at src/Test-PLC, open the LabVIEW project and then run the Run Tests
VI in the Tests virtual folder.
Please feel free to contribute to the project or report bugs