Custom Code
  • 31 Jan 2024
  • PDF

Custom Code

  • PDF

Article summary

The PortIO can run custom Visual Basic code to help it parse strings read from files, serial ports or sockets, write back to the OPCDA server and any other manipulation possible from standard VB code. It is also where the user configures the parameters for socket, serial and file read for PortIO. To view the custom code for a PortIO, click Edit and choose Custom Code. The default code look like this:

All custom code sets require these four sub routines: Init, Service2, Cycle and PostOPCData.

Init: Called once at the startup of the PortIO and is normally used to initializes a number of parameters.

gPortType: String representing the PortIO type, for example, ‘File’, ‘OPC’, ‘Socket’ or ‘Serial’.

gNumValues: Obsolete. The number of tags configured for the PortIO.

gSnapFlag: Obsolete. Flag to determine if a snap file is written out.

gHistoryTimeFlag: Obsolete. Flag to write out local history file.

gHistoryTagFlag: Obsolete. Flag to write local tag history file.

Service2: Called each time a new data string comes in from the file, socket or serial port.

iPort: The configuration number set up in the PortSetup call or if an OPC PortIO, the number of the OPCDA server configure, if more than one is being accessed or read from.

gPortType: A string indicating the PortIO type, for example , ‘File’, ‘OPC’, ‘Socket’ or ‘Serial’.

gDataString: String read from file, socket or serial port, as one continuous string.

gValues: These are the PortIO’s tag’s values, in order by dsparam1. dsparam1 is the unique ID number of a tag within a source and is found in the ctc_tag table of the configuration database.

gStatus: A way to send a status back that read or parse failed.

Dates: The PortIO’s tag’s timestamps, in order by dsparam1. dsparam1 is the unique ID number of a tag within a source and is found in the ctc_tag table of the configuration database.

gQuality: The PortIO’s tag’s qualities, in order by dsparam1. dsparam1 is the unique ID number of a tag within a source and is found in the ctc_tag table of the configuration database.

qAlarm: The PortIO’s tag’s alarm state, in order by dsparam. dsparam1 is the unique ID number of a tag within a source and is found in the ctc_tag table of the configuration database.

Cycle: Called once a cycle, every second or faster.

gPortType: String containing the PortIO type.

gValues(): Array of the values for the tags, indexed by dsparam1. dsparam1 is the unique ID number of a tag within a source and is found in the ctc_tag table of the configuration database.

Quality(): Array of the qualities for the tags, indexed by dsparam1. dsparam1 is the unique ID number of a tag within a source and is found in the ctc_tag table of the configuration database.

Alarms(): Array of the alarm state for the tags, indexed by dsparam1. dsparam1 is the unique ID number of a tag within a source and is found in the ctc_tag table of the configuration database.

ArrayValues(): Obsolte. An array of variants to be used if assigning arrays to values.

Dates(): Array of the timestamps for the tags, indexed by dsparam1. dsparam1 is the unique ID number of a tag within a source and is found in the ctc_tag table of the configuration database.

gLastValues(): Array of the previous values written out by the PortIO for each tag, indexed by dsparam1. dsparam1 is the unique ID number of a tag within a source and is found in the ctc_tag table of the configuration database.

PostOPCData: Called each time an update is received from the OPCDA server and before the PortIO writes out an exception file to PARCHistory. Allows the custom code to do some manipulation of OPC data before written to history.


Was this article helpful?