Serving up the RealTime() Instruction with a Side of Alias Declarations

von Janet Albers | Aktualisiert: 10/07/2015 | Kommentare: 2

Stichwörter

CRBasic

Blog Themen


Suchen Sie im Blog


Blog abonieren

Erhalten Sie eine Email wenn ein neuer Artikel veröffentlicht wird. Wählen Sie die Themen die Sie interessieren.


Geben Sie Ihre Emailadresse ein:



Artikel vorschlagen

Gibt es ein Thema zu dem Sie mehr erfahren möchten?

Leave this field empty

dinner plate with a serving of RealTime() instruction and Alias declaration

CRBasic has a full menu of instructions to help you write or edit your data logger program. This article offers a main course of scheduling your data logger actions using the RealTime() instruction with a side dish of making your program easier to read with Alias declarations.

The RealTime() Instruction

The RealTime() instruction acquires the year, month, day, hour, minute, second, microsecond, day of week, and day of year from the data logger clock and stores the results in an array. This is useful if you want to schedule the data logger to perform an action at particular intervals or on particular days. For example, you can use the RealTime() instruction to schedule an action every Tuesday or once a month.

In the RealTime() instruction example below, a Boolean variable is set to "True" on the fifth day of every month. You might use this to test an alarm or run a calibration routine.

RealTime() program example

Alias Declarations

In the above example, did you notice the instruction “If rTime(3) = 5 Then state = True”? This instruction would be more readable as "If Day of Month (DOM) is True.”  You can use the Alias declaration to assign the second name of “DOM” to “rTime(3)” like this:  

  • Alias rTime(3) = DOM

Now, in the above example, we can use "If DOM = 5 Then state = True."

Alias declarations are particularly useful when using arrays, such as with the RealTime() instruction, so you can easily identify individual variables using unique names.

Aliased versus non-aliased variables

A Helpful Resource

Did you know that you can copy and paste the Alias declarations for the RealTime() instruction from the RealTime Example in the CRBasic Editor Help? Follow these steps to access this resource:

  1. Highlight RealTime in the instruction list of the CRBasic Editor.
  2. Click the Help button above the instruction list.
  3. In the window that opens, click the Example link, which opens a smaller window with an example program that uses the Alias declarations.

    Alias declaration examples in CRBasic Editor Help

  4. Highlight and copy (Ctrl+C) the applicable Alias declarations, and paste (Ctrl+V) them into your program.

Recommended for You: For more information about variable arrays and Alias declarations, watch the ”CRBasic | Advanced Programming” video.


Hungry for more information about the RealTime() instruction or Alias declarations? Post your comment or question below.


Artikel teilen



Über den Author

janet albers Janet Albers was a Senior Technical Writer. She enjoyed sharing tips, simplifying concepts, and guiding our clients to a successful project. She had been with Campbell Scientific, Inc. longer than the CR1000, but not quite as long as the CR10X. After work hours, Janet enjoyed the outdoors with her boys and dogs.

Alle Artikel von diesem Author anzeigen.


Kommentare

Cristian | 08/24/2017 at 04:03 PM

Hi Janet,

For a propagation chamber, I need to set different conditions for each day (starting a random day). Basically a different set point of humidity for each day*. I have been looking for a "time" intruction to do this but without luck so far.

*example

If DAY=1 then if Humidity <90% then PorSet (1,1)...

If DAY=2 then if Humidity <80% then PorSet (1,1)...

And so on...

Could you please help me with this?

Thanks very much.

Cristian

jra | 08/25/2017 at 02:07 PM

Try the Timer() instruction. Something like: 

Public ElapsedTime, DayOfTest, startflag As Boolean

If startflag = true Then
ElapsedTime = Timer (1,Hr,0) 'start timer
startflag = false
EndIf

ElapsedTime = Timer (1,Hr,4) 'read timer

If ElapsedTime > 0 AND ElapsedTime <= 24 Then DayOfTest = 1
If ElapsedTime > 24 AND ElapsedTime <= 48 Then DayOfTest = 2
If ElapsedTime > 48 AND ElapsedTime <= 72 Then DayOfTest = 3

Please log in or register to comment.