beautypg.com

C programming examples, C programming examples -18 – Sensaphone SCADA 3000 Users manual User Manual

Page 204

background image

16-18

SCADA 3000 User’s Manual

Listed below is the same program written using a ‘straight through’ approach. Only IF state-

ments:

main ()

{

if (read_uaf(input,0,1)==0)

{

write_uaf(output,0,3,on);

}

if ((read_uaf(input,0,1)==1)

{

write_uaf(output,0,3,off);

}

}

In this case, when input 1 closes, output 3 will be turned on and then continue with the rest of

the program. If input 1 opens, output 3 will be turned off. This program cannot get held up in

a WHILE loop. Please note that these examples are greatly simplified for this discussion and

are only intended to demonstrate the dangers that are possible when using WHILE loops.

C Programming examples

Example #1 Checking for alarms
The following lines of code will check to see if Alarm 9 exists.

If (read_uaf(alarm,9,0) != 0)

{

/* an alarm exists on alarm channel 9 */

}

else

{

/* no alarm on channel 9 */

}


Example #2 Checking for low-level alarms
The following lines of code will check to see if a low-level alarm exists on Alarm channel 9.

If (read_uaf(alarm,9,0) == 2)

{

/* a low-level alarm exists on alarm channel 9 */

}

else

{

/* no low-level alarm on channel 9 */

}

Example #3 Checking for high-level alarms
The following lines of code will check to see if a high-level alarm exists on Alarm channel 9.

If (read_uaf(alarm,9,0) == 3)

{

/* a high-level alarm exists on alarm channel 9 */

}

else

{

/* no high-level alarm on channel 9 */

}