VTSWrite
This subroutine is not a part of the VTScada API. You must write it as part of your communications driver.
The VTSWrite module is launched by the VTSDriver code to write a block of values to the I/O device. Its code is very similar to that of the VTSRead module with the same number of parameters.
Format:
Trigger |
A logical value that, when true, will request that the VTSWrite module send the data to the I/O device. |
Data |
An array where the written data will be read. |
N |
The number of values to write to the I/O device. If MemAddr is an array of strings, then N indicates 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 write block, provided that 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. The data type of the MemAddr parameter in VTSGetAddr affects the data type of this MemAddr parameter. If the DataType 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 VTSRead 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, 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. |
Comments
The VTSWrite module will usually be slain immediately after the write is completed.
VTSWrite must increment one of two mandatory internal variables each time it is called. Either "Counts" if the write was successful or "ErrorCounts" otherwise.
Example
The code for VTSWrite might look like:
< VTSWrite ( TriggerParm{ Will do read on positive edge }; Array{ Array to put the result into }; N{ The number of values to read }; MemAddress{ Address to read }; BitNum{ Bit to read }; Info1{ Info1 - not used }; Info2{ Info2 - not used }; Info3{ Info3 - not used }; DataType{ Data type used for read - uses standard types }; ) [ { Trigger is PUBLIC and is referenced by VTSDriver } Trigger= 1{ TRUE when initial trigger set }; Error = 0; Counts = 0; ErrorCounts = 0; StartTime { Request start time }; ElapsedTime { Request elapsed time }; Tries = 0 { Number of attempts on modem }; WriteActive = 0 { TRUE when the write has been triggered }; ] Main [ If Trigger || TriggerParm; [ { Process the data according to the protocol } . . . { Reset the triggers } ResetParm(Self(), 1); Trigger = 0; ] ] >