Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I programmatically set a custom, non-linear, table driven scale

The DAQ assistant has a custom scale feature. It allows entry of a table of values. As I understand it, this establishes a piecewise linear mapping from input voltage to physical units. I want to read calibration data table from a file and programmatically put it into this table rather than doing manual entry. The calibration data file changes so I don't want the filename hardwired.
 
Searched files shown in solution browser (even hidden ones) and couldn't find an API. How do I do this?
 
I'm using VS2005, MS 8.0.1, WXP.
0 Kudos
Message 1 of 9
(5,843 Views)
Steve -
You should be able to use the Assistant inside Visual Studio to manually populate a table and look at the code that the Assistant generates to see what API calls are made to populate the table programmatically.
 
Unfortunately, my system is in a bad state right now, so I can't try it out quickly. Let us know if this works for you.
 
- David
0 Kudos
Message 2 of 9
(5,833 Views)
Hi Steve

The assistant will create a scale in the Measurement and Automation Explorer (MAX) for you and load it from there. It won't generate the scale code for you.

In order to do what you want, you will need to create a TableScale class and use the name you specified for the scale in the CreateXXXChannel method.

Bilal Durrani
NI
0 Kudos
Message 3 of 9
(5,832 Views)

Bilal,

Thank you. I got some code to work that creates a new custom scale, but I couldn't figure out how to get/set the old custom scale values. The custom scale I made manually with the assistant is called "MyScale". It shows up in MAX as well. The test code that works to create a new scale, "MyNewScale" is shown below. It is in DaqTask.vb generated by the assistant.

Public Overridable Sub Configure()

Dim PreArray() As Double = {-0.1, -0.08, -0.06, 0, 0.06, 0.08, 0.1}

Dim PostArray() As Double = {-160, -130, -90, 0, 80, 120, 140}

Dim MyNewScale As New TableScale("MyNewScale", PreArray, PostArray)

AIChannels.CreateVoltageChannel(

"Dev1/ai1", "Voltage", AITerminalConfiguration.Differential, -1, 1, "MyNewScale")

Timing.ConfigureSampleClock(

"", 1000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 1000)

Dim oldPreArray() As Double

Dim oldPostArray() As Double

'How do I create a TableScale object that references the existing custom scale called "MyScale"?

oldPreArray = MyScale.PreScaledValues

oldPostArray = MyScale.ScaledValues

End Sub

The "MyNewScale" gets created fine. Your e-mail implied that I could create a reference to it in code? How do I do that?

0 Kudos
Message 4 of 9
(5,824 Views)
Hi Steve,

Once the scale has been created and is visible in MAX, you should be able to reference it (as well as all of your other custom scales) using:

DaqSystem.Local.Scales

Hope this helps. Have a good one Steve!
Dan Weiland
0 Kudos
Message 5 of 9
(5,798 Views)

Dan,

Could you give me a line(s) of code that returns a list of the local scales in some variable? The way to set up the object declarations and reference everything isn't clear, I get hard to decipher error messages. (New to VS2005, programmed a lot in VB6). It would be nice if the MS online documentation included some examples. I looked thru the example directory and they all made things from scratch.

Thanks,

Steve

0 Kudos
Message 6 of 9
(5,787 Views)
Hi Steve,

If you call this line of code, it will return all the scales into a string array.  Let me know if you have any questions.

Dim scales() = NationalInstruments.DAQmx.DaqSystem.Local.Scales
0 Kudos
Message 7 of 9
(5,747 Views)

Terry,

I must not be clear. The custom scale exists and the scales() array gives me a string array that holds all the names. So, knowing the name of an existing scale made by MAX or my own code, how do I access the prescaled and scaled arrays AFTER the fact? Once I pick NationalInstruments.DAQmx.DaqSystem the only useful choice is Local and then I cannot get to PreScaledValues or ScaledValues.

I need to get the PreScaledValues and ScaledValues of a named, existing custom scale. In addition, once I have the TableScale object I may need to change some of the arrrays by the program. (One simple example is that I may need to change the offset so I would add it to the custom scale ScaledValues array.)

I must be dense or something. Thanks for your patience.

Steve

0 Kudos
Message 8 of 9
(5,743 Views)

Here is an example of loading an existing TabelScale from MAX

  Dim table As TableScale
  Dim scale As Scale = DaqSystem.Local.LoadScale("MyScale")

  If scale.Type = ScaleType.Table Then

            table = CType(scale, TableScale)
            Dim prescale As Double() = table.PreScaledValues
            Dim scaled As Double() = table.ScaledValues
  End If

Bilal Durrani
NI
0 Kudos
Message 9 of 9
(5,724 Views)