Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 6 Channels and Conversions

6.9 Channel Functions and Variables

Scroll Prev Top Next More

Functions:

Channels offer four different functions.  These function are accessed by following the channel name with a period, then the function:

MyChannel.ClearHistory()

These functions can be used anywhere sequence code is used: sequences, events, etc.

Here are the four functions:

AddValue(Value):  

Calling this function manually adds a value to the history of the channel. Value can be a scalar value or an array of values.  If Value has time associated with it, the time of each row is inserted as well.  If Value does not have time associated with it, the current time is inserted before the data is added to the channel.  For array data with multiple rows, all rows are assigned the same time.  Use the InsertTime() function on value if you want to insert a different time.

Application: The AddValue() function is typically used in sequences that acquire data using unusual methods.  For example, many of the serial devices have device functions which will read a batch of points across multiple channels with a single call.  Once the data is acquired, you can use the AddValue() function to add the data to the appropriate channels.  For example:

 

// read three consecutive tags from a Modbus device:

Private In = Device.MyModbus.ReadHoldingFloat(1,600,3)

// ReadHoldingFloat returns a 2 dimensional array, but with 1 row, 3 columns.

 

// now add the three values to three different channels:

CoreTemperature.AddValue(In[0][0])

WaterTemperature.AddValue(In[0][1])

WaterPressure.AddValue(In[0][2])

AddValue() does not convert the value from the channel's conversion.  It will, however, cause the data point to be logged to any logging sets, broadcast to any remote systems, and alarms to be calculated.

ClearHistory([# of points to leave]):  

Calling this function will clear the channels history of all values except for the number of points specified in the function.  Leaving this parameter blank clears all the points in the history, which is the same as ClearHistory(0).  After clearing, the history will rebuild itself as new data arrives.

MyChannel.ClearHistory(5) clears all but the last five data points.

MyChannel.ClearHistory() clears the entire history.

Application: The most common application of the ClearHistory() function is when creating X-Y graphs.  Since graphs utilize the entire history unless specified otherwise, the X-Y graph may display undesired points.  For example, if you are running batch experiments and need a new X-Y graph with each batch, you could clear the history of the channels used in your graph at the beginning of each batch.

GetHistoryLength():

Returns the number of historical data points in the channel, essentially the number of rows.  This function differs from NumRows() in two ways: NumRows() works on channels, variables and any other array, but for channels will return the number of historical data points, but only up to the channel's history length. GetHistoryLength() only works with channels, but will return the length including any persisted data as well and is much more efficient then using NumRows(MyChannel[0,1e7]) which will achieve the same thing but require the entire MyChannel persisted history to be loaded into memory.  Bottom line: use GetHistoryLength() to retrieve the number of data points in a channel, and NumRows() for all other arrays.

Time:  

This is not quite a function, but allows you to request the Time associated with the channel instead of the data.  This is the same as GetTime(), but offers more when used with variables (as explained in the section on variables under Sequences & Scripting):

MyChannel.Time returns the time of all data points in the history of MyChannel (the same as GetTime(MyChannel))

MyChannel.Time[0] returns the time of the most recent data point in MyChannel (the same as GetTime(MyChannel[0]))

Variables:

All the properties of a channel except the channel name are editable from script with the following variables.  To edit the channel name you must delete the channel and recreate it.  Changes to some of the properties, namely device, device number, i/o type, channel, strSpecifier, timing and offset, will not take effect until you call the Channel.Restart() function.   This function, described in the next section, stops the acquisition and restarts it with the new parameters.  The values may appear to be changed, but the changes do not affect acquisition until the Restart() call.

Like the functions above, all these variables are preceded with the channel name and a period.

strDevice: this is the name of the device as a string.  If you change this value, make sure and change the IOType as well.  Although two different devices may have the same IOType string name like "A to D", internally they may be coded differently.

DeviceNumber

strIOType: the I/O type name as a string.

Channel

Timing

Offset

HistoryLength

PersistAmount: remember that changing this value will clear the persistence file of any existing data.

ModbusRegister

HistoryInterval

strConversion: this should be set to "None" when no conversion is desired.

Broadcast: 0 or 1

BroadcastInterval

Average: this is 0 if averaging is off, or the number of data points to average.

strSpecifer: this is the quick note / special / opc column often used by the device.

strQuickNote2: another space to store some info about a channel.  This is typically this is one liner information.

strNote: yet another space for random info about a channel. This is typically more in depth info about the channel.

strGroup: the group the channel belongs.  Note that channel groups are created on the fly, so you simply assign a channel a new group name to create a new group.  Changes to strGroup may not update in the workspace as dynamic, scripted changes to strGroup are typically used in fully scripted apps in conjunction with the Channel.ListAll() function described in the next section.

strEvent: the sequence script that gets executed when the channel receives a new data point.