VTSRead

This subroutine is not a part of the VTScada API. You must write it as part of your communications driver.

Description: The VTSRead module is run continuously to read data from the I/O device. It is called from the VTSDriver code.
Returns: Nothing (Data returned via parameters)
Usage: Script Only.
Function Groups:
Related to: DelRead
Format: VTSRead(Trigger, Data, N, MemAddr, BitNumber, Info1, Info2, Info3, DataType[, CallBackObj]);
Parameters:
Trigger
A logical value that, when true, requests that the VTSRead module scan the I/O device for data.
Data

Do not use in new code. Instead, use \CallBackObj\RefreshData()

In legacy applications, this was an array into which the read data is to be placed.

N
The number of values to read from the I/O device. If MemAddr is an array of strings, then N is set to the size of the array.
MemAddr
Assists VTScada in creating more efficient driver read and write calls. PLC I/O locations with different MemAddr values and the same values for the Info1, Info2, and Info3 parameters are coalesced into the same read block, provided they are within VTSMaxBlock, or the return of VTSMaxBlock(Info1, Info2, Info3, DataType) values of each other.
It is the responsibility of the VTSGetAddr module to set this variable to the correct data type and value. Note that the data type of the MemAddr parameter in VTSGetAddr affects the data type of this parameter. If the data type is a string in VTSGetAddr, then this parameter will be an array of strings.
BitNumber
A pointer to the integer bit number within the memory address specified by MemAddr. This value may be set to invalid if there is no bit value.
Info1, Info2, Info3
Are variables (not pointers), that are used by the VTScada code to determine which addresses can be coalesced into a larger read block. These parameters are also passed to the VTSGetAddr and VTSWrite subroutines. Any values that are not required should be set to "0" (i.e. they must be a valid value). These values are typically set to such things as file type or data area. Any differences between the values of the three Info parameters and those of another Address will prevent those addresses from being coalesced (i.e. grouped into the same read request).

Note that Info1 must be a number: a string value will not work. If your code sets Info1 to a string value then the SetData module in VTSDrvr.WEB will not work correctly and client computers will not display the results of the driver server computer's read commands. For example, an analog input that is drawn on the screen will always have invalid contents if the Info parameters are set to strings rather than a number.
DataType
A pointer to a value that holds the data type preferred for the specified address. This data type may be left invalid if the VTSRead and VTSWrite subroutines ignore it. If left invalid the default data type will be 2 (16-bit unsigned integer).
This value will be overridden by the explicit data type specified as an appended string to the address. The DataType is what is passed to the VTSRead and VTSWrite subroutines from VTSGetAddr. The appended data type (refer to the table in the "Address" parameter section above) specifies how the data is to be interpreted after it is read from the I/O device if this is to be different from the DataType returned by VTSGetAddr. The VTSRead and VTSWrite modules do not see the value of the appended data type string.
CallBackObj
Optional, but recommended. An object value whose scope is used to call RefreshData. (see: Data Propagation) RefreshData is the recommended method for propagating data.
If using RefreshData to propagate data, then VTSRead should not also update the Data Array parameter on its own.
VTSRead must return an object (usually Self()) that includes the three mandatory variables: Counts, ErrorCounts and Error.

Comments:

A VTSRead should return data for one or more addresses as contained in the array parameter, MemAddress. Data is returned by calling CallBackObj\RefreshData as described in the topic, Data Propagation. An example is provided at the end of the parameter description.

VTSRead must increment either Counts or Error Counts before processing new data.

Example:

<
VTSRead
(
  Trigger{ Will do read on positive edge           };
  Data{ Array to put the result into               };
  N{ The number of values to read                  };
  MemAddress{ Address to read                      };
  BitNum{ Bit to read / not used here              };
  Info1{ Info1                                     };
  Info2{ Info2                                     };
  Info3{ Info3                                     };
  DType{ Data type used for read                   };
  CallBackObj{ Object value where RefreshData is located };
)
[
  Error        = 0;
  Counts       = 0;
  ErrorCounts  = 0;
  StartTime            { Request start time              };
  ElapsedTime          { Request elapsed time            };
  Tries        = 0     { Number of attempts on modem     };
]
Main [

  If Trigger;
  [
    ResetParm(Self(), 1) { Reset the trigger since does not feed back 
                           from the driver };

      { Process data according to the protocol }
    . . .
 
      { error in data, increment ErrorCounts },
    IfElse((AValid(TimeArray[0], ArraySize(TimeArray, 0) !=  ArraySize(TimeArray, 0)) || 
           (AValid(DataArray[0], ArraySize(ValueArray, 0) !=  ArraySize(ValueArray, 0)), 
      ++ErrorCounts,
    {Else - no errors in data, increment Counts and send data}
      Execute(
        ++Counts,
          { Send data and timestamps }
        CallBackObj\RefreshData(TimeArray,ValueArray,Invalid,Invalid)
      ) {End Execute},
    ) {End IfElse};

    Return(Self);
  ]
]
>