07-02-2010 05:41 AM
Hi,
I am writing a .Net application that needs to read/write to an FPGA via DMA. To do this I've written some LabVIEW VIs that do the read/write, generated a .net interop assembly and successfully incorportated this into my application. The APIs generated by the LabVIEW builder are
public static void ReadDma32(int Channel, int DataBufferSize, out uint[] Data, out int NumberOfEntriesRead, out int ReadResult);
where the channel parameter identifies which DMA FIFO should be accessed. The ReadDma32 calls block until they have any data to return so it's an asynchronous process. This all works fine until I want to read from two different DMA channels at the same time. I then get a AccessViolationException with the message "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." I assume this is because of some marshalling issue when two different threads call the same method at the same time. I've tried changing the execution settings (reentrant execution) on the ReadDma32 vi but this has no effect.
Does anyone have any suggestion on how to solve this issue? My only idea so far is to remove the channel parameter from the method signature and have separate read/write dma methods for each DMA FIFO defined. Not very elegant.
thanks,
Ralph
public static void WriteDma32(int channel, uint[] data, out int writeResult);09-02-2010 07:57 AM
I am also getting same problem, have u got solution?
Mine is still simple case.
I have created interop dll for labview VI's.I am using interop dll in .NET environment.The method signature is public static void ReconstructRawData(byte COMPort, double[] FlowValuesFullScaleFlow, double[] TemperaturesC, ErrorCluster errorin, byte Gastype, bool ValueFormatrealunitsFalse, out ushort GasDensity, out double[,] RawData, out ushort MaxFlow, out ushort GasID, out ErrorCluster errorout);I am calling as shown belowbyte bComPort = byte.Parse("1");byte bGasType = byte.Parse("6");bool blnValueFromatFalse = false;ushort GasDensity = 0;double[,] RawData = new double[100, 100];//double[][] RawData = null;ushort MaxFlow = 0;ushort GasID = 0;ErrorCluster ErrorIn = new ErrorCluster();double[] dblFlowValue = new double[2];dblFlowValue[0] = 20;dblFlowValue[1] = 50;double[] dblTempValue = new double[2];dblTempValue[0] = 10;dblTempValue[2]= 20;But i am getting memory error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt"Stack Trace:at System.Runtime.InteropServices.Marshal.ReadInt32(IntPtr ptr, Int32 ofs)at System.Runtime.InteropServices.Marshal.ReadIntPtr(IntPtr ptr)at NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalArrayOut(Type arrayType, IntPtr data)at NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalOutputArray(IntPtr entryPointDataSpace, Type arrayType, Int32 terminalIndex)Now hot to send RawData(multidimentional array) to an method of interop dll?
09-02-2010 07:59 AM
I have created interop dll for labview VI's.I am using interop dll in .NET environment
.The method signature is
public static void ReconstructRawData(byte COMPort, double[] FlowValuesFullScaleFlow, double[] TemperaturesC, ErrorCluster errorin, byte Gastype, bool ValueFormatrealunitsFalse, out ushort GasDensity, out double[,] RawData, out ushort MaxFlow, out ushort GasID, out ErrorCluster errorout)
;I am calling as shown below
byte bComPort = byte.Parse("1");
byte bGasType = byte.Parse("6");
bool blnValueFromatFalse = false;
ushort GasDensity = 0;
double[,] RawData = new double[100, 100];
ushort MaxFlow = 0;
ushort GasID = 0;
ErrorCluster ErrorIn = new ErrorCluster();
double[] dblFlowValue = new double[2];dblFlowValue[0] = 20;dblFlowValue[1] = 50;
double[] dblTempValue = new double[2];dblTempValue[0] = 10;dblTempValue[2]= 20;
But i am getting memory error "Attempted to read or write protected memory.This is often an indication that other memory is corrupt"
Stack Trace:
at System.Runtime.InteropServices.Marshal.ReadInt32(IntPtr ptr, Int32 ofs)at System.Runtime.InteropServices.Marshal.ReadIntPtr(IntPtr ptr)at NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalArrayOut(Type arrayType, IntPtr data)at NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalOutputArray(IntPtr entryPointDataSpace, Type arrayType, Int32 terminalIndex)
Now hoW to send RawData(multidimentional array) to an method of interop dll?
09-03-2010 04:51 AM
Hi,
First of all I didn't use a multi-dimensional array but I'd be surprised if that made a difference.
I've managed to get the interop working now but there were two issues I had to overcome.
It's worth adding some logging before and after the interop calls or using a debugger so that you can be 100% certain the number of different threads that are calling the same static method at the same time.
Hope this helps.
Ralph