Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

trouble with WriteNamedWaveformWDT and C#

Hi All,

 

I'm having difficulty with niHSDIO_WriteNamedWaveformWDT, but this time with C#.  The problem is as follows.

 

1.  I added the WriteNamedWaveformWDT method in a similar manner to the other methods in the niHSDIO.cs wrapper supplied by National Instruments.

 

2.  A byte[] array is then passed to this function in the manner specified in the HSDIO user manual.  Each byte has a value equal to either 0, 1, or 2 (which is the byte representation for 'Z' or tri-state).

 

3.  There do not appear to be any examples for C# that use the WriteNamedWaveformWDT function.

 

I attach the modified wrapper and a screenshot indicating the nature of the error.

 

All advice is gratefully accepted.  This is very critical for my application - I2C communication using PXI-6551 and Visual C# Express.

 

Thanks.

 

Anand

 

 

Download All
0 Kudos
Message 1 of 4
(3,703 Views)

Hi All,

 

I received timely help from the folks at National Instruments with the WriteNamedWaveformWDT functoin and C#.  Thank you guys.  Here is a working portion that I just experimented with.  So far, I've only tried the generation portion.  I also attach the niHSDIO.cs file that was modified by NI to incorporate the WriteNamedWaveformWDT function call.

 

// Test NI's generation configuration for a very specific case

 string LineSDA = "3";

string LineSCL = "0";

string genChannelList = LineSCL + "," + LineSDA;

niHSDIO hsdioGen = niHSDIO.InitGenerationSession(txtResourceName.Text, false, false, "");

hsdioGen.AssignDynamicChannels(genChannelList); // clock and data line

hsdioGen.ConfigureSampleClock(niHSDIOConstants.OnBoardClockStr, Convert.ToDouble(txtClockRate.Text));

hsdioGen.ConfigureInitialState(genChannelList, "ZZ");

hsdioGen.ConfigureIdleState(genChannelList, "ZZ");

byte[] data = new byte[] { 0, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2, 0}; //

hsdioGen.WriteNamedWaveformWDT("MyWaveform", (data.Length)/2, 71, data); //71 is Group_by_sample

hsdioGen.Initiate();  // begin generation

hsdioGen.WaitUntilDone(-1);

hsdioGen.Dispose();  // end task and clear memory

 

This proves that the WriteNamedWaveformWDT function is fine and can be called using C#.  Now, I need to rebuild my I2C drivers. 

 

There is an outside chance that I was not correctly generating the byte array that had to be passed to the WriteNamedWaveformWDT function - needs investigation.

 

Anand

 

P.S:  Thanks to Cole Reeder and all the other applicatoin engineers as well as the great folks at HSDIO R&D who helped put this together.

0 Kudos
Message 2 of 4
(3,615 Views)

Hi All,

 

Not sure if this is the culprit but I've found some difference in the way I typed in the PInvoke member WriteNamedWaveformWDT and the way National Instruments does.

 

My (previous) version

 

  public int WriteNamedWaveformWDT(string Waveform_Name, int Samples_To_Write, Int32 Data_Layout, System.Byte[] Data)

{

int pInvokeResult = PInvoke.WriteNamedWaveformWDT(this._handle, Waveform_Name, Samples_To_Write, Data_Layout, Data);

PInvoke.TestForError(this._handle, pInvokeResult);

return pInvokeResult;

}

 

NI's version

 

 public int WriteNamedWaveformWDT(string Waveform_Name, int Samples_To_Write, int Data_Layout, byte[] Data)

{

int pInvokeResult = PInvoke.WriteNamedWaveformWDT(this._handle, Waveform_Name, Samples_To_Write, Data_Layout, Data);

PInvoke.TestForError(this._handle, pInvokeResult);

return pInvokeResult;

}

 

I used System.Byte[] while NI's uses byte[].  Could this be the source of the problem?

 

Anand

0 Kudos
Message 3 of 4
(3,602 Views)

Hello Anand,

 

I am very happy to hear that you got everything up and working.  I think the difference (our culprit here) is that there are two parts of the wrapper.  The first is the PInvoke that you have in your code and the other is the actual DLL Inport Call.  With this inport call, the parameters are defined as System.Byte and Int32 instead of the Byte and int. Hope this helps to clear some things up.

ColeR
Field Engineer
0 Kudos
Message 4 of 4
(3,586 Views)