Campbell-scientific CR9000X Measurement and Control System Manual de usuario Pagina 147

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 442
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 146
Section 4. CRBasic – Native Language Programming
4.2.5 Constants
A constant can be declared at the beginning of a program to assign an
alphanumeric name to be used in place of a value so the program can refer to
the name rather than the value itself. Using a constant in place of a value can
make the program easier to read and modify, and more secure against
unintended changes. Constants can be changed while the program is running if
they are declared using the ConstTable/EndConstTable instruction. See
Example 4.2.5-1.
Programming Tip: Using all uppercase for constant names may make them
easier to recognize.
EXAMPLE 4.01. CRBASIC Code: Using the Const Declaration
Public MTempC, PTempF
ConstTable
Const CTOF_MULT = 1.8
Const CTOF_OFFSET = 32
EndConstTable
BeginProg
Scan (1,Sec,0,0)
ModuleTemp (MTempC,1,4,250)
MTempF = MTempC * CTOF_MULTult + CTOF_OFFSET
NextScan
EndProg
4.2.6 Flags
Flags are a useful program control tool. While any variable of any data type
can be used as a flag, using Boolean variables, especially variables named
“Flag”, works best. If the value of the variable is -1 the flag is high. If the value
of the variable is 0 the flag is low (Section 4.6). CSI's logger support software
looks for the variable array with the name Flag when the option to display flag
status is used in one of the real time screens. EXAMPLE 4.0-1 shows an
example using flags to change the word in string variables.
EXAMPLE 4.0-1. CRBASIC Code: Flag Declaration and Use
Public Flag(8) As Boolean
Public FlagReport(2) As String
BeginProg
Scan (1,Sec,0,0)
If Flag(1) = True Then
FlagReport(1) = "High"
Else
FlagReport(1) = "Low"
EndIf
If Flag(2) = True Then
FlagReport(2) = "High"
Else
FlagReport(2) = "Low"
EndIf
NextScan
EndProg
4-19
Vista de pagina 146
1 2 ... 142 143 144 145 146 147 148 149 150 151 152 ... 441 442

Comentarios a estos manuales

Sin comentarios