Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Temperature from USB TC01 C# WPF

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.

0 Kudos
Message 1 of 8
(4,050 Views)

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

0 Kudos
Message 2 of 8
(4,039 Views)

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.

0 Kudos
Message 3 of 8
(3,994 Views)

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

0 Kudos
Message 4 of 8
(3,989 Views)

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.

0 Kudos
Message 5 of 8
(3,988 Views)

Do you see anyhing like this in NI-MAX?

 

 

 

 

0 Kudos
Message 6 of 8
(3,986 Views)

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.

0 Kudos
Message 7 of 8
(3,983 Views)

It was the Firmware problem all along. It is working quite well. Thank you sooooo much for your help.

0 Kudos
Message 8 of 8
(3,980 Views)