Overview   Project   Class   Tree   Deprecated   Index 
FRAMES    NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD

dcl
Class SerialPort

Object
   |
   +--File
         |
         +--PollAble
               |
               +--SerialPort

   in SerialPort.h

class SerialPort
extends PollAble

직렬포트 관련 장치파일을 구성하고 접근한다.

직렬포트에 대한 파일명은 UNIX에서 /dev/tty#N, /dev/ttyS#N, /dev/ttyUSB#N 과 같은 것들이고, Windows에서는 COM#N 등 이다.

Linux에서 직렬포트는 프로세스가 uucp그룹에 포함되어 있지 않으면 접근이 거부되므로 확인한다.

이 클래스는 직렬포트의 Non-Blocking 입출력에 대하여 준비되어 있다. 자세한 사용방법은 SerialPollThread를 참고한다.

USB-Serial 장치를 사용하는 경우 실행시간에 포트가 제거될 수 있다. UNIX의 경우 onEvent(Events _events, SerialPollThread* _pWatcher)의 _events에 POLLHUP가 전달 되고, Windows의 경우 File::read(void* _buf, size_t _n), File::write(const void* _buf, size_t n)의 호출 과정에서 예외를 처리해야 한다. Windows 에러코드는 ERROR_ACCESS_DENIED (5)이다.

See Also:
PollAble, SerialPollThread

Inner Classes, Typedefs, and Enums
enum SerialPort::BaudRate
          
enum SerialPort::ByteSize
          
enum SerialPort::FlowControl
          
enum SerialPort::PurgeFlag
          
enum SerialPort::StopBits
          
   
Fields inherited from class PollAble
__events
   
Fields inherited from class File
__path, __handle, __closeOnClose, __fileType, __readEvent, __writeEvent
 
Constructor Summary
SerialPort( const String& _path, bool _nonBlocking, size_t _inQueue = 4096, size_t _outQueue = 4096 )
          주어진 경로의 포트를 열고 객체를 구성한다.
virtual ~SerialPort()
          
 
Method Summary
 static bool access( const String& _path )
          주어진 경로의 가능 여부를 확인한다.
protected virtual bool onEvent( short _revents, PollThread* _pPollThread )
          SerialPollThread에의해 감시되다가 이벤트가 발생되었을 때 호출된다.
 void open( const String& _path, bool _nonBlocking, size_t _inQueue = 4096, size_t _outQueue = 4096 )
          주어진 경로의 포트를 연다.
 void purge( int _flags )
          전송되지 않거나, 또는 읽혀지지 않는 데이터를 버린다.
 void setAttributes( SerialPort::BaudRate _baudRate = BR_38400, SerialPort::ByteSize _byteSize = BS_8NO, SerialPort::StopBits _stopBits = SB_1, SerialPort::FlowControl _flowControl = FC_NONE )
          

포트의 속성을 설정한다.

   
Methods inherited from class PollAble
onEvent
   
Methods inherited from class File
toString, open, open, sync, close, available, read, write, seek, getSize, handle, path, fileType, access, rename, unlink, exists, getSize, getBaseName, getDirName, getDirDelimeter, isDirDelimeter, makeFileName, getTempDir, openTempFile, closeTempFile, getRealPath, getUnixPath, getWinPath, isAbsPath, readText
   
Methods inherited from class Object
toString, destroy, className, isInstanceOf, typeInfo
 

Constructor Detail

SerialPort

public SerialPort( const String& _path, bool _nonBlocking, size_t _inQueue = 4096, size_t _outQueue = 4096 ) throw( IOException* );
주어진 경로의 포트를 열고 객체를 구성한다.
See Also:
open(const String& _path, bool _nonBlock, size_t _inQueue, size_t _outQueue)}

~SerialPort

public virtual ~SerialPort();


Method Detail

access

public static bool access( const String& _path );
주어진 경로의 가능 여부를 확인한다.

UNIX에서는 access(R_OK | W_OK)로 확인하고, Windows에서는 경로를 열어보고 그 결과를 반환한다.


onEvent

protected virtual bool onEvent( short _revents, PollThread* _pPollThread ) throw( IOException* );
SerialPollThread에의해 감시되다가 이벤트가 발생되었을 때 호출된다.

open

public void open( const String& _path, bool _nonBlocking, size_t _inQueue = 4096, size_t _outQueue = 4096 ) throw( IOException* );
주어진 경로의 포트를 연다.

파일을 열때 플래그는 File::READWRITE | File::NOCTTY 가 기본으로 사용되고, _nonBlocking이 true이면, File::NONBLOCK이 함께 사용된다.

_inQueue, _outQueue는 Windows에만 사용하고 그 외에는 무시된다. 자세한 내용은 SetupComm 을 참고한다.


purge

public void purge( int _flags ) throw( IOException* );
전송되지 않거나, 또는 읽혀지지 않는 데이터를 버린다.

setAttributes

public void setAttributes( SerialPort::BaudRate _baudRate = BR_38400, SerialPort::ByteSize _byteSize = BS_8NO, SerialPort::StopBits _stopBits = SB_1, SerialPort::FlowControl _flowControl = FC_NONE ) throw( IOException* );

포트의 속성을 설정한다.

SerialPort port(String(_T("/dev/ttyS0"), false);
port.setAttributes(SerialPort::BR_9600, SerialPort::BS_8NO, SerialPort::SB_1, SerialPort::FC_NONE);
    ...

 Overview   Project   Class   Tree   Deprecated   Index 
FRAMES    NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD