Quantcast
Channel: Measurement Studio for .NET Languages topics
Viewing all 1999 articles
Browse latest View live

I cannot make a new service request

$
0
0

I would put in a service request asking why the service request form hangs, but that will not work.  ;|

 

What is up with the service request manager?


NI VISA ActiveX and Measurement Studio 2015

$
0
0

Hi everybody,

 

I am currently updating an old software designed with VB .NET which used to target the .NET Framework 1.0 .

 

This software relied on an old version of Measurement Studio (can't determine which one precisely).

 

I have to update the software with a new version of Visual Studio (2015) and Measurement Studio 2015 in order to target the .NET Framework 4.5 .


Everything is working well except that I can't find the NI VISA ActiveX : AxCWVisaLib.AxCWVisa .

 

Do you have an idea where I can find it or how can I upgrade to the namespace NationalInstruments.Visa easily ?

 

Did this ActiveX disappear somehow ? Do you know the path to the ActiveX ?

 

Thanks for your answers !

 

Regards,

 

Max

Sporadic Error 200292

$
0
0

Error -200292

Some or all of the samples to write could not be written to the buffer yet. More space will free up as samples currently in the buffer are generated. To wait for more space to become available, use a longer write timeout. To make the space available sooner, increase the sample rate.

 

I am using a USB6343 X Series DAQ with Visual C# .NET.  On some machines we get the error -200292 when writing with these lines:

      var writer = new AnalogMultiChannelWriter(m_stim.Stream);
      writer.WriteMultiSample(false, m_waveform);

 

We are trying to generate a 60us wide pulse at 2400Hz (416.67 us) on two analog output channels with a phase offset between the channels.  The output buffer contains two cycles worth of data, which comes to 374 samples per channel.  The output generation is continuously retriggered by a frequency counter that is running at a frequency of 1200Hz. There are 42 sample clocks between the end of the generation and the next frequency clock edge, so there should be plenty of time for the hardware to finish generation and set up for the next trigger.

 

The problem is both waveform dependent and host PC dependent.  On my development machine everything works beautifully.  On some of our machines this setting fails consistently and on some it fails intermittently.  We have other waveform settings where everything works well across all of our host PC's.

 

The timeout is already 10 seconds, so increasing the timeout as the message suggests is not going to help anything. We have been able to cure many other sporadic problems of this nature by adjusting the buffer size.  In this case I have adjusted the buffer size so that it holds 1, 2, 3, or 5 complete cycles of data, to no avail.  Our other successful settings have both more data and less data than this setting. 

 

I am at a loss for what to try next.  Any suggestions?

 

I have included a simplified version of our generation code:

/// <summary>
/// Start a dual electrode stimulation train.  The pulse amplitudes are independently specified for each channel, but the pulse
/// train timing is identical for both channels.
///
/// The stimulation pulse train consists of a negativing going current pulse at the specified width
/// and amplitude then a 50 usec gap then a positive going current pulse at the specifed width and amplitude, followed by a rest
/// for the remainder of the period corresponding to the specified frequency.  If the period is so short that it cannot support
/// a 50usec pause after each pulse, then the available rest time in the period will be split equally.  Note that the peak to peak
/// amplitude is twice the specified amplitude.
///
/// For frequencies below 1KHz, the positive going pulse has double the specified pulse width and half the amplitude of the
/// negative going pulse
///
/// If onTime and offTime are specified then pulse trains will be delivered during the ontime followed by a pause for the offTime
/// perior to restarting the sequence.  For the transition between ON-OFF, a partial pulse train will be delivered if both positive
/// and negative pulses can be delivered prior to the expiration of the ON time.  If onTime or offTime is not specified, then the
/// pulse train is restarting.
/// </summary>
/// <param name="amplitude1">amplitude of stimulation pulse on the first channel [V]</param>
/// <param name="amplitude2">amplitude of stimulation pulse on the second channel [V]</param>
/// <param name="frequency">frequency of pulse stimulation [Hz]</param>
/// <param name="pulseWidth">width of single stimulation pulse [uS]</param>
/// <param name="channel2Delay">% cycle delay of channel 2 relative to channel 1</param>
public static void StartDualStim(double amplitude1, double amplitude2,
                                 int frequency, double pulseWidth, double channel2Delay = 0.0)
{
  try
  {
    var period = 1.0 / frequency; //desired period

    m_stim = new Task();
    m_frequencyClock = new Task();
    m_stim.AOChannels.CreateVoltageChannel(m_daq.AOPhysicalChannels[0], "stim0", -MaxOutputVoltage, MaxOutputVoltage, AOVoltageUnits.Volts);
    m_stim.AOChannels.CreateVoltageChannel(m_daq.AOPhysicalChannels[1], "stim1", -MaxOutputVoltage, MaxOutputVoltage, AOVoltageUnits.Volts);
    m_stim.Control(TaskAction.Verify);

    //to minimize timing error we need to make the pulse width an even multiple of the sampling clock time
    var n = (int) Math.Floor(4000 * pulseWidth * 1e-6 / period);

    //If necessary, decrease the sampling multiple to to stay below the DAQ's maximum sampling rate
    var maxSamplingRate = m_daq.AIMaximumMultiChannelRate;
    //the output max rate is higher, but the sample clock balks if you use that number
    n = Math.Min(n, (int) Math.Floor(maxSamplingRate * pulseWidth * 1e-6));

    //determine how many ticks are used to make the pulse width
    var tickTime = pulseWidth * 1e-6 / n;
    var samplingRate = 1 / tickTime;

    m_stim.Timing.ConfigureSampleClock("", samplingRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples);

    //actual sampling rate may deviate from requested, so recalculate
    tickTime = 1 / m_stim.Timing.SampleClockRate;
    var periodTicks = (int) Math.Round(period / tickTime);
    period = periodTicks * tickTime; //actual period given hardware limitations
    var channel2ShiftTicks = (int) (periodTicks * channel2Delay);

    //DAQ can sometimes shutoff if the number of samples is too small.  This problem is PC dependent, not DAQ dependent.  
    //For frequencies above 4kHz we will define two or three complete periods instead of one to increase the sample count.
    var periodCount = (int) Math.Ceiling(.33e-3 / period) + 1;

    var pulseTicks = (int) Math.Round(pulseWidth * 1e-6 / tickTime);

    m_frequencyClock.COChannels.CreatePulseChannelFrequency(m_daq.COPhysicalChannels[3], "stimFreq0", COPulseFrequencyUnits.Hertz, COPulseIdleState.Low, 0, frequency, 0.5);
    m_frequencyClock.Control(TaskAction.Verify);
    m_frequencyClock.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples, 100);

    var gapTicks = (periodTicks - 2 * pulseTicks) / 2;
    var leftoverTicks = periodTicks - pulseTicks * 2 - gapTicks - channel2ShiftTicks - 3;

    m_waveform = new double[2, periodTicks * periodCount - leftoverTicks];
    for (var i = 0; i < m_waveform.GetLength(1); i++)
    {
      var cycleTick = i % periodTicks;
      if (cycleTick < pulseTicks)
        m_waveform[0, i] = -amplitude1;
      else if (pulseTicks + gapTicks <= cycleTick && cycleTick < gapTicks + pulseTicks * 2)
        m_waveform[0, i] = amplitude1;
      else
        m_waveform[0, i] = 0.0;

      if (channel2ShiftTicks <= cycleTick && cycleTick < pulseTicks + channel2ShiftTicks)
        m_waveform[1, i] = -amplitude2;
      else if (pulseTicks + gapTicks + channel2ShiftTicks <= cycleTick && cycleTick < gapTicks + pulseTicks * 2 + channel2ShiftTicks)
        m_waveform[1, i] = amplitude2;
      else
        m_waveform[1, i] = 0.0;

      var writer = new AnalogMultiChannelWriter(m_stim.Stream);
      writer.WriteMultiSample(false, m_waveform);

      m_stim.Timing.SampleQuantityMode = SampleQuantityMode.FiniteSamples;
      m_stim.Timing.SamplesPerChannel = m_waveform.GetLength(1);
    }

    m_stim.Triggers.StartTrigger.Type = StartTriggerType.DigitalEdge;
    m_stim.Triggers.StartTrigger.Retriggerable = true;
    m_stim.Triggers.StartTrigger.DigitalEdge.Edge = DigitalEdgeStartTriggerEdge.Rising;
    m_stim.Triggers.StartTrigger.DigitalEdge.Source = "/" + m_frequencyClock.COChannels[0].PhysicalName + "InternalOutput";

    m_stim.Control(TaskAction.Verify);
    m_stim.Start();
    m_frequencyClock.Start();
  }
  catch (Exception exception)
  {
    SessionViewModel.WriteLogEntry("DAQ_Exception", exception.Message);
    SessionViewModel.GetInst().StimSessionMessageText = exception.Message + "\nDAQ Exception";
    throw;
  }
}

