DAQ question from a complete novice

Hello everyone,

I've been using Igor Pro now for a few months for DAQ but only using the built in panels in NIDAQ tools mx. I bit the bullet last week and decided I needed to start programming (holy cow, this is tricky!). I'm a complete novice to programming full stop, so I've bought myself a few C books to learn at home in the evenings. I'm using my hardware/software to conduct measurements on dye solar cells and have written a few very simple functions to turn lights on and off, flash LED pulses etc using the DAQmx_CTR_OutputPulse function to control a switching transistor (I'm new to electronics too! phew!)

The first simple programme (or so I thought) I wanted write was is to do a "photovoltage decay experiment". Very simply, I illuminate my solar cell for 15s whilst measuring the OCP with DAQ analogue input. After 15s the light goes off and you measure the voltage dropping to zero (this can be up to a minute in some devices).

This is what I have so far:

To turn the light on for 15s and then off I have this:

Function RunPVDecay()
String DeviceName = StringFromList(0, fDAQmx_DeviceNames())
DAQmx_CTR_OutputPulse /DEV=DeviceName /DELY=0 /FREQ = {1000, 0.5} /IDLE=0 /NPLS=15000 /RATE=-1 /STRT=1 /OUT=("PFI1") 1;
End

and that works fine.

I've also managed to write a few lines to capture the analogue input and covert it into a wave.

Function GetVOC()

String DeviceName = StringFromList(0, fDAQmx_DeviceNames())

Wave VOC
DAQmx_CTR_OutputPulse /DEV=DeviceName /DELY=0 /FREQ = {1000, 0.5} /IDLE=0 /NPLS=15000 /RATE=-1 /STRT=1 /OUT=("PFI1") 1;
VOC=fDAQmx_ReadChan (DeviceName, 4, -1, 1,0)
Display VOC
modifygraph live=1
setaxis left -0.8, 0
End

This also works ok but what I really want to do (and here is my question finally!) is when the user pushes the button to run the function on the panel that I have built, I want a prompt to come up asking for the wave name, I want that wave to be saved in a certain folder and to be returned immediately to a graph and then all further waves to be appended to the same graph.

I feel a bit cheeky asking for help and maybe I should go away and learn to code properly first! But if anybody out there does want to help, I would be extremely grateful.

Many many thanks,

Matt

Hi Matt,

learning programming can be a daunting task at first, but it will reward you well whatever field you're in. Good luck on your journey!

Matt Carnie wrote:

when the user pushes the button to run the function on the panel that I have built, I want a prompt to come up asking for the wave name, I want that wave to be saved in a certain folder and to be returned immediately to a graph and then all further waves to be appended to the same graph.


I have a function that does something similar to what you want. Basically, you provide it with a data folder the wave will be created in (can be any valid DFREF), and it will ask the user to specify an output name. Then it will check whether the name is valid and unique, and will keep prompting the user until both are satisfied. If the user cancels, the function will return an empty string, otherwise it will return the desired wave name. Here is the function:

Function /S GetNewOutputWaveName(suggestedName, outputDataFolder, promptString)
    // prompt the user for a wave name in dataFolder
    // check that the name is a valid wave name and return it
    // if the user canceled then return an empty string

    string suggestedName        // suggested wave name to start from (can be empty string)
    DFREF outputDataFolder      // data folder the wave will be saved in - used to check if the name is unique
    string promptString         // string displayed in the prompt so the user knows what the name is used for
   
    string outputWaveName = suggestedName
    variable outputWaveFound = 0
   
    do
        Prompt outputWaveName, "Wave name:"
        DoPrompt promptString, outputWaveName
        if (V_flag == 1)    // the user canceled
            return ""
        endif
       
        // check if the name is not a blank string
        if (strlen(outputWaveName) == 0)
            continue
        endif
       
        // check if the name is acceptable to Igor
        // do not allow liberal names
        if (stringmatch(outputWaveName, CleanupName(outputWaveName, 0)) != 1)
            outputWaveName = CleanupName(outputWaveName, 0)
            continue
        endif
       
        // check if the wave already exists
        wave /Z outputWave = outputDataFolder:$outputWaveName
        if (WaveExists(outputWave) == 1)
            // the requested wave already exists
            // offer the user to overwrite it (replace all of this with a simple 'continue' if you do not want this to happen)
            DoAlert 2, "A wave called \"" + outputWaveName + "\" already exists! Do you want to replace it with the new wave?"
            switch (V_flag)
                case 1: // OK to replace
                        // we're all set
                    outputWaveFound = 1
                    break
                case 2: // Don't replace, use a different name instead
                    outputWaveName = UniqueName(outputWaveName, 1, 0)
                    continue
                    break
                case 3: // user cancelled, escape
                    return ""
                    break
                default:    // shouldn't happen
                    Abort "Unknown value for V_flag in DoAlert"
                    break
            endswitch
        endif
       
        // if we arrive here then the waveName looks okay
        outputWaveFound = 1
    while (outputWaveFound == 0)
   
    return outputWaveName
End


To use this function, embed it in your code as follows:
DFREF thisFolder = GetDataFolderDFR()
string outputWaveName = GetNewOutputWaveName("SuggestedName", thisFolder, "Give me a name!")
if (strlen(outputWaveName) == 0)
    // user cancel
    // up to you to handle this appropriately
    return -1
endif

// make the output wave
Make /O/D/N=128 thisFolder:$outputWaveName      // look for help on the '$' operator if you don't understand what this means
wave theUsersOutputWave = thisFolder:$outputWaveName    // create a wave reference to the new wave that makes it a bit easier to use

// do something with the wave
// the wave is not special - treat 'theUsersOutputWave' as you would any other wave

Display theUsersOutputWave


As for making it so that the code runs when the user presses a button, that's not included. I'd suggest you try it yourself first and then just post back here if you can't get it to work.
This is amazing! Thank you. I'll let you know how I get on.

I love this forum. Perhaps in around 10 years or so I might be able to contribute my own codings.

Thanks again,

Matt

-----------Update-----------------------

It works! I have a few more things to work out but I should go and figure them out for myself.

Many thanks,

Matt