LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving a "DAQmx Task" data type

I use the XML file/string functions to load/save the state of controls between VI executions.  It has never been a problem in the past, but with this new project I need to save a DAQmx Task control.  The control is a drop-down box that lists the DAQmx tasks that were setup in Measurement and Automation Explorer.  So the value from this control (which is of type DAQmx Task) is passed to the XML file and then read from the XML file on a later execution of the VI.

The problem is, the value of a DAQmx Task boils down to an ID that changes between LabVIEW executions.  I have a DAQmx Task called "MyDigitalOutTaskTest".  I execute my code, select the task "MyDigitalOutTaskTest" from the drop down, and then stop the code so that the XML file is written.  I check my XML file it has this entry:

<Refnum>
<Name>Digital Output Task:</Name>
<RefKind>Generic Tag</RefKind>
<RefType>NIDAQ</RefType>
<Val>0x0694E1E0</Val>
</Refnum>

While LabVIEW is not running, I switch the control to some other DAQmx task and hit the "run" button.  The VI behaves as expected, looks up the value of the control from the XML file and switches the control to the entry "MyDigitalOutTaskTest".

Now, I fully exit LabVIEW, re-launch LabVIEW, open the VI, and hit the "run" button.  This time "MyDigitalOutTaskTest" is not selected from the dropdown and instead it is a blank field.  *sigh*.  I select the task from the dropdown and stop my VI which then dumps a new .XML file containing the control settings.  Looking in my XML file, I find that the <Val> tag's value has changed:

<Refnum>
<Name>Digital Output Task:</Name>
<RefKind>Generic Tag</RefKind>
<RefType>NIDAQ</RefType>
<Val>0x06CCB968</Val>
</Refnum>

I run the same procedure, and again I get a different number: 0x07B24D70

So this value is dynamic.  Now what?  What property from the control do I use to save to the XML and can use to load from the XML file so this work as desired.  I would still very much like to use the DAQmx Task drop down control, as this has a nice interface that has updated values with new DAQmx Task entries as well as a browser that can be used to edit a task.

-Nic
0 Kudos
Message 1 of 6
(3,840 Views)

I am not sure on why you are saving the value.  I think the value of a task is a internal reference to a daqmx object, this will change from run to run so saving this value doesnt get you much.  Why are you saving this data.  you can just recreate the task at the start of execution.  The task will be destroyed when you clear the task or labview goes out of memory and the value wil nolonger mean anything.  I would guess (I could be wrong) that saving this is like saving a pointer, it only means something in respect to an application instance.

 

Paul

 

 

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 2 of 6
(3,836 Views)
No.  The task is setup using Measurement and Automation Explorer and has a name assigned to it.  I like to use this dropdown as this program may be run with different tasks depending on what the user wants to do.  I realize that the way LabVIEW treats the value from the control in the image is the problem.  Still, I can right-click this control outside of execution and select "Set current value as default" and it will select the same task on every execution.  Not so if I pass the value into an XML file and try to reload that value at the start of execution.

Thanks you for your input!
-Nic
0 Kudos
Message 3 of 6
(3,833 Views)
Hi Nic,
 
This was reported to R&D (# 98750) for further investigation.  As a workaround you can flatten the DAQmx task to a string before converting it to XML.  Then do the opposite when reading the value from the XML file.  Example code for this process can be found in the attachments here
Jennifer R.
National Instruments
Applications Engineer
0 Kudos
Message 4 of 6
(3,784 Views)
Thanks Jennifer!  That solution worked great!
0 Kudos
Message 5 of 6
(3,765 Views)
Wonderful!  Glad to be able to help. 
Jennifer R.
National Instruments
Applications Engineer
0 Kudos
Message 6 of 6
(3,763 Views)