12-16-2016 09:05 AM
I am trying to find an example of reading the temperature directly from the USB port instead of using LabView or some other software. I have a program that is used for recording low temperature test data. At the moment the analyst has to manually enter the temperature before sending the data to the DB. I want the temperature to be read (maybe every 30 seconds) to eliminate human input. Just trying to establish a session caused an exception.
private UsbSession usbSession; public Temp() { GetSession("TempProbe"); } private void GetSession(string instName) { if (usbSession == null) { usbSession = new UsbSession(instName); } }
The instrument has been named TempProbe using NI Max. The test method said "Insufficient location information or the device or resource is not present in the system." I have not been able to find any examples or documentation. What I did find was over 6 years old and the example would not compile.
I am running Visual Studio 2013 professional, .Net 4.6.
Any help would be appreciated.
12-16-2016 09:31 AM
Hi Scott,
The device will appear in NI-Max as a DAQ device, not a USB device.
See the attached pdf for some example code in C# for the TC-01
Curt
12-20-2016 09:51 AM
Thank you for your reply. After some hassels with Bit9 I was able to get the proper DLL installed so I can use it from VS 2013 and I wrote a small sample to test the reading according to the example you linked to. But I am getting an error and can't figure out what it wants.
It says "Device Identifier is invalid." The inner exception says "Empty string suggested device(s): TempProbe"
I named the device TempProbe and when viewed in NI Max it shows as TempProbe. So I have
private void GetTempChannel()
{
Task tempTask = new Task();
try {
AIChannel myAIchannel = tempTask.AIChannels.CreateThermocoupleChannel(
"TempProbe",
"TempProbe",
0,
200,
AIThermocoupleType.J,
AITemperatureUnits.DegreesC);
AnalogSingleChannelReader tempReader = new AnalogSingleChannelReader(tempTask.Stream);
double analogDataIn = tempReader.ReadSingleSample();
CurrentTemp = analogDataIn;
}
catch (Exception e)
{
MessageBox.Show("Exception " + e.Message + "\n\n" + e.InnerException);
}
}
private double currentTemp;
public double CurrentTemp
{
get { return currentTemp; }
set
{
currentTemp = value;
}
}
Can you see anything wrong with this?
Thank you.
12-20-2016 10:29 AM
Hi,
When you plug the device in does it show up in NI-MAX as a device with a number, like "Dev1"?
try
AIChannel myAIchannel = tempTask.AIChannels.CreateThermocoupleChannel(
"Dev1",
"TempProbe",
0,
200,
AIThermocoupleType.J,
AITemperatureUnits.DegreesC);
Curt
12-20-2016 12:14 PM
No. It shows up as TempProbe. When you plug it into the USB a window, "NI USB-TC01 "TempProbe" - NI Device Monitor opens. If you look at the device in Computer it shows up as CD Drive (E:) NI USB-TC01.
12-20-2016 12:27 PM
Do you see anyhing like this in NI-MAX?
12-20-2016 01:14 PM
No. I discovered I can't do much until I update the firmware. That's going to require another delay while I get something else approved by security.
I'll respond then.
12-20-2016 01:50 PM
It was the Firmware problem all along. It is working quite well. Thank you sooooo much for your help.