Read

(VTSDriver Library)

Description: Used to create a request for a single read of a given driver address. (This is in contrast to the polled read request of the AddRead function).
Returns: Object value of underlying read module.
Usage: Script Only.
Function Groups: Stream and Socket
Related to:   AddRead
Format: …\Driver\Read(Address, N, PtrDataDest)
Parameters:  
Address
Required. The address of the data to read. Depending on the driver protocol being used, this can be the starting register of the data to be read, a single address string, or an array of address strings.
N
Required. If the PLC supports reading a range of registers, this must be the number of elements to read. If Address is an array, this must be the size of the array. Otherwise this should be set to 1. This must not exceed the driver's VTSMaxBlock value.
PtrDataDest
Required. A pointer to destination for the data. May be a pointer to a variable or the object value of a module that contains a NewData module. If a pointer and N is 1, this will be set to the value that was read. If N > 1, this will be set to an array of values that were read. If an object value, the object's NewData will be called with the value that was read. Will be set to Invalid if the read fails.
Comments:

Allows the reading of a specific address on demand. The resulting data will be sent only to the requesting machine. This will also be the case when the function is run in a client-of-a-client configuration.
The object value of the underlying read module is returned from the function. When the read finishes, the returned object’s value will go to Invalid, signaling the end of read.

This function does not support bit extraction or type conversions. Use BuffRead on the result, followed by BuffWrite to do a type conversion. Depending on how the float was formed by the PLC a call to BuffOrder might be needed to arrange the bytes correctly. To perform bit extraction, use the Bit function on the result of the Read.

Example:

If 1 WaitForReadToEnd;
[
  Obj = ModDrv1\Driver\Read(40001, 5, &Val);
]

WaitForReadToEnd [
  If !Valid(Obj);
  [
    { … process data from read … }
    { When Obj is Invalid, read operation is complete and Val    }
    { will be an array of 5 values.                            }
    { If the read did not succeed, such as in the case of server }
    { failover, Val would be an array of 5 Invalid elements.   }
  ]
]

This example reads from addresses 40001 to 40005 of a Modbus driver tag named ModDrv1 and returns the result as an array in the variable Val.

Bit, BuffRead, BuffWrite, BuffOrder