Rockwell Automation 1789-L10_L30_L60 SoftLogix 5800 System User Manual User Manual

Page 134

Advertising
background image

134

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

Chapter 7

Develop External Routines

extern "C" __declspec(dllexport) void SayRungState(EXT_ROUTINE_CONTROL * pERCtrl)
{

pERCtrl->ctrlWord.EN = pERCtrl->ctrlWord.EnableIn;

rungState = INVALID_STATE;

// Only create the thread on prescan.
if (pERCtrl->ctrlWord.ScanType == 1)
{

hControllerState = CreateEvent(NULL, FALSE, TRUE, NULL);
if (hControllerState)
{

HANDLE hThread;

hThread = (HANDLE) _beginthread (RungStateThread,

0,

// stack size

hControllerState);

// arglist

if (hThread != INVALID_HANDLE_VALUE)
{

// The following code will set the thread's priority to the
// same priority as the task that invoked the external routine.
// If the thread is not performing time-critical work, then
// it is recommended that you set its priority to
// THREAD_PRIORITY_IDLE, i.e.
// SetThreadPriority (hThread, THREAD_PRIORITY_IDLE);
SetThreadPriority (hThread,

GetThreadPriority(GetCurrentThread()));

}

}

}
else
{

if (pERCtrl->ctrlWord.FirstScan)
{

rungState = FIRST_SCAN;

}
else if (pERCtrl->ctrlWord.EnableIn)
{

rungState = RUNG_TRUE;

}
else
{

rungState = RUNG_FALSE;

}

SetEvent(hControllerState);

}

return;

}

Advertising