dpDirectRead()

The function reads values from datapoints directly from the PLC

Synopsis

int dpDirectRead(uint timeout, string dp1, <type1> &var1 [, string dp2, <type2> &var2, ...]);

Parameters

Parameter Meaning
timeout The optional timeout parameter is specified in milliseconds. By default, the timeout is set to 10,000 ms (10 seconds).

Setting the timeout to 0 results in a minimal timeout of approximately 1 second.

If the timeout is reached (e.g.: no response from the PLC), an error is returned - see the section errors below.

dp1 Datapoint configs (attributes) to be read.
var1 The queried datapoint values are written to the variables &var1, &var2 etc.

Return Value

The dpDirectRead() function typically returns 0 to indicate success. If an error occurs, it returns -1.

Errors

Errors of the related (CTRL) manager or errors issued by other mangers (EVENT) can be retrieved with getLastError() (e.g.: error is issued if datapoints or configs do not exists or if the address is not existing in the PLC). All potential errors that can be caught are defined in the message catalog directRead.cat

You can iterate over the dyn_errClass and use the available functions to retrieve further details about the error:

  • getErrorCode(): Returns the error code. This can be interpreted using directRead.cat.
  • getErrorDpName(): Indicates which DPE (datapoint element) caused the error.
  • getErrorManId(): Indicates which manager set the error (e.g., DRV, EVENT, etc.).
  • getErrorText(): Returns the error text. Additional information may be included.
  • getErrorUserData: If it is a protocol-specific error code, it is set here by the driver.

Example: getErrorCode() returns 0004 (Direct write to $DP failed: The read request returned the following error: 12345).

In getErrorUserData(), the exact protocol error code is then set, so the error text does not need to be parsed, e.g.: 12345.

Details

The dpDirectRead() function reads values directly from datapoints in the PLC and assigns them to variables such as var1, var2, etc. Simply use the address config, which defines the connection to the PLC.You can read any number of pairs consisting of a datapoint attribute and its value.
Important:
The _original.._value and _original.._userBits/status64 configs can be read. Attempting to read any other configs will fail and return an error code.

Assignment

Datapoint Functions

Availability

UI, CONTROL