DCL 4.0
Loading...
Searching...
No Matches
SerialPort Class Reference

#include <SerialPort.h>

Inheritance diagram for SerialPort:
PollAble File Object

Static Public Member Functions

static bool access (const String &_path)
Static Public Member Functions inherited from File
static FileopenTempFile (const String &_dirname, const String &_prefix, unsigned int _mode=0666) __DCL_THROWS1(IOException *)

Protected Member Functions

virtual bool onEvent (short _revents, PollThread *_pPollThread) __DCL_THROWS1(IOException *)
Protected Member Functions inherited from File
 File ()
 File (HandleType _handle, const String &_path)
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Additional Inherited Members

Public Types inherited from File
enum  Whence { BEGIN , CURRENT , END }
Public Member Functions inherited from File
virtual String toString () const
virtual ~File ()
 File (const String &_path, int _oflags=READONLY, int _mode=0666) __DCL_THROWS1(IOException *)
void open (const String &_path, int _oflags=READONLY, int _mode=0666) __DCL_THROWS1(IOException *)
 File (HandleType _handle, int _ohints, bool _closeOnClose) __DCL_THROWS1(IOException *)
void open (HandleType _handle, int _ohints, bool _closeOnClose) __DCL_THROWS1(IOException *)
virtual void sync () __DCL_THROWS1(IOException *)
virtual void close () __DCL_THROWS1(IOException *)
virtual size_t available () const __DCL_THROWS1(IOException *)
virtual size_t read (void *_buf, size_t _n) __DCL_THROWS1(IOException *)
virtual size_t write (const void *_buf, size_t _n) __DCL_THROWS1(IOException *)
off_t seek (off_t _offset, int _whence) __DCL_THROWS1(IOException *)
off_t size () const __DCL_THROWS1(IOException *)
DateTime mtime () const __DCL_THROWS1(IOException *)
bool time (time_t *_atime, time_t *_mtime, time_t *_ctime) const
HandleType handle () const
const String & path () const
Public Member Functions inherited from Object
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const
Protected Attributes inherited from File
String __path
HandleType __handle
bool __closeOnClose

Detailed Description

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

직렬포트에 대한 파일명은 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

Definition at line 51 of file SerialPort.h.

Member Function Documentation

◆ access()

bool SerialPort::access ( const String & _path)
static

주어진 경로의 가능 여부를 확인한다.

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

Definition at line 245 of file SerialPort.cpp.

246{
247#if __DCL_WINDOWS
248 SECURITY_ATTRIBUTES securityAttributes = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
249 HANDLE handle = CreateFileW(
250 _path, // __in LPCTSTR lpFileName,
251 GENERIC_READ | GENERIC_WRITE, // __in DWORD dwDesiredAccess,
252 0, // __in DWORD dwShareMode,
253 &securityAttributes, // __in LPSECURITY_ATTRIBUTES lpSecurityAttributes,
254 OPEN_EXISTING, // __in DWORD dwCreationDisposition,
255 0, // __in DWORD dwFlagsAndAttributes,
256 NULL // __in HANDLE hTemplateFile
257 );
259 CloseHandle(handle);
260 return true;
261 }
262 return false;
263
264#else
265 return __access(_path, R_OK | W_OK);
266
267#endif
268}
DCLCAPI int __access(const String &_path, int _type)
Definition _unistd.cpp:22
#define NULL
Definition Config.h:340
#define INVALID_HANDLE_VALUE
Definition Dir.cpp:31
#define TRUE
HandleType handle() const
Definition File.h:242

◆ onEvent()

bool SerialPort::onEvent ( short _revents,
PollThread * _pPollThread )
protectedvirtual

SerialPollThread에의해 감시되다가 이벤트가 발생되었을 때 호출된다.

Implements PollAble.

Definition at line 270 of file SerialPort.cpp.

272{
273 return true;
274}

The documentation for this class was generated from the following files: