Programming example: windows event – Rockwell Automation 1789-L10_L30_L60 SoftLogix 5800 System User Manual User Manual

Page 154

Advertising
background image

154

Rockwell Automation Publication 1789-UM002J-EN-P - December 2012

Chapter 8

Program Windows Events to Monitor and Change Controller Execution

Trigger a Controller Task from a Windows Application

In your application, such as Visual Basic or FactoryTalk software, use standard
Windows API functions to open and set the Windows event in the controller.

Make sure you do the following:

Name the Windows-event task in the controller with the same name as the

Windows event in the external application.

Open or create the Windows event in the external application as an

‘automatic reset’ event, otherwise the task within the controller executes
continuously once the Windows event is set.

Use a CreateEvent call to create the Windows event; use a SetEvent call to

signal the Windows event.

Programming Example: Windows Event

This example, a Visual Basic application, uses Windows events to communicate
to a SoftLogix controller. The application passes data via a memory-mapped file
by using the Win32 standard library.

The following example code shows how you can create the public declarations:

Public Declare Function CreateEvent Lib "kernel32" Alias "CreateEventA" _
(lpEventAttributes As Any, ByVal bManualReset As Long, _
ByVal bInitialState As Long, ByVal lpName As String) As Long

Public Declare Function SetEvent Lib "kernel32" (ByVal hEvent As Long) As Long

The following example code shows how you can use the CreateEvent and
SetEvent calls. This example uses the shutdown, program, and run outbound
events (see

page 147

) before executing the Windows event named ‘counter.’

There is a corresponding Windows-event task in the controller named ‘counter.’

Dim hCounter As Long
Dim hOutbound(3) As Long
Dim hCounter As Long

Private Sub Form_Load()
Dim ErrorCodeEvent1 As Long

On Error GoTo noHandle
ErrorCodeEvent1 = 0

Advertising