Configure the InteractionMode of NumericTextBoxDouble in c#

$
0
0

Hi,

I'm trying to set the InteractionMode of a NumericTextBoxDouble to TextInput and ButtonClicks but I can't find the way to set 2 Mode like in xaml : InteractionMode="ButtonClicks TextInput"

 

How can I do this in c# ?

test1.InteractionMode = NumericTextBoxInteractionModes.TextInput;

 

Thanks

Measurement & automation explorer. Test panel for simulated device won't launch

$
0
0

Hi.

I want to launch a test panel for a simulated device (USB-6008) on Measurement & Automation explorer (max). I have configured a propriate task. But when I select the simulated device and click "test panel", then nothing happens. No test panel appears. What is wrong?

How can I get X-axis location from mouse click location on waveformgraph

$
0
0

Hi,

    I'm trying to place cursor using context menu on zoomed graph.

    So, I need to get x location from mouse click location. I searched for it but didn't get proper method for it.    

Create custom control from MS boolean control?

$
0
0

Greetings from Michigan,

 

Is is possible to create a custom control from a Measurement Studio control, particular a boolean button or switch control?  I have an application where I want to use a Measurement Studio switch control that inherits from another third party control.  Is this possible?

 

Thanks,

D

Modify WPF Legend Glyphs

$
0
0

Hi,

How can i modify the events or toggle button properties of WPF Legend Glyphs?
ie.: I would like plot color change with toggle button click, and not the visibility property.

Or how can i change a Plot color if i clicked with mouse on the plotname?

And how to modify the TextBox that contains the plotname to IsReadOnly?


WPF Legend: context menu

$
0
0

Is there any way with the WPF Legend control to detect the type of item the user clicks on when they right click to open a context menu? I have an application showing plots and cursors in the legend. When the user clicks on a cursor, I want to serve up a context menu for that cursor. If they click on a plot, I want to present a context menu for that plot. Not only do I need to know the type of item, but also which item specifically they click on.

 

I do exactly this in WinForms with the legend control there. There does not appear to be a similar mechanism in WPF. Am I missing something?

Support for .NET Framework 3.5 in Windows 10

$
0
0

Hi everyone!

I'm trying to install .NET 3.5 support on my Windows 10 machine for use with NI Visa. We built our software around Visa 5.1.2, but I'm not sure if we would need to globally update our libraries or if there's a way to force the NI installer to detect .NET 3.5 on the machine. The framework is installed on the Windows 10 machine, but for some reason the NI installer won't detect it. 

Any help is greatly appreciated!

Where are DAQmx .NET and API's Documentation?

$
0
0

Hi,

I am working on some project where I need to use NI-DAQmx to create application using Visual C# .NET without Measurement Studio.


I have installed the latest NI-DAQmx 16.1.0., I managed to install .Net Framework 4.5.1 language support as well as the correspondent examples. But I can not find any DAQmx .NET and API Documentation.

Spent a lot of time on the forum and NI site and cannot not find anything.

 

Please help

Thank you

Problems Transferring Setup from PC to Rigol DS2072A DSO using MessageBasedSession.

$
0
0

I'm using c# .net to communicate with the DSO using MessageBasedSession. So far have been able to upload Event Tables from the DSO to pc ok.
Below shows the System Setup Command: SystemSetup.jpg

 

  I can save the DSO Configuration data to the PC:

Code: [Select]
 string loadCommand = ":SYSTem:SETup?";
                mbSession.Write(loadCommand); 
                mbSession.ReadToFile("D:\\DSOSetupRTF.stp"); /
 
but not back again to the DSO - nothing happens:
Code: [Select]
  loadCommand = ":SYSTem:SETup ";
                    mbSession.Write(loadCommand);
                     mbSession.WriteFromFile("D:\\DSOSetupRTF.stp");

 

I wonder if MessageBasedSession is correct for this purpose? The only other reference I've found on this is the following post  (here):

systSavePost.jpg

They are, I think, using Linux (or some such) - but I would also think that .Net should have a corresponding function. So I guess my question is what can I use in .NET to get this working, as it seems to do in the above post?

 

cDAQ and NI 9234: sampling data at a given frequency

$
0
0

In short: I need to sample the voltage input of an NI-9234 hosted inside a cDAQ-9174, and I need to sample it at 20 Hz. That is, I expect to get exactly 20 samples every second, no one more and no one less. And, as far as I've been able to test, it seems impossible: even using the NI examples there is no way to get data at a given frequency, I always get data at absurdly and totally arbitraries high speed, usually in the range of 1600 sample per seconds. Why is the damn thing ignoring the settings? After a bit it even crash 'cause the software (NI examples) cannot keep the pace with the sample data rate...which is obvious, considering that the hardware is doing anything but what it is been asked to do.

 

How can I get a few thousand Euros of hardware to do what it's been bought for, before I start banging the head in the wall?? :-D

How can i copy instrument image to a clipboard by gpib(c#)?

$
0
0

How can i  copy instrument image to a clipboard by gpib(c#)?  

Data reading with NI USB DAQ 6343 X series

$
0
0

Hi

i have a couple of question regarding the code c# and using NI USB DAQ 6343

 

i have a project with couple of data acquisition. i added function generator function to my code from NI examples 

1:

// functiongenerator.cs
public static double[] GenerateSineWave( double frequency, double amplitude, double sampleClockRate, double samplesPerBuffer) { double deltaT = 1/sampleClockRate; // sec./samp int intSamplesPerBuffer = (int)samplesPerBuffer; double[] rVal = new double[intSamplesPerBuffer]; for(int i = 0; i < intSamplesPerBuffer; i++) rVal[i] = amplitude * Math.Sin( (2.0 * Math.PI) * frequency * (i*deltaT) ); return rVal; }
// mainform.cs
private void startButton_Click(object sender, System.EventArgs e)
        {
            // Change the mouse to an hourglass for the duration of this function.
            Cursor.Current = Cursors.WaitCursor;

            // Read UI selections
     /*       DigitalEdgeStartTriggerEdge triggerEdge;
            if (this.triggerEdgeComboBox.Text == "Rising")
                triggerEdge = DigitalEdgeStartTriggerEdge.Rising;
            else
                triggerEdge = DigitalEdgeStartTriggerEdge.Falling;
*/
            try
            {
                // Create the master and slave tasks
                inputTask = new Task("inputTask");
                outputTask = new Task("outputTask");

                // Configure both tasks with the values selected on the UI.
                inputTask.AIChannels.CreateVoltageChannel(inputChannelComboBox.Text,
                    "",
                    AITerminalConfiguration.Differential,
                    Convert.ToDouble(inputMinValNumeric.Value),
                    Convert.ToDouble(inputMaxValNumeric.Value),
                    AIVoltageUnits.Volts);

                outputTask.AOChannels.CreateVoltageChannel(outputChannelComboBox.Text,
                    "",
                    Convert.ToDouble(outputMinValNumeric.Value),
                    Convert.ToDouble(outputMaxValNumeric.Value),
                    AOVoltageUnits.Volts);

                // Set up the timing
                inputTask.Timing.ConfigureSampleClock("",
                    Convert.ToDouble(rateNumeric.Value),
                    SampleClockActiveEdge.Rising,
                    SampleQuantityMode.ContinuousSamples,
                    Convert.ToInt32(samplesNumeric.Value));

                outputTask.Timing.ConfigureSampleClock("",
                    Convert.ToDouble(rateNumeric.Value),
                    SampleClockActiveEdge.Rising,
                    SampleQuantityMode.ContinuousSamples,
                    Convert.ToInt32(samplesNumeric.Value));

                // Set up the start trigger
                
                string deviceName = inputChannelComboBox.Text.Split('/')[0];
                string terminalNameBase = "/" + GetDeviceName(deviceName) + "/";
        //        outputTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(terminalNameBase + "ai/StartTrigger", triggerEdge);

                // Verify the tasks
                inputTask.Control(TaskAction.Verify);
                outputTask.Control(TaskAction.Verify);

                // Write data to each output channel
                FunctionGenerator fGen = new FunctionGenerator(Convert.ToString(frequencyNumeric.Value),
                    Convert.ToString(samplesNumeric.Value),
                    Convert.ToString(frequencyNumeric.Value / (rateNumeric.Value / samplesNumeric.Value)),
                    waveformTypeComboBox.Text,
                    amplitudeNumeric.Value.ToString());

                output = fGen.Data;

                writer = new AnalogSingleChannelWriter(outputTask.Stream);
                writer.WriteMultiSample(false, output);

                // Officially start the task
                StartTask();

                outputTask.Start();
                inputTask.Start();

                // Start reading as well
                inputCallback = new AsyncCallback(InputRead);
                reader = new AnalogSingleChannelReader(inputTask.Stream);
                
                
                // Use SynchronizeCallbacks to specify that the object
                // marshals callbacks across threads appropriately.
                reader.SynchronizeCallbacks = true;
                
                reader.BeginReadMultiSample(Convert.ToInt32(samplesNumeric.Value), inputCallback, inputTask);

            }
            catch (Exception ex)
            {
                StopTask();
                MessageBox.Show(ex.Message);
            }
        }

my question is: could i generate frequencies from AO0/AO1 up to 5KHz - 10KHz,  in NI MAX with creating task , i can not generate frequencies more then 900Hz.

 

2:

 

i need to measure 2 channels in same time AI2-AI3, next loo AI3-AI4

i understand i nee to set the device  with this syntax Dev1/AI2, Dev1/AI3

but that is next how i can set all necessary data to my code and how i can read it to datatable

 

3:

how i can save data continuously to my excel file, do i need to use threads, or i can buffer all data and at the end of the test

save all data to excel file at once.

 

 

 


.NET for PXI-6672 Timing Module?

$
0
0

I have a series of PXI chassis, each running the same operations, but I want to synchronize those operations to start and stop at the same time.  For this, in each chassis I have a PXI-6672 Timing Module which I have not implemented yet.  I have been using the .NET 4.0 framework to build up my code and so I would like to continue to use this framework when implementing the 6672's, however I haven't been able to find any resources for doing this.  Is there any way to use the .NET 4.0 framework to implement 6672 Timing Modules?

DAQmx Lowpass Filter Cutoff Frequency

$
0
0

I am looking to enable lowpass filtering on multiple stations and DAQ boards. I had in mind that a 1MHz cutoff is a good starting point, and we already have some physical RC filters in this neighborhood. The idea is to replace any physical filters with those built into the DAQ system.

 

I have started with these properties found in DAQmx

Dim _channel As NationalInstruments.DAQmx.AIChannel
_channel = _task.AIChannels.CreateVoltageChannel(...)
_channel.LowpassEnable = True
_channel.LowpassCutoffFrequency = 1000000000.0

based of this page, and some more info here. However, I haven't found the latter very helpful as the task I created in MAX doesn't have a "Device" tab...

 

My question is, how do I know the filter frequencies available on my cards? I have not been able to find this information anywhere. Across 15 production machines, I have an assortment of DAQ cards, including 6001, 6008, 6211, and 6343, currently.

 

Also, do I need to select some clock source to perform the filtering? I am not sure how it is done internally in the card.

NI-VISA Method to send a String followed by Binary Data

$
0
0

 

I would like to send a command in ASCII format, immediately followed by a byte array. The obvious way to send the binary data is using:

     MessageBasedSessionWriter writer = new MessageBasedSessionWriter(mbSession);               
     writer.BinaryEncoding = BinaryEncoding.RawLittleEndian;
     writer.WriteBinary(setupData);

where setupData is a byte array, already returned from the instrument. The command string has to be in the same Write() method as the byte array, but after some reading and a lot of trial and error I'm baffled. Is there no way to do this in .NET?

Memory Leak in PointAnnotation

$
0
0

I use some PointAnnotation in my graph. Each time the data is updated - I remove all the PointAnnotation and add news.
After I do it many times - I got an OutOfMemory exception.
I found that there is a memory leak in PointAnnotation and as a result - all the points I removed actually stayed in memory.

Here is a simple code to get it:

xaml:

<Window x:Class="WpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ni="http://schemas.ni.com/controls/2009/xaml/presentation"
        Title="MainWindow" Height="350" Width="525"><Grid><Grid.RowDefinitions><RowDefinition/><RowDefinition Height="Auto"/></Grid.RowDefinitions><ni:Graph x:Name="graph"/><Button Grid.Row="1" Click="Button_Click">Add Point Annotations</Button></Grid></Window>

xaml.cs:

 public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            PointAnnotation point = new PointAnnotation();
            point.Fill = new SolidColorBrush(Colors.Red);
            point.HorizontalPosition = 5;
            point.VerticalPosition = 5;
            point.TargetShape = PointShape.Ellipse;
            point.TargetSize = new Size(10, 10);
            point.ArrowVisibility = System.Windows.Visibility.Collapsed;
            point.InteractionMode = AnnotationInteractionModes.None;
            graph.Children.Add(point);
            Thread.Sleep(800);

            Task t = new Task(() =>
            {
                for (int i = 0; i < int.MaxValue; i++)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                        {
                            graph.Children.RemoveAt(0);
                            point = new PointAnnotation();
                            point.Fill = new SolidColorBrush(Colors.Red);
                            point.HorizontalPosition = i % 11;
                            point.VerticalPosition = i % 11;
                            point.TargetShape = PointShape.Ellipse;
                            point.TargetSize = new Size(10, 10);
                            point.ArrowVisibility = System.Windows.Visibility.Collapsed;
                            point.InteractionMode = AnnotationInteractionModes.None;
                            graph.Children.Add(point);
                        });
                    Thread.Sleep(70);
                }
            });
            t.Start();
        }
    }

This code only adds a point and removes it in a loop from 0 to int.MaxValue.
I get this exception after I add about 80000 points. (to do it faster - you can remove the Thread.Sleep)

 

Is there a workaround I can add to my code to fix this issue (beyond reusing of the same instances)?

clearing resource cache in visaNS

$
0
0

VisaNS, Windows 7, VisualC# 2013, 

 

When I execute

 

string[] resources = ResourceManager.GetLocalManager().FindResources("?*");

 

I am getting a cached copy.  Therefore when i disconnect an instrument the instrument still shows up in the returned list of resources.  How can i clear the cache before calling FindResources?

Viewing all 1999 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>