09-08-2011 12:39 PM
I am using NI usb 6211, based on .NET2.0
Here is my code:
using NationalInstruments.DAQmx;
using (Task digitalWriteTask = new Task())
{ // Create an Digital Output channel and name it.
digitalWriteTask.DOChannels.CreateChannel("Dev1/Port1/line0", "",ChannelLineGrouping.OneChannelForAllLines);
// Write digital port data. WriteDigitalSingChanSingSampPort writes a single sample
// of digital data on demand, so no timeout is necessary.
DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter(digitalWriteTask.Stream);
writer.WriteSingleSamplePort(true, 3); }
when using (Task digitalWriteTask = new Task()) is called, error shows:
MissingMethodException: Method contains unsupported native code
<Module>.<CrtImplementationDetails>.LanguageSupport.Initialize (<CrtImplementationDetails>.LanguageSupport* )
<Module>..cctor ()
Anyone knows what is wrong here?
Thanks.
09-08-2011 06:25 PM
Annie,
I could not reproduce this error. I copied and pasted your code and did not receive the error. Could you post more of your code? Maybe a small project that reproduces this error.
09-09-2011 02:02 AM
Thank you for looking into my problem.
I probably have to mention that I use MonoDevelop as IDE here.
Is there some sort of compatibility issue here? Somehow .dll files (nationalinstruments.daqmx.dll, nationalinstruments.common.dll, nationalinstruments.common.native.dll) use .net native code thats not present in mono?
09-09-2011 04:30 AM
I used traditional NI-DAQ plus VC to control NI card,
except for .dll files, we have to specify in head files the library nidaq32.lib, nidex32.lib.
I am wondering whether, in NI-DAQmx + .Net, there is an equivalent definition?
09-09-2011 07:53 AM
I got NIDAQmx.lib from C:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\lib32 and \include
and also add all dll files (nationalintruments.daqmx.dll, nationalintruments.common.dll, nationalintruments.common.native, dll);
but still catch error message:
An exception was thrown by the type initializer for <Module>
when I try to create the task.
Here is my code:
using System.Collections;
using System;
using NationalInstruments.DAQmx;
using System.IO;
public class IO_control_NI : MonoBehaviour {
void Start () { }
void Awake() { }
// Update is called once per frame
public void performActions(int cont_v)
{
if (cont_v == 2) // reward deliver
{
try
{
// private DigitalSingleChannelWriter digitalWriter;
using (Task digitalWriteTask = new Task())
{
digitalWriteTask.DOChannels.CreateChannel("Dev1/Port1/line0", "",ChannelLineGrouping.OneChannelForAllLines);
DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter(digitalWriteTask.Stream);
writer.WriteSingleSamplePort(true, 3);
}
}
catch (Exception ex)
{
var sw = new StreamWriter("nierror.txt",true);
sw.WriteLine(ex.Message);
sw.Close();
}
}
}
}
09-09-2011 06:26 PM
Unfortunately, NI-DAQmx does not support development in Mono. Our DAQmx .NET assemblies are mixed-mode, which is probably why you are running into problems. It may be possible to get it to work in Mono, but I do not understand enough about Mono to really help much. It is my understanding that there is little to no support for mixed-mode assemblies in Mono (although it is a heavily requested feature). Currently National Instruments does not provide any support for this.