SerialPort with C#

SerialPort통신을 할일이 생겨서 C#으로 만지작 거리는데

System.IO.Ports를 호출하면 해결.
예제 소스에서는 thread를 돌려서 데이터 통신을 하던 데 , SerialDataReceivedEventHandler이벤트를 하면 thread를 따로 만들지 않아도 매번 이벤트를 호출한다.

HEXA값을 주고 받는 일이라 SerialPort.Write(), Read() 모두 byte[]로 전달.


_port = new SerialPort();
_port.Encoding = Encoding.GetEncoding(28591);
port.PortName = comboport.SelectedItem.ToString();
_port.BaudRate = 9600;
_port.DataBits = 8;
_port.DataReceived += new SerialDataReceivedEventHandler(Read);

_port.Open();

_port.ReadTimeout = 500;
_port.WriteTimeout = 500;

멋지다 C#!

Tags:

2 Comments »

  1. 빈태 said,

    May 31, 2007 @ 12:58 pm

    델빠에서는 호랑이 담배 피던 시절에 다되던 거3…
    것도 공짜 컴포넌트로
    아마 시렬로 값이 오갈때 이벤트로도 처리할수 있다지???

  2. illtal said,

    June 4, 2007 @ 9:11 pm

    델빠 유저가 아니라서 무효. C#에 디펜던트한 나요.

RSS feed for comments on this post · TrackBack URI

Leave a Comment