Elmo HARSFEN0602, HARmonica software manual Until iteration, While expression

Models: HARmonica HARSFEN0602

1 220
Download 220 pages 51.63 Kb
Page 39
Image 39

HARSFEN0602ElmoHARmonicaSoftwareManual

PRELIMINARYDRAFT

Syntax:

while( expression )

statement

end

The while keyword executes statement repeatedly until expression becomes 0.

The expression can be logical or/and numerical.

Note: expression may be within round parentheses or without ones.

Example:

OB[1]=0

Digital output 1 is OFF

while(IB[1])

 

OB[1]=1

While the digital input 1 is ON, the digital

 

output 1 is ON

end

 

OB[1]=0;

Digital output 1 is OFF

….

 

 

While (IB[2])

 

end

 

MO=1;

This command will be performed only after

 

digital input 2 is OFF.

37

5.5.4Until iteration

Syntax:

until (expression ) ;

The until keyword suspends the execution of the program until expression becomes true (nonzero). The expression can be logical or/and numerical.

Example:

Assume that user wants to suspend the program until the variable PX exceeds 20000 and digital input 1 is ON.

The code below has the same functionality

until (( PX==2000)&IB[1]) ;

The until expression may be useful to synchronize threads for amplifiers that support multithread programs. For example, we have two threads. Assume that the second thread must start after the first thread finishes some work. We define a global variable, which shows whether the first thread finished or not. The second thread is suspended by until expression.

We first define a variable:

 

int IsFirstFinished ;

**The global variable definition

The variable is initially set to zero.

 

 

The code of the first thread shall be:

 

 

 

 

 

 

Page 39
Image 39
Elmo HARSFEN0602, HARmonica software manual Until iteration, While expression