티스토리 뷰
목차
NI 온도 측정 프로그램 (C# 프로그래밍, NI TC-01 USB)
이 글은 NI에서 공식 발행한 C# 메뉴얼에서 발췌한 내용입니다. 전체 내용은 링크된 pdf 파일에서 확인하세요.
[NI DAQ C# 프로그래밍]
4 Temperature Logging Example (온도 측정 프로그램)
In this example we will use a NI TC-01 USB Thermocouple device. We will create the following simple application:
[NI 온도 측정 프로그램]
Add Reference:
We need to add the following Assembly references:
- NationalInstruments.Common
- NationalInstruments.DAQmx
We add References by right-clicking the References node in the Solution Explorer:
[NI 온도 측정 프로그램]
When we have added the necessary References, the Solution Explorer will look like this:
[NI 온도 측정 프로그램]
The dlls are normally to find here:
[NI 온도 측정 프로그램]
Initialization:
We need to add the following Namespaces:
1 2 | using NationalInstruments; using NationalInstruments.DAQmx; | cs |
Add Code:
Enter the following code lines:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 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(); } } | cs |
Test your application:
Run your application. When clicking the button, you should now retrieve data from the temoerature device.
Error?
If your application runs without error that’s fine, but perhaps you get the following error:
[NI 온도 측정 프로그램]
In order to fix the problem, open the Properties for your project:
[NI 온도 측정 프로그램]
Make sure to select “.NET Framework X” in the “Target framework” drop-down menu.
NI 온도 측정 프로그램 (C# 프로그래밍, NI TC-01 USB)