// RT.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
int main(void)
{
char szPort[15]; //포트명을 저장할 변수
wsprintf(szPort,"com%d", 2); // 2번포트로 통신
//Comm device를 File Open과 같은 방법으로 연결
HANDLE m_hComm = NULL; //통신 포트 핸들
m_hComm = CreateFile( szPort,GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (m_hComm == INVALID_HANDLE_VALUE)
{
printf("(!) Failed to create a Comm Device file.");
return FALSE;
}
DCB dcb;
dcb.DCBlength = sizeof(DCB);
GetCommState(m_hComm, &dcb); //DCB 초기갑
dcb.BaudRate = 9600; //전송속도
dcb.ByteSize = 8; //데이터비트 4~8
dcb. Parity = 0; //Parity 0~4 = no, odd, even, mark, space
dcb.StopBits = 0; //StopBits 0,1,2 = 1, 1.5, 2
SetCommState(m_hComm, &dcb); //DCB변경
OVERLAPPED osWrite;
osWrite.Offset = 0;
osWrite.OffsetHigh = 0;
osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
char buf[100];
while(1)
{
WriteFile(m_hComm, buf, strlen(buf), NULL, &osWrite);
printf("send1:%s",buf);
Sleep(1000);
}
CloseHandle(m_hComm);
return 0;
}
'임베디드' 카테고리의 다른 글
AVR용 USB타입 ISP툴 FT232BL 드라이버 (0) | 2009.10.15 |
---|---|
AVR실습 윈도우 기반의 직렬통신(Read) (0) | 2009.07.14 |
AVR실습 직렬통신 (0) | 2009.07.14 |
AVR실습 외부 EEPROM쓰기 (0) | 2009.07.08 |
AVR 실습 내부 EEPROM 쓰기 (0) | 2009.07.07 |
댓글