ReportEvent

ITcEventLog

This method is used to issue an event from a COM client like the HMI program to the TcEventLogger.

HRESULT ReportEvent([in] SAFEARRAY(VARIANT)* eventHead,
                    [in] SAFEARRAY(VARIANT)* eventData)
);

Parameters

eventHead

[in] Pointer to a safearray with the bounds 0 to 9 that represents the event header. The array represents the same information as TcEventHeader. The items of the array are explained in the following table

index

TcEventHeader item

DataType

Description

0

nClass

TcEventClass

The class of the event, like alarm, warning, hint

1

nPriority

TcEventPriority (long)

The event priority. Since now the priority is always: TcEventPriority.TCEVENTPRIO_IMPLICIT=0

2

dwFlags

TcEventFlags (long)

The flags control the behavior of the alarm. That could be combined by an OR junction.

3

dwUserData

long

A spare variable that can be used by the user.

4

nId

long

The event id, that unique represents this type of event for this one Event Source.

5

nInvokeId

long

 

6

fDate

VARIANT-DATE

The date and time when this event occur

7

nMs

long

The millisecond part of the event date

8

varSource

variant

The source id source name. The event source is used to distinguish different device. Like I/O Event, or different parts of the PLC program.

9

szFmtProgId

BSTR string

The PrgId of the formatter. If we want to use the standard XML formatter the string should be set to "TcEventFormatter.TcXmlFormatter"

 

eventData

[in] A pointer to a safe array that represents the event arguments. In the configuration of the event formatter, it's defined how to place the event arguments into the displayed event message. The following data types are supported by the standard formatter. int (16bit), long (32bit), float(32bit), double(64bit), string(BSTR)

Return Values

S_OK

Function was successfully called

TCEVENTERR_ISSIGNALED

The event with this source id and event id was already signaled.

Visual Basic sample code

' get the one and only event logger
Dim evtLogger As TCEVENTLOGGERLib.TcEventLog
Set evtLogger = New TCEVENTLOGGERLib.TcEventLog

' create event header
Dim arrHeader(0 To 9) As Variant

arrHeader(0) = TcEventClass.TCEVENTCLASS_ALARM ' event class
arrHeader(1) = TcEventPriority.TCEVENTPRIO_IMPLICIT ' event priority
arrHeader(2) = TcEventFlags.TCEVENTFLAG_LOG ' event flags
arrHeader(3) = 0 'user data
arrHeader(4) = 1 ' event id
arrHeader(5) = 0 'invoke id
arrHeader(6) = Now ' event date and time
arrHeader(7) = 123 ' millisecond part of the event date and time
arrHeader(8) = 1 ' event soruce id
arrHeader(9) = "TcEventFormatter.TcXmlFormatter" ' XML formatter ProgId

' create event parameters
Dim arrParam(0 To 1) As Variant
arrParam(0) = 1234 ' first parameter as long
arrParam(1) = 1234.777 ' second parameter as double

' log the event
Call evtLogger.ReportEvent(arrHeader, arrParam)

Remarks

After this method call the Event Logger will raise the event OnNewEvent on all client that implements the event interface _ITcEventLogEvents (VB: Dim WithEvents).

For C++ and Visual Basic programmers it's more convenient to use the method ITcEventLogC::ReportEvent or ITcEventC3::ReportEventEx.