From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

6556 - Hardware Compare (HWC) in C#

The following is the corrected line.

//Loads the generation bit pattern and the expected bit pattern into the card's memory.
            pxiBoxGenerate.WriteNamedWaveformWDT("Test", digitalWordByte.Length / 2, niHSDIOConstants.GroupByChannel, digitalWordByte);

 The total length needs to be divided by 2 because I'm loading in two patterns with the variable digitalWordByte.

 

0 Kudos
Message 11 of 19
(2,913 Views)

Oh ok, in my case i am not comparing the signals just generating so i am not doing this step 

 string digitalWordString = digitalWordGenerateString + digitalWordAcquireString;

so i dont think I am having that error. Anyway I will try something else...

Thanks for the reply....

0 Kudos
Message 12 of 19
(2,907 Views)

hi.......

Can you help me with this situation. When I am trying generate signal from multiple channels i am getting this error  " A digital State value in the waveform u attempted to write is invalid for this device or for this configuration. Supported Values: 0,1"

 

But when i am trying with single channel i was  getting this error "Requested Waveform length is invalid, because the number of samples is not an integer multiple of the waveform length increment" . But this single channel error is solved when i changed the digitalwordbyte value as below

 

"// digitalWordByte = digitalWordGenerateString.Select(n => Convert.ToByte(char.GetNumericValue(n))).ToArray();
digitalWordByte = new byte[] { 1, 1, 0, 1 };"

 

is their a function or something I am missing. How can i remove my first error and is their any thing wrong with my approach to remove the second error'


Please reply to to me if u have any solution for this.

Thanks in advance............

0 Kudos
Message 13 of 19
(2,898 Views)

Can you share your source code?

0 Kudos
Message 14 of 19
(2,893 Views)
niHSDIO pxiBoxGenerate;
string resourceName;
string channelListGenerate;
double sampleClockRate;
string digitalWordGenerateString = "110";
string digitalWordString;
byte[] digitalWordByte;

private void btnwrite_Click(object sender, EventArgs e)
        {
            resourceName = txtResourceName.Text;
            channelListGenerate = txtChannelName.Text;
            sampleClockRate = Convert.ToDouble(txtRate.Text);

            digitalWordString = digitalWordGenerateString;

            //digitalWordByte = digitalWordString.Select(n =>Convert.ToByte(char.GetNumericValue(n))).ToArray();
            digitalWordByte = new byte[]{1,1,0,1};
            
            pxiBoxGenerate = niHSDIO.InitGenerationSession (resourceName, true, true, "");
          
            pxiBoxGenerate.AssignDynamicChannels(channelListGenerate );
            
            pxiBoxGenerate.ConfigureSampleClock(niHSDIOConstants.OnBoardClockStr, sampleClockRate);
                      
            pxiBoxGenerate.ConfigureGenerationMode(niHSDIOConstants.Waveform);
      
            pxiBoxGenerate.ConfigureGenerationRepeat(niHSDIOConstants.Continuous, 1);
            
            pxiBoxGenerate.ConfigureSoftwareStartTrigger();
           
            pxiBoxGenerate.ExportSignal(niHSDIOConstants.SampleClock, "", niHSDIOConstants.DdcClkOutStr);
         
            pxiBoxGenerate.ExportSignal(niHSDIOConstants.DataActiveEvent, "", niHSDIOConstants.Pfi1Str);

            pxiBoxGenerate.WriteNamedWaveformWDT("Test", digitalWordByte.Length, niHSDIOConstants.GroupByChannel, digitalWordByte);

            pxiBoxGenerate.Initiate();
            
            pxiBoxGenerate.SendSoftwareEdgeTrigger(niHSDIOConstants.StartTrigger, "");
            
            pxiBoxGenerate.DeleteNamedWaveform("Test"); 
        }           
    }
}

This is the code with which I am trying to generate the LVDS signal. One important thing i forgot to mention is that I am using PXI 6562, not PXI 6556. Sorry about that. Also the DeleteNamedWaveform function is showing error

"You cannot perform this action while the session is in the running state." when trying through single channel. 

