13.1.6. cesOpenPort


SYNOPSYS

t_i32 cesOpenPort(
      [in] t_i32 nNodeID,
      [in] t_i32 nChannel,
      [out] t_i32  nSerType,
      [in] t_i32 nBaudId,
      [in] t_i32 nDataBits,
      [in] t_i32 nStopBits,
      [in] t_i32 nParity,
  )

DESCRIPTION

  • 해당 채널(Port) 을 할당하고 시리얼 통신 설정을 통해 통신 포트 Open 후 사용할 준비를 합니다.

PARAMETER

  • nNodeID : 원격 노드 ID

  • nChannel : 채널 번호

  • nSerType : 시리얼 통신 모드

Value

Meaning

0

RS-232

1

RS-422

2

RS-485

  • nBaudId : 시리얼 통신시 사용할 기 정의된 Baud Rate 인식 번호

Value

Meaning

0 (BAU D_2400)

Baud Rate 2400

1 (BAUD_4800)

Baud Rate 4800

2 (BAUD_9600)

Baud Rate 9600

3 (BAUD_14400)

Baud Rate 14400

4 (BAUD_19200)

Baud Rate 19200

5 (BAUD_38400)

Baud Rate 38400

6 (BAUD_57600)

Baud Rate 57600

7 (BAUD_115200)

Baud Rate 115200

  • StopBits : Stop Bits 에 대한 설정 값이며 1 또는 2 의 값을 설정

  • nParity : Parity Bits 에 대한 설정 값이며 0 (패러티 없음), 1 (홀수 패러티), 2 (짝수 패러티) 의 값을 설정할 수 있다.

RETURN VALUE

  • 함수 호출 여부를 반환합니다.

Value

Meaning

음수

수행 실패

0 (ceERR_NONE)

수행 성공

EXAMPLE

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include "ceSDK.h"
#include "ceSDKDef.h"
long nSerialChNo = 0; // 시리얼 채널(Port) 번호
long nSerType = 0; // 시리얼 통신 모드. 0: RS232, 1: RS422, 2: RS485
long nBaudId = BAUD_9600; // Baud Rate 설정. 0 ~ 7 번 모드
long nDataBits = 8; // Data Bits 설정. 5 ~ 8
long nStopBits = 1; // Stop Bits 설정. 1 or 2
long nParity = 1; // Parity Bits 설정. 0: None, 1: Odd, 2: Even

// 0 번 시리얼 포트를 Open 합니다.
 if ( cesOpenPort ( nSerialChNo, nSerType, BAUD_9600, nDataBits, nStopBits, nParity ) != ceERR_NONE )
 {
 OutputDebugString ( "cesOpenPort has been failed" );
 }