본문 바로가기
C++ 200제/코딩 IT 정보

NI 온도 측정 프로그램 (C# 프로그래밍, NI TC-01 USB)

by vicddory 2018. 1. 27.

NI 온도 측정 프로그램 (C# 프로그래밍, NI TC-01 USB)



이 글은 NI에서 공식 발행한 C# 메뉴얼에서 발췌한 내용입니다. 전체 내용은 링크된 pdf 파일에서 확인하세요.


daq ni 프로그래밍 c#[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 daq 온도측정 visual studio 프로그래밍[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 온도 측정 프로그래밍 프로그램[NI 온도 측정 프로그램]


When we have added the necessary References, the Solution Explorer will look like this:


ni 온도측정 dll 비주얼 스튜디오 연동[NI 온도 측정 프로그램]


The dlls are normally to find here:


ni 온도측정 visual studio c#[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:


visual studio ni 온도측정[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)

댓글