Thanks for giving your time to me.

 

0 Kudos
Message 15 of 19
(2,890 Views)

I modified your code below.  I commented out the ExportSignal() methods because you don't need those unless you are doing hardware compare.  You can't call the DeleteNamedWaveform() method if your signal is set to continuous generation.  I commented this out as well.  Maybe give it a try?

 

It seems like you if it threw an error at the DeleteNamedWaveform() method, you were able to get through all of the previous.  Did you see any output?  Are you looking on a scope?

 

Also, for this particular code block you provided, I'm assuming you're only trying to output on one channel.  Is this true?

 

I should also mention that I've never used a 6562, but I think the 6556 and 6562 use a lot of the same methods.

 

niHSDIO pxiBoxGenerate;
string resourceName;
string channelListGenerate;
double sampleClockRate;
string digitalWordGenerateString = "110";
string digitalWordString;
byte[] digitalWordByte;

private void btnwrite_Click(object sender, EventArgs e)
        {
            resourceName = txtResourceName.Text;
            channelListGenerate = txtChannelName.Text;
            sampleClockRate = Convert.ToDouble(txtRate.Text);

            digitalWordString = digitalWordGenerateString;

            //digitalWordByte = digitalWordString.Select(n =>Convert.ToByte(char.GetNumericValue(n))).ToArray();
            digitalWordByte = new byte[]{1,1,0,1};
            
            pxiBoxGenerate = niHSDIO.InitGenerationSession (resourceName, true, true, "");
          
            pxiBoxGenerate.AssignDynamicChannels(channelListGenerate );
            
            pxiBoxGenerate.ConfigureSampleClock(niHSDIOConstants.OnBoardClockStr, sampleClockRate);
                      
            pxiBoxGenerate.ConfigureGenerationMode(niHSDIOConstants.Waveform);
      
            pxiBoxGenerate.ConfigureGenerationRepeat(niHSDIOConstants.Continuous, 1);
            
            pxiBoxGenerate.ConfigureSoftwareStartTrigger();
           
            //pxiBoxGenerate.ExportSignal(niHSDIOConstants.SampleClock, "", niHSDIOConstants.DdcClkOutStr);
         
            //pxiBoxGenerate.ExportSignal(niHSDIOConstants.DataActiveEvent, "", niHSDIOConstants.Pfi1Str);

            pxiBoxGenerate.WriteNamedWaveformWDT("Test", digitalWordByte.Length, niHSDIOConstants.GroupByChannel, digitalWordByte);

            pxiBoxGenerate.Initiate();
            
            pxiBoxGenerate.SendSoftwareEdgeTrigger(niHSDIOConstants.StartTrigger, "");
            
            //pxiBoxGenerate.DeleteNamedWaveform("Test"); 
        }           
    }
}

 

 

0 Kudos
Message 16 of 19
(2,885 Views)

hiii....

Thanks for the reply........

Actually I am trying to get a output in both single and multiple channel. The code is working fine for single channel and I am able to generate some waveform also which i cheked with the osciloscope. But i need the same for multiple channel also and when I try that i get this error :

"A digital state value in the waveform you attempted to write is invalid for this device or for this configuration. Supported Values: 0, 1" in WriteNamedWaveformWDT Function.

I am not able to understand this error. If u get anything in this please reply, it will be of great help.

Thanks again for your time...........

 

 

 

0 Kudos
Message 17 of 19
(2,878 Views)

