컴퓨터/C#
C# 시리얼 통신 프로그램
Begi
2020. 4. 28. 22:15
반응형
시리얼 통신을 구현하기 위해 컨트롤을 윈도우에 추가하여 하는 방법이 있고 다음과 같이 직접 코딩하는 방법도 있다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
using System;
using System.IO.Ports;
// 객체를 생성한다.
SerialPort com = new SerialPort();
// 시리얼 포트를 설정한다.
com.PortName = "COM1";
com.BaudRate = 9600;
com.DataBits = 8;
com.Parity = Parity.None;
com.StopBits = StopBits.One;
// 시리얼 포트를 연다.
com.Open();
// 시리얼 포트에서 값을 읽는다.
string s = com.ReadLine();
// 시리얼 포트에 값을 쓴다.
com.WriteLine("Hello");
// 시리얼 포트를 닫는다.
com.Close();
|
cs |
반응형