12-06-2018 07:42 PM - edited 12-06-2018 08:06 PM
I have built a Labview (2012 SP1) .NET assembly with a function call which requires passing analog input channel. When calling the routine from Visual Studio 2013 I get "Attempted to read or write protected memory" with the stack trace pointing at an issue with MarshalLvDataAcquisitionChannelIn. If I remove parameters which pass in anything related to input/output channels the error goes away.
Installed DAQmx version is 15.5.1.
Stack trace:
at System.Runtime.InteropServices.Marshal.WriteInt32(IntPtr ptr, Int32 ofs, Int32 val) at System.Runtime.InteropServices.Marshal.WriteInt32(IntPtr ptr, Int32 val) at NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalStringIn(String value, IntPtr strHandle) at NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalLvDataAcquisitionChannelIn(LVDataAcquisitionChannel value, IntPtr data) at NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalStructIn(Object value, IntPtr data) at NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalArrayIn(Array value, IntPtr data) at NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalInputArray(IntPtr entryPointDataSpace, Array value, Int32 terminalIndex) at ST.MyClass.Execute(String SetupStr, LVPath CommandPath, LVCluster_1[*] InputChannelInThisCluster, LVCluster_2 InputChannelHereToo, Boolean bool1, Boolean bool2, ErrorCluster ErrorIn, Boolean bool3, LVReferenceNumber context, LVCluster_3[*] anotherCluster, LVCluster_4[*]& OutputChannelHere, LVCluster_5[*]& PIDResults, LVCluster_4[,]& OutputCahnnelHereAsWell, LVCluster_6[*]& Response, LVCluster_6[*]& MoreOfResponse, Boolean& bool4, Boolean& bool5, ErrorCluster& ErrorOut)
I create a voltage input channel this way:
Device mDevice1 = DaqSystem.Local.LoadDevice("Dev1");
mDevice1.Reset();
NationalInstruments.DAQmx.Task inputTask = new NationalInstruments.DAQmx.Task();
inputTask.AIChannels.CreateVoltageChannel(IS, "IS", (AITerminalConfiguration)(-1), -10, 10, AIVoltageUnits.Volts);
inputTask.Control(TaskAction.Verify);
Everything runs 32 bit (LabView and client .NET code) and client code is .NET 4.5.1 (tried .NET 2, 3.5, 4. , 4.5.) .
How do I correctly pass a LVDataAcquisitionChannel (as a part of a cluster/struct (?)) into the LabView .NET assembly?
Thank you