- 31 Jan 2024
- Print
- PDF
Custom Code Functions
- Updated on 31 Jan 2024
- Print
- PDF
MSGAdd(strMsg)
strMsg(string): Adds the string to the message handler in port IO.
SetMonitor(item, a) This loads a custom monitor.
Item(Integer): The index of the custom monitor.
a(String): Name of the custom monitor.
WriteToOPC(strReadSnapPath, lnReadDSParam, lnWriteDSParam, CycleTimeSec, Optional vWriteVal As Variant)
Used to write values back to the OPC server. This reads the value from another source’s current value file or snap file based on its dsparam1.
strReadSnapPath(String): The path to a valid snap file.
lnReadDSParam(Long): The DS Parameter for the tag to read from the snap file defined in strReadSnapPath.
lnWriteDSParam(Long): The DS Parameter for the tag to write to in the local PortIO.
CycleTimeSec(Long): How often to read and write to OPC in seconds.
vWriteVal(Variant): A returned variable that is the value that was written to the OPC.
WriteValToOPC(vWriteVal, lnWriteDSParam, CycleTimeSec)
Writes a value to an OPC tag within the PortIO based on that tag’s dsparam1 ID.
vWriteVal(Variant): Value to write to PortIO.
lnWriteDSParam(Long): The DS Parameter of the tag to write to the OPC.
CycleTimeSec(Long): How often to write the value to the OPC.
GetSnapValue(strSnapPath, lnDSParam)
Gets the value for a tag from a PortIO’s current value or snap file based on its dsparam1 ID number.
strSnapPath(String): The file path to a valid snap file.
lnDsParam(Long): The DS Parameter of the tag to read from the snap file.
SetBadTagLimit(lnBadTagLimit, lnReTestNum, lnWaitTimeSec)
Sets the PortIO’s bad tag limit, which can also be set from the PortIO configuration screen.
lnBadTAgLimit(Long): The limit on how many bad tags are allowed.
lnReTestNum(Long): How many times the tags will be checked before PortIO stops trying to find them.
lnWaittimeSec(Long): How many seconds PortIO will wait between reconnect attempts.
SetWatchDogTag(lnDSParam1, lnChangeRate, lnReConTimeSec)
lnDSParam1(Long): The DS parameter of the tag that should be watched.
lnChangeRate(Long): Time in seconds that the tag should change value before a reconnect is called.
lnReConTimeSec(Long): Time in seconds to wait before reconnects.
ReInitialize(blnReInitPortIO)
blnreInitPortIO(Boolean): Set to True to cause a reinitialize, or False to cause nothing to happen.
OPC_UseLoopNumAsNames(blnUseLoopNum)
blnUseLoopNum(Boolean): Set to True to use loopnum or False to use sname for OPC Tag names.
SetOPCGroupSize(lngGroupSize)
lngGroupSize(Long): Sets the maximum group size.
InputProfileTag(dsparam1, varArrayData, TimeStamp)
Dsparam1(Long): The DS parameter of the tag that is to be filled.
varArrayData(Variant): An array of data to be written.
timestamp(Date): Time Stamp.
OPCTagsInitialized() As Boolean
Returns a true/false value to indicate if the OPC tags have been initialized.
OPC_Dissconnect(iPort,WaitTime)
iPort (Long): If reading from more than one OPC, this is the ID number of the one to disconnect from.
WaitTime (long): The amount of time to wait until re-connecting in seconds. If configured with fail-over OPC, this would toggle to the next OPC in the list.
CreateObjectRemote(ClassName As String, ServerName As String) As Object
Returns an object that is the created from the two strings. It calls this function:
Set CreateObjectRemote = CreateObject(ClassName, ServerName)
WriteVal(DSParam As Variant, blnWriteVal As Boolean)
Set a Boolean indicating whether or not the PortIO should write out the indicated tag’s value. If set to False, it will not write that tag’s value to history until set to True again.
Data2File
This will force the PortIO to call the routines that write out the history and snap files. Use this way: “Call Data2File”.
GetOPCTagList(vOPCTagList As Variant)
Returns, in a variant array, the list of the OPC tag names, indexed by dsparam1.
GetVarValues(vVarValList() As Variant)
Returns all the tag’s values, whether singles, text and/or arrays in one array of variants. gValues only returns values that are singles.
DBConnectionString as string
Function call that will return the database connection string to connect to the dataPARC database the PortIO is connected to.
GetDsparam2Array as variant
Returns the complete array of dsparam2 values for all the tags configured in the PortIO. dsparam2 is a field in the database for tags and can be set in the Tag Editor in Excel.
GetDsparam3Array as variant
Returns the complete array of dsparam3 values for all the tags configured in the PortIO. dsparam3 is a field in the database for tags and can be set in the Tag Editor in Excel.
GetTagDefArray as variant
Returns the complete array of TagDef values for all the tags configured in the PortIO. TagDef is a field in the database for tags and can be set in the Tag Editor in Excel.
GetProfileData(dsparam1 As Long, vValues As Variant, TimeStamp As Date)
Subroutine that will retrun the values array and timestamp for any profile tags. Takes in the dsparam1 of the profile tag and returns an array of values and a timestamp.
GetSourceName as string
Function that returns the name of the source the PortIO is configured for.
GetTagType(dsparam1 As Long) As String
Function that returns the tag type for a tag given the dsparam1.
GetValFromSQL(strSQL As String) As Variant
Returns the first value for a SQL string from the PARCview configuration database. If a valid SQL query is built and entered to this function, it will return the first values in the first record returned from the query.
IsPrimaryPC() As Boolean
Function that returns a Boolean if the PortIO is running on the PrimaryPC in a redundant PC mode.
IsRedundantInPrimaryMode() As Boolean
Function that returns a Boolean if a PortIO is the redundant PortIO in a redundant setup but is now running as the primary since the Primary PortIO is offline.
SendData(iPort As Integer, datastring As String)
For Serial and Socket PortIO, sends data as a data string to the serial or socket that PortIO is connected too. The iPort is the index number of the socket or serial connection.
ShutDownPortIO(blnShutDown As Boolean)
Subroutine that can be called from custom code to shut down the PortIO after the current cycle is completed. Normally, FireDaemon would restart the PortIO.
UpdateHeartBeat()
Subroutine that can be called to update the heartbeat timestamp.
TagIndex(sName as string) as long
Function that given the name of a tag will return its index number or dsparam1.
GetTagValue(Index as long,varValue as variant,sngValue as single,dtTime as date,Quality as byte) as Boolean
Function, given an Index for a tag, will return all the tag’s values. Returns a Boolean of True if tag is found, False if not found.
PutTagValue(Index as long,varValue as variant,sngValue as single,dtTime as date,Quality as byte) as Boolean
This will assign all the input variables values to a tag in the PortIOs arrays. This value(s) will then be written to history following the same rules as any other PortIO tag.
An example of how the last three functions would be used in the PostOPCData code is shown below:
Sub PostOPCData()
Dim l_Boolean AsLong, l_Dig2 AsLong
Dim varB AsVariant, dtB AsDate, QualityB AsByte, sngValueB AsSingle
Dim varD AsVariant, dtD AsDate, QualityD AsByte, sngValueD AsSingle
Dim b AsBoolean
'Get the index of the tag whose sname is "Boolean"
l_Boolean = TagIndex("Boolean")
If l_Boolean > 0 Then
b = GetTagValue(l_Boolean, varB, sngValueB, dtB, QualityB)
If b Then
l_Dig2 = TagIndex("Dig2")
If l_Dig2 > 0 Then
b = GetTagValue(l_Dig2, varD, sngValueD, dtD, QualityD)
If dtB > dtD Then'The timestamp of the Boolean is later than of Dig2
IfCBool(varB) Then
varD = "Green"
Else
varD = "Red"
EndIf
b = PutTagValue(l_Dig2, varD, sngValueD, dtB, QualityB)
EndIf
EndIf
EndIf
EndIf
EndSub