09-22-2017 11:18 AM
I am trying to get the temperature from a thermocouple and display it on my main window. It works perfectly on my computer. The temperature updates every two seconds as it is supposed to. I had previously posted a question about required DLLs for this to work on the lab computers which do not have NI software installed. I was told I needed to install the NIDaq Runtime engine. I installed that but still got the error:
"System.IO.FileLoadException: A procedure imported by 'NationalInstruments.DAQmx.dll' could not be loaded."
The stack trace takes it back to the constructor where I call the "Watch Temperature" method which does the following.
try
{
TempScanner = new Thermocouple();
TempWorker = new BackgroundWorker();
TempWorker.WorkerReportsProgress = true;
TempWorker.WorkerSupportsCancellation = true;
TempWorker.DoWork += (s, e) =>
{
TempScanner.TempWorker = TempWorker;
TempScanner.MonitorTemp(ref watchTemp);
};
TempWorker.ProgressChanged += (s, e) =>
{
var t = e.UserState as Temperature;
this.Temperature = t.Temp;
};
TempWorker.RunWorkerCompleted += (s, e) =>
{
TempWorker = null;
TempScanner = null;
};
TempWorker.RunWorkerAsync();
}
The critical parts of the thermocouple class are shown below.
public Thermocouple()
{
//These are the default values.
SecondsDelay = 2;
MinimumTemp = -70;
MaximumTemp = 200;
List<string> chnls = GetPhysicalChannels();
PhysicalChannelName = chnls[0];
string[] ary = chnls[0].Split('/');
AssignedChannelName = ary[0];
ThermocoupleType = AIThermocoupleType.J;
tempChannel = tempTask.AIChannels.CreateThermocoupleChannel(
PhysicalChannelName, AssignedChannelName, MinimumTemp, MaximumTemp, ThermocoupleType, AITemperatureUnits.DegreesC);
tempReader = new AnalogSingleChannelReader(tempTask.Stream);
}
public void MonitorTemp(ref bool watchTemp)
{
while (watchTemp)
{
if (!TempWorker.CancellationPending)
{
Temperature t = new Temperature();
t.Temp = GetTemp();
TempWorker.ReportProgress(100, t);
t = null;
Thread.Sleep(milliseconds);
}
else
{
tempReader = null;
tempChannel = null;
tempTask = null;
}
};
}
The runtime engine I installed was NIDAQ1410f1Runtime.
As you can see it is not all that complex. There must be a simple solution to this problem.
Thank you
09-25-2017 12:53 PM
What version of the DAQmx do you have on the working computer? It sounds like the development computer has a version newer than 14.1, and you just need a newer version of the runtime.
If it turns out to be a version conflict, you can download the latest version of the runtime here:
NI-DAQmx Runtime 17.1.0
http://www.ni.com/download/ni-daqmx-run-time-engine-17.1/6838/en/