Limiting variable size


Recommended Posts

Hey, I'm still reasonably new to Daqfactory and I can't figure out how to limit an array size.

Currently I have internal variables linked to the channel names so the channel names are easier to change as one sequence just needs to be edited and the whole file will continue to work. However the internal variables are holding the past 3600 data points and I only need the most recent one and the rest is a waste of space. Could you please show a script I can run that does this automatically?

The assigning sequence looks something like

while(1)

ChannelName0 = AIN0

...

delay(sampling_rate)

endwhile

where sampling rate is its own variable which dictates the time between readings

 

Link to comment
Share on other sites

I'm unclear why you would do this in the first place.  Channels are designed so that you can name them based on their purpose rather than there physical location and so should remain the same within an application.  What I mean is that you shouldn't name channels things like "AIN0", or "LabJack1_FIO4" or similar, but instead name them "BoilerTemperature", or "InletValve".  Then, the rest of your system is always referencing it by its purpose which doesn't change even if the hardware changes.  If the hardware changes, you just leave the channel name alone and adjust the Device Type, D#, I/O type and channel number (and OPC specifier for some devices).  What you are doing is just adding an extra, unnecessary layer.

As to your original question, use [0] to get just the most recent reading from a channel (or any array really).  See the section on subsetting, 4.6 in the user's guide.

Link to comment
Share on other sites

The reason I've done variable internal names is I'm not certain what is going to be used in the final system so it easier to keep everything as open as possible and refer to it as positions on the board.

Is there a way to limit the size of the internal variable array? For example I can just force it to be a 10 digit array and when the new digit is read its stored in AIN0[0] and AIN0[9] is deleted and everything within the array moves up one position

Link to comment
Share on other sites

OK, well, if you just want to give your channels alternate names, use the aliasFor() function.  So, if you have a channel called "MyChannel" and a variable called "MyVariable" that you want to use to reference MyChannel, just call this once:

MyVariable.AliasFor("MyChannel")

Now, whenever you access MyVariable, DAQFactory will actually go get the data from MyChannel instead of from the variable.  There is no copying of data so you don't have to worry about your memory.  Note that member functions do not work through this, i.e. MyChannel.ClearHistory() will clear the history of MyChannel, but MyVariable.ClearHistory() won't do anything.

AliasFor() was originally designed to allow structured data in classes to be mapped to the rather flat channel structure, especially for OPC which has no functions for reading data from script.  But it works for other stuff too!

But as to your specific question, if you are filling the variable with AddValue, then, yes, there is a history amount.  So, for example:

global x
x.HistoryLength = 3
x.addValue(1)  // x now = 1
x.addValue(2) // x now = {2,1}
x.addValue(3) // x now = {3,2,1}
x.addValue(4) // x now = {4,3,2}

Note that history only applies when using AddValue().  It does not apply when using InsertAt() or Append() until you do another addValue, so continuing on with my example:

x.append(5) // x now = {4,3,2,5}, history length has no effect
x.addValue(6) // x now = {6,4,3}, history length was applied

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share