Reading and logging single datapoints


Recommended Posts

I get data in on an analogue channel. I would like to have a knob that sets the data to zero (i.e. remove offset) as long as the knob is active.

Then I would need (say 10) single datapoints that are collected (and logged/stored/exported)  whenever I push another knob. The datapoints should be shown in a table and finally the mean value of the collected datapoints should be shown.

Has anyone some tips and hints on how to achieve this? I am completely new to DAQFactory (I did read the manual several times but not too successful until now)

Link to comment
Share on other sites

By knob I am assuming you actually mean a button, and that the first button just gives you a zero point, which is used for the following 10 readings.  To do this, you need first to create a sequence marked Auto-Start with a little script to initialize a couple variables:

global zeroPoint = 0
global takeData = 0

After you create this sequence, run it to create these variables.  Since you marked it auto-start, it will run when you load your document.

Next, create a channel to hold this captured data.  I'll call it, say "capData".  You can call it what you want.  Device type "Test", "D to A".

Next, create a button for the zero.  I'm going to assume the analog channel is just called "Input".  For the button, go to the Action tab and select Quick Sequence.  The script is simply:

zeroPoint = input[0]

Next, create another button for the test start.  Again, create a quick sequence.  In this case, assuming you want 10 data points you'd do:

takeData = 10

The first line clears out your last run.  The second tells us we want to capture 10 data points.

Finally, go to the Event tab of the Input channel by clicking on the channel name in the workspace.  Put in script like this:

if (takeData > 0)
   capData.addValue(input[0] - zeroPoint)

The event script runs every time Input gets a new reading.  If takeData is non-zero, it copies the most recent reading, Input[0], over to the capData channel after subtracting out your zero.

That is it.  You can use a logging set to log this capData channel.  Likewise, you can display it in a table or graph or whatever you'd like.  Likewise, you can display the zero point, along with the number of data points left to acquire, as these are just variables.


Link to comment
Share on other sites

Wow, thanks for the fast reply!

The software works fine.

Just one more question about writing to file: I want to log the data to file. Right now I manually set a file name in the DAQFactory Logging page and then start the logging with a button. How can I get the software to ask for the name of the file where to log to before starting the logging?

Link to comment
Share on other sites

Hello Guru,

Thanks again.

When using this script the Windows Explorer screen appears (as expected) where I can fill in the file to save the data to (see first image)

However, the data is not logged to the file I input here. Instead it still keeps on logging to the file that is present in the Logging screen (see second image).

Can you please help me out once again?



Link to comment
Share on other sites

Did you remember the second part where the file selected is assigned to the logging set?  In your case you would have to change my sample code to:

private string filename = file.filesavedialog()
if (!isempty(filename))
   logging.Logging_set_1.strfilename = filename

Link to comment
Share on other sites

Hello Guru,

It works.

I have one new question, hopefully this is the last time I bother you.

The program now works as required, meaning that when I push the button 'Take Sample' only one reading is captured. (this was not so well explained in my first message to you).

At the moment my prototype looks as image 1. The software calculates the mean of 10 data captures using a (probably clumsy) expression as shown in image 2.

This way, I am "stuck" to the number of 10 captured data points.

 I would like to improve this calculation such that the value shown in 'Mean' shows the running average. So if I capture just 1 data point it shows the mean of this 1 data point, if I capture 2 data points I get the mean of 2 data points and so forth.

Is there a 'standard' expression/method for this?

Prototype so far.JPG

mean calculation.JPG

Link to comment
Share on other sites

 Sure, just use mean(CapturedData)

You can do just the last 10 data points with:


instead of the manual way you did it.  Check out section 4.12 in the users guide for a summary of general math functions available, and 4.12.7 specifically for mean().

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.

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.