logo

English

이곳의 프로그래밍관련 정보와 소스는 마음대로 활용하셔도 좋습니다. 다만 쓰시기 전에 통보 정도는 해주시는 것이 예의 일것 같습니다. 질문이나 오류 수정은 siseong@gmail.com 으로 주세요. 감사합니다.

WIN CE C++ 시리얼 제어 방법

by digipine posted Oct 28, 2017
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

일반적인 시리얼포트 제어 방법은..

 

1. 포트를 생성하고..

HANDLE  hPort = CreateFile (lpszPortName,

                      GENERIC_WRITE,
                      0,

                      NULL,
                      OPEN_EXISTING,
                      0, 

                      NULL); 

 

2. 포트를 설정하고..

DCB PortDCB;

PortDCB.DCBlength = sizeof (DCB);

GetCommState (hPort, &PortDCB);

PortDCB.BaudRate = 9600;

PortDCB.fBinary = TRUE;
PortDCB.fParity = TRUE; 
PortDCB.fOutxCtsFlow = FALSE; 
PortDCB.fOutxDsrFlow = FALSE; 
PortDCB.fDtrControl = DTR_CONTROL_ENABLE;
PortDCB.fDsrSensitivity = FALSE;
PortDCB.fTXContinueOnXoff = TRUE;
PortDCB.fOutX = FALSE;               
PortDCB.fInX = FALSE;                
PortDCB.fErrorChar = FALSE;  
PortDCB.fNull = FALSE;            
PortDCB.fRtsControl = RTS_CONTROL_ENABLE;
PortDCB.fAbortOnError = FALSE;
PortDCB.ByteSize = 8;                
PortDCB.Parity = NOPARITY;   
PortDCB.StopBits = ONESTOPBIT;

 

if (!SetCommState (hPort, &PortDCB))
{
  dwError = GetLastError ();
  MessageBox (hMainWnd, TEXT("Unable to configure the serial port"),
              TEXT("Error"), MB_OK);
  return FALSE;
}

3. 타임아웃 설정하고..

COMMTIMEOUTS CommTimeouts;
GetCommTimeouts (hPort, &CommTimeouts);

CommTimeouts.ReadIntervalTimeout = MAXDWORD; 
CommTimeouts.ReadTotalTimeoutMultiplier = 0; 
CommTimeouts.ReadTotalTimeoutConstant = 0;   
CommTimeouts.WriteTotalTimeoutMultiplier = 10; 
CommTimeouts.WriteTotalTimeoutConstant = 1000;   

 

if (!SetCommTimeouts (hPort, &CommTimeouts))
{
  // Could not set the timeout parameters.
  MessageBox (hMainWnd, TEXT("Unable to set the timeout parameters"),
              TEXT("Error"), MB_OK);
  dwError = GetLastError ();
  return FALSE;
}

4. 포트에 제어 문자 출력

DWORD dwError,
      dwNumBytesWritten;

WriteFile (hPort,     &Byte,    1,    &dwNumBytesWritten,    NULL );

5. 포트 닫으면 끝

CloseHandle(hPort);

TAG •

List of Articles
No. Subject Author Date Views
104 공짜 무료 C/C++ 컴파일러들 file digipine 2017.10.28 4376
103 UML - 기본편 ( 기본 표기 형식 및 관계 표현법 ) digipine 2017.10.28 878
102 프로세스 능력 성숙도 모델(CMMI)의 적용 digipine 2017.10.28 698
101 ALM의 등장 배경, 오해와 진실 digipine 2017.10.28 376
100 CMM / CMMI 란 무엇인가? digipine 2017.10.28 2467
99 Thread간 동기화관리자 digipine 2017.10.28 572
98 Windows API - 안전한 문자열 함수들 digipine 2017.10.28 354
» WIN CE C++ 시리얼 제어 방법 digipine 2017.10.28 631
96 WIN CE, GPS - NMEA protocol - GPS Virtual Driver digipine 2017.10.28 2829
95 NMEA-0183을 이용한 GPS 애플리케이션 제작 digipine 2017.10.28 445
94 Windows에서 SVN 용 폴더 한 번에 삭제하기 digipine 2017.10.29 463
93 WinPCap과 Ethereal, Wireshark 을 이용한 스니핑(Sniffing) digipine 2017.10.29 5428
92 FFT (Fast Fourier Transform) 고속 푸리에 변환 예제 소스 digipine 2017.10.29 12544
91 Linux(리눅스) 파일 시스템 정리 (ext, ext2, ext3, ext4) digipine 2017.10.29 1107
90 Ubuntu Server OS 한국어 모드로 설치 후 서버 콘솔에서 한글 깨짐 해결 방법 digipine 2017.10.31 2240
89 QCAD 1.1 한국 최초의 2D CAD 소프트웨어 file digipine 2017.11.01 829
88 OpenAL 사용법 정리 1 digipine 2017.11.01 3397
87 WPA_SUPPLICANT 빌드 방법 digipine 2017.11.01 338
86 WPA_SUPPLICANT 빌드 방법 digipine 2017.11.01 544
85 Iconv 사용법 소스 digipine 2017.11.01 1262
Board Pagination Prev 1 2 3 4 5 6 Next
/ 6