Try the code below and compare it against the previous working single channel code.  The keys are creating a digital word for each channel you want to use (digital words have to be the same length), concatenate them together into one string (concatenation type depends on if you're grouping by channel or not), convert that string into a byte[], load that byte[] into WriteNamedWaveformWDT();  The pseudo-code for WriteNamedWaveformWDT() is WriteNamedWaveformWDT(striing digital word name, int length of a single digital word, not the total length of concatenated digital words, group by channel or the other option, byte[] concenated digital words).

 

(Hopefully the code works...I didn't try it.  However, all of the correct ideas are there.)

 

niHSDIO pxiBoxGenerate;
string resourceName;
string channelListGenerate;
double sampleClockRate;
string digitalWordGenerateString = "110";
string digitalWordString;
//byte[] digitalWordByte;
byte[] digitalConcatenatedWordByte;
string digitalWordStringChannel1; //Digital word for specific channel
string digitalWordStringChannel2; //Digital word for specific channel
string digitalWordStringChannel3; //Digital word for specific channel
string digitalConcatenatedWordString;
int numberOfChannels;

private void btnwrite_Click(object sender, EventArgs e)
        {
            resourceName = txtResourceName.Text;
            //channelListGenerate = txtChannelName.Text;
            channelListGenerate = "1,2,3"; //Assuming three channels.
            numberOfChannels = 3; //Will be used in WriteNamedWaveformWDT() below.  Needs to match number of channels in channelListGenerate above.
            sampleClockRate = Convert.ToDouble(txtRate.Text);

            //digitalWordString = digitalWordGenerateString;
            
            //Individual digital words need to be concatenated into one string and then converted to type byte[] for WriteNamedWaveformWDT() below.
            digitalWordStringChannel1 = "1,1,0,1"; //Can be a unique pattern.
            digitalWordStringChannel2 = "1,1,0,1"; //Can be a unique pattern.
            digitalWordStringChannel3 = "1,1,0,1"; //Can be a unique pattern.
            digitalConcatenatedWordString = digitalWordStringChannel1 + digitalWordStringChannel2 + digitalWordStringChannel3;
            digitalConcatenatedWordByte = digitalWordString.Select(n =>Convert.ToByte(char.GetNumericValue(n))).ToArray();
            
            //digitalWordByte = new byte[]{1,1,0,1};
            
            pxiBoxGenerate = niHSDIO.InitGenerationSession (resourceName, true, true, "");
          
            pxiBoxGenerate.AssignDynamicChannels(channelListGenerate);
            
            pxiBoxGenerate.ConfigureSampleClock(niHSDIOConstants.OnBoardClockStr, sampleClockRate);
                      
            pxiBoxGenerate.ConfigureGenerationMode(niHSDIOConstants.Waveform);
      
            pxiBoxGenerate.ConfigureGenerationRepeat(niHSDIOConstants.Continuous, 1);
            
            pxiBoxGenerate.ConfigureSoftwareStartTrigger();
           
            //pxiBoxGenerate.ExportSignal(niHSDIOConstants.SampleClock, "", niHSDIOConstants.DdcClkOutStr);
         
            //pxiBoxGenerate.ExportSignal(niHSDIOConstants.DataActiveEvent, "", niHSDIOConstants.Pfi1Str);

            //WriteNamedWaveformWDT() below requires the length of a single digital word and the concatenated digital words in type byte[].
            //(All digital words need to be the same length.)
            pxiBoxGenerate.WriteNamedWaveformWDT("Test", digitalWordByte.Length / numberOfChannels, niHSDIOConstants.GroupByChannel, digitalConcatenatedWordByte);

            pxiBoxGenerate.Initiate();
            
            pxiBoxGenerate.SendSoftwareEdgeTrigger(niHSDIOConstants.StartTrigger, "");
            
            //pxiBoxGenerate.DeleteNamedWaveform("Test"); 
        }           
    }
}

 

0 Kudos
Message 18 of 19
(2,874 Views)

hi thanks for the reply. I am now able to generate LVDS Waverform. But do u have any idea about which function should i use for Acquisition of the waveform. As I am using WriteNamedWaveformWDT() to write data into the PXI I am unable to find any fucntion to fetch data with respect to that. Their are some functions like FetchWaveformU32() but it will work only if i am using WriteNamedWaveformU32(). And I am not able to use WriteNamedWaveformU32() as some error is showing about incompatible function. In your code also their is no fuction to fetch data as you are comparing generation and Acquisition data.    But i want to see the acquired data in a textbox. So if you have any idea about this it will be really helpfull.

 

Thanks again for Your Reply..............

0 Kudos
Message 19 of 19
(2,852 Views)