Programmatically saving the controller – Rockwell Automation 1789-L10_L30_L60 SoftLogix 5800 System User Manual User Manual

Page 156

Advertising
background image

156

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

Chapter 8

Program Windows Events to Monitor and Change Controller Execution

Programmatically Saving the
Controller

From an external routine or application, you can programmatically save the
current controller information (tag data values and configuration information).

A programmatic save can use these pre-defined Windows events. Replace the ‘

xx

with the 2-digit slot number where the controller resides.

Programming Example: Programmatic Save of Controller

The following example codes show how you can use all of the above events to
programmatically save the contents of a controller. This code uses printf
statements to help track progress through the application.

int savenow(int slot)
{
DWORD status;
WCHAR eventname[_MAX_PATH];
SECURITY_ATTRIBUTES sa;
PSECURITY_DESCRIPTOR pSD;

// Create a NULL DACL to allow other tasks to access the external events.
pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
if (pSD == NULL)
return 1;

if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION))
return 1;

// Add a NULL DACL for full permission for all
if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE))
return 1;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = TRUE;

// CreateEvent(security, manuallyReset, initialState, eventName);
swprintf(eventname, sa_kicksave_event_fmt, slot);
h_kicksaveEvent = CreateEvent (&sa, FALSE, FALSE, eventname);
printf("h_kicksaveEvent = %d

swprintf(eventname, sa_savepermitted_event_fmt, slot);
h_savePermittedEvent = CreateEvent (&sa, TRUE, FALSE, eventname);
printf("h_savePermittedEvent = %d

swprintf(eventname, sa_savestart_event_fmt, slot);
h_saveStartEvent = CreateEvent (&sa, TRUE, FALSE, eventname);
printf("h_saveStartEvent = %d

Windows Event

Description

SOFTLOGIX_

xx

_KICKSAVE

This incoming event indicates that a save is to be forced in the controller in slot

xx

.

SOFTLOGIX_

xx

_SAVEPERMITTED

This outbound event indicates that a save is permitted in the controller in slot

xx

.

SOFTLOGIX_

xx

_SAVESTART

This outbound event indicates that a save has started in the controller in slot

xx

.

SOFTLOGIX_

xx

_SAVEDONE

This outbound event indicates that a save has completed in the controller in slot

xx

.

SOFTLOGIX_

xx

_SAVELOCK

This event is a handshake between multiple clients. Use this event to prevent multiple clients from attempting to start
a save at the same time in the controller in slot

xx

.

Advertising