Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics NI USB-TC01 Thermocouple Measurement Device HANS- PETTER HALVORSEN, 2013.02.18 Faculty of Technology, Postboks 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01
Table of Contents Table of Contents... ii Preface... 1 1 Introduction... 1 2 System Description... 5 2.1 Documentation... 5 3 Configuration... 6 3.1.1 Testing the NI USB- TC01 in MAX... 6 4 Using TC01 in LabVIEW... 8 4.1 NI- DAQmx... 8 4.1.1 DAQ Assistant... 9 5 Using TC01 in Visual Studio and C#... 14 5.1 DAQmx... 14 5.2 C# Example... 15 6 Using TC01 with Measurement Studio... 19 6.1 DAQmx Driver... 19 6.2 Measurement Studio... 19 6.3 Create a NI Windows Application... 19 6.4 Create a NI DAQ Windows Application... 23 ii
Preface You will find this document and lots of other information in the following web site: http://home.hit.no/~hansha/?equipment=tc01 In order to use the NI TC- 01 Thermocouple device you need to install the DAQmx driver. You can use the TC- 01 device with LabVIEW or with Visual Studio. We can also use the device with Measurement Studio, which is an add- on to Visual Studio. Så the different alternatives are as follows: A - Using LabVIEW: 1. LabVIEW + DAQmx driver (Chapter 4) B - Using Visual Studio/C#: 2. Visual Studio + DAQmx driver (Chapter 5) 3. Visual Studio + DAQmx driver + Measurement Studio (Chapter 6) In this document we go through all these alternatives. 1
1 Introduction Below (Figure 1) we see the NI USB- TC01 Thermocouple Measurement device. Figure 1: NI USB- TC01 Thermocouple Measurement Device The NI USB- TC01 provides connections for one thermocouple. Thermocouple types J, K, R, S, T, N, E, and B are supported. At TUC we will use the J type. The NI USB- TC01 software support for Windows 7/Vista/XP is provided by the device. No separate driver installation is required for operation. Below (Figure 2) we see the different components that NI USB- TC01 Thermocouple is part of: Figure 2: NI USB- TC01 Thermocouple Components 1
Introduction The following window (Figure 3) should pop up automatically when you plug in your NI USB- TC01 device in your USB port: Figure 3: NI USB- TC01 Launch Screen If not this window pops up automatically, we need to start it manually, see Figure 4below: Figure 4: NI USB- TC01 appears as a separate drive in your Windows Explorer
Introduction Select TC01Launcher.exe and the Launch Screen in Figure 3 will appear. From the Launch Screen the following are available (Figure 5): LabVIEW Example (Figure 6 and Figure 7): Figure 5: Temperature Logger
Introduction Figure 6: LabVIEW Example Front Panel Figure 7: LabVIEW Example Block Diagram
2 System Description Below (Figure 8) we see the NI USB- TC01 Thermocouple Measurement device. Figure 8: NI USB- TC01 Thermocouple Measurement Device 2.1 Documentation The documentation for the NI USB- TC01 device is as follows: NI USB- TC01 User Guide and Specifications NI USB- TC01 Data Sheet NI USB- TC01 Calibration Procedure These documents are available from www.ni.com (or just Google them) 5
3 Configuration Configuring and testing: NI USB- TC01 can be configured and tested using MAX (Measurement and Automation Explorer), which is installed with the NI- DAQmx Driver Software. 3.1.1 Testing the NI USB-TC01 in MAX Before you start to use the NI USB- TC01 in an application, you should test the device in the Measurement and Automation Explorer (MAX), see Figure 9. Figure 9: MAX In the MAX window, expand the Devices and Interfaces node. Right- click on the NI USB- TC01 device and select Self- Test (Figure 10). 6
7 Configuration Figure 10: Self Test Hopefully the self- test passes without errors. Then, you should test the device using the Test Panels (Figure 11). Figure 11: Test Panels
4 Using TC01 in LabVIEW Software requirements: LabVIEW + DAQmx driver 4.1 NI-DAQmx In order to use the NI USB- TC01 in LabVIEW you need to use the DAQmx functions, see Figure 12 below. Figure 12: NI- DAQmx 8
9 Using TC01 in LabVIEW DAQmx Data Acquisition palette (Figure 13): Figure 13: DAQmx Palette in LabVIEW 4.1.1 DAQ Assistant The easiest ways is to use the DAQ Assistant. When you drag the DAQ Assistant icon on your Block Diagram, the following window appears (Figure 14): Figure 14: DAQ Assistant Wizard Select Signal Type
10 Using TC01 in LabVIEW In this window you need to select Acquire Signals and Thermocouple. In the next window (Figure 15) you select the channels, and in this case there is only one channel available (AI0). Figure 15: DAQ Assistant Wizard Select Channel When clicking Finish, the following window appears (Figure 16):
11 Using TC01 in LabVIEW Figure 16: DAQ Assistant - Properties In the Timing Settings, select 1 Sample (On Demand). You are now finished with the configuration. Click OK in the DAQ Assistant window The DAQ Assistant icon appears on the Block Diagram: Example: Wire the data output to a numeric indicator like this (and hit the Run button):
12 Using TC01 in LabVIEW Then numeric indicator will show, e.g., the following value: If you want a continuous acquisition, put a While loop around the DAQ Assistant like this: However you should not use the DAQ Assistant inside a loop because of the lack of performance. The following is therefore better: In this example we have put the DAQ Assistant outside the While loop. Inside the loop we have used the DAQmx Read.vi in order to read the value from the ai0 channel.
13 Using TC01 in LabVIEW You should also use the DAQmx Start Task.vi and the DAQmx Clear Task.vi. [End of Example]
5 Using TC01 in Visual Studio and C# Software requirements: Visual Studio + DAQmx driver 5.1 DAQmx In order to use the NI USB- TC01 Thermocouple Measurement device with C# we need to have the DAQmx driver and the DAQmx API for C# installed. Note! In order to install the DAQmx API for C#, make sure to select.net Support when installing the DAQmx driver. This application uses the C# API included in the NI DAQmx driver, so make sure that you have installed the NI DAQmx driver in advance. During the installation makesure to select Custom : 14
15 Using TC01 in Visual Studio and C# Next, make sure that you select.net Framework X.x Support for the version of.net that yourversion of Visual Studio id using: 5.2 C# Example We vill create the following simple application: Add Reference: We need to add the following Assembly references: NationalInstruments.Common
16 Using TC01 in Visual Studio and C# NationalInstruments.DAQmx We add References by right- clicking the References node in the Solution Explorer: When we have added the necessary References, the Solution Explorer will look like this: The dlls are normally to find here:
17 Using TC01 in Visual Studio and C# Initialization: We need to add the following Namespaces: using NationalInstruments; using NationalInstruments.DAQmx; Add Code: Enter the following code lines: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using NationalInstruments; using NationalInstruments.DAQmx; namespace TC01_DAQ_Example { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btngetdata_click(object sender, EventArgs e) { Task temperaturetask = new Task(); AIChannel myaichannel; myaichannel = temperaturetask.aichannels.createthermocouplechannel( "Dev1/ai0", "Temperature", 0, 100, AIThermocoupleType.J, AITemperatureUnits.DegreesC, 25 ); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(temperatureTask.Stream); double analogdatain = reader.readsinglesample(); txttempdata.text = analogdatain.tostring(); } } } Test your application: Run your application. When clicking the button, you should now retrieve data from the temoerature device. Error?
18 Using TC01 in Visual Studio and C# If your application runs without error that s fine, but perhaps you get the following error: In order to fix the problem, open the Properties for your project: Make sure to select.net Framework X in the Target framework drop- down menu.
6 Using TC01 with Measurement Studio Software requirements: Visual Studio + DAQmx driver + Measurement Studio 6.1 DAQmx Driver In order to use the NI USB- TC01 Thermocouple Measurement device with C# we need to have the DAQmx driver and the DAQmx API for C# installed. Note! In order to install the DAQmx API for C#, make sure to select.net Support when installing the DAQmx driver. 6.2 Measurement Studio C# is a powerful programming language, but has few built- in features for measurement and control applications. Measurement Studio is an add- on to Visual Studio which makes it easier to create such applications. With Measurement Studio we can implement Data Acquisition and a graphical HMI. You don t need to use the Measurement Studio to create an application where you use the NI USB- TC01 Thermocouple Measurement device (as shown in previous chapter), but it is easier. Here we will use Visual Studio and the Measurement Studio Add- in to create some DAQ examples where we get temperature data from the NI USB- TC01 Thermocouple Measurement device. 6.3 Create a NI Windows Application In this example, we will select the NI windows Application Template in the New Project window (Error! Reference source not found.). 19
20 Using TC01 with Measurement Studio Figure 17: NI Windows Application Note! The New Project window may look different on your computer, it depends on what features you have installed and which version or edition of Measurement Studio you are using. Next we select the Class Libraries we want to include. In our case we need at least to select the DAQmx Library (Error! Reference source not found.). Figure 18: Measurement Studio Class Libraries
21 Using TC01 with Measurement Studio When we click Finish an empty project will be created for us. We are now ready to create our own application. We start by creating a simple User Interface (Error! Reference source not found.): Figure 19: Simple User Interface for reading Temperature Data When we click the Read Temp button, the Temperature data shall be shown in the Temp Data TextBox. In the event Handler for the Read Temp button, we create the following code: private void btnreadtempdata_click(object sender, EventArgs e) { Task analogintask = new Task(); AIChannel myaichannel; myaichannel = analogintask.aichannels.createthermocouplechannel( "Dev1/ai0", "Temperature", 0, 100, AIThermocoupleType.J, AITemperatureUnits.DegreesC, 25 ); } AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogInTask.Stream); double analogdatain = reader.readsinglesample(); txttempdata.text = analogdatain.tostring(); Then we can test our application:
22 Using TC01 with Measurement Studio Improvements: We should use a Timer in order to read Temperature data at specific intervals instead of pushing a button each time we need data. We drag in a Timer component from the Toolbox. First, we need to start the Timer: public Form1() { InitializeComponent(); } timer1.start(); Next, we need to specify the interval. We can do that in the Properties window: In the Timer Event we write the code for reading the Temperature: private void timer1_tick(object sender, EventArgs e) { Task analogintask = new Task(); AIChannel myaichannel; myaichannel = analogintask.aichannels.createthermocouplechannel( "Dev1/ai0", "Temperature", 0,
23 Using TC01 with Measurement Studio 100, AIThermocoupleType.J, AITemperatureUnits.DegreesC, 25 ); AnalogSingleChannelReader reader = new AnalogSingleChannelReader(analogInTask.Stream); double analogdatain = reader.readsinglesample(); } txttempdata.text = analogdatain.tostring("0.0"); Finally, we test the application: Congratulations, you have created your first DAQ application using Measurement Studio. 6.4 Create a NI DAQ Windows Application Note! This option is only availible if you to have either the Professional or Enterprise version of the Measurement Studio software. We start by creating a New Project from Visual Studio. In the New Project window (Figure 20) we select Visual C#» Measurement Studio, and then select the NI DAQ Windows Application Template that is part of the Measurement Studio.
24 Using TC01 with Measurement Studio Figure 20: New Project Window in Visual Studio Note! The New Project window may look different on your computer, it depends on what features you have installed and which version or edition of Measurement Studio you are using. Next, we need to go through different steps in a wizard. In the first step we select Create a new project task (Figure 21): Figure 21: Add DAQ Component In the next step we select the measurement type (Figure 22), and since the NI USB- TC01 Thermocouple Measurement device is for reading Temperature values, we need to select Acquire Signals.
25 Using TC01 with Measurement Studio Figure 22: Select Measurement Type In the Acquire Signals node we first select Temperature and then select Thermocouple. Figure 23: Thermocouple Next we need to select the physical channel(s), Figure 24. Since the NI USB- TC01 Thermocouple Measurement device has only one channel available, we need to select ai0 (Analog In, Channel 0).
26 Using TC01 with Measurement Studio Figure 24: Select Physical Channels Next we can set different Properties (Figure 25), such as Input Range, Acquisition Mode, Thermocouple Type, etc.
27 Using TC01 with Measurement Studio Figure 25: Properties Finally we see a Preview of the User Interface before it is automatically generated by the Measurement Studio (Figure 26):
28 Using TC01 with Measurement Studio Figure 26: Preview of User Interface When we click Finish, the Solution, the Project and User Interface will be automatically created (Figure 27). Finally we can test the Application (Figure 28): Figure 27: Visual Studio Generated Solution
29 Using TC01 with Measurement Studio Figure 28: Test of Application With this approach we get a flying start and we can change the code as we please. The drawback with this approach is that the code that is automatically generated is a little bit messy. So actually, this is not a method I will recommend to use.
Telemark University College Faculty of Technology Kjølnes Ring 56 N- 3918 Porsgrunn, Norway www.hit.no Hans- Petter Halvorsen, M.Sc. Telemark University College Faculty of Technology Department of Electrical Engineering, Information Technology and Cybernetics E- mail: hans.p.halvorsen@hit.no Blog: http://home.hit.no/~hansha/