32 COverlapped(
void) : m_hEvent(NULL)
40 if ( m_hEvent != NULL )
42 ::CloseHandle(m_hEvent);
52 operator OVERLAPPED*(void)
55 if ( m_hEvent == NULL )
57 m_hEvent = ::CreateEvent(NULL, FALSE, TRUE, NULL);
58 ::ResetEvent(m_hEvent);
60 ::ResetEvent(m_hEvent);
61 m_overLapped.hEvent = m_hEvent;
73 size_t GetResult(HANDLE h, DWORD wait = 0)
75 if ( ::GetLastError() == ERROR_IO_PENDING )
80 if( ::GetOverlappedResult(h, &m_overLapped, &work, FALSE) )
84 else if ( ::GetLastError() != ERROR_IO_INCOMPLETE )
89 size_t result = INVALID_SIZE;
91 switch ( ::WaitForSingleObject(m_overLapped.hEvent, wait) )
94 if ( ::GetOverlappedResult(h, &m_overLapped, &r, FALSE) )
112 OVERLAPPED m_overLapped;
171 CRs232cEx(
void) : m_propertyEx(_T(
"RS232C"), TNBVIW_KIND_RS232C), m_pListener(NULL)
173 m_propertyEx = _super::GetProperty();
175 m_eventMask = EV_RXCHAR | EV_RXFLAG | EV_TXEMPTY | EV_CTS | EV_DSR | EV_RLSD | EV_BREAK;
176 m_eventMask |= EV_ERR | EV_RING | EV_PERR | EV_RX80FULL | EV_EVENT1 | EV_EVENT2;
243 bool r = _super::Open();
244 m_propertyEx.
typeName = _super::GetProperty().typeName;
245 m_propertyEx.
typeId = _super::GetProperty().typeId;
249 return m_thread.
Start();
263 m_propertyEx.
typeName = _super::GetProperty().typeName;
264 m_propertyEx.
typeId = _super::GetProperty().typeId;
276 virtual size_t Receive(
size_t size, LPVOID _P)
282 if ( ! ::ClearCommError(
GetHandle(), &dwErrors, &tComStat) )
284 _GetLastError(
"ClearCommError");
287 if ( size > tComStat.cbInQue )
289 size = tComStat.cbInQue;
328 ::WaitCommEvent(
GetHandle(), &event, m_eventOverlapped);
329 if ( ::GetLastError() != ERROR_ACCESS_DENIED )
331 DWORD r = m_eventOverlapped.GetResult(
GetHandle(), INFINITE);
332 if ( r ==
sizeof(DWORD) )
335 if ( m_pListener != NULL )
362 DWORD desiredAccess = GENERIC_READ | GENERIC_WRITE;
363 DWORD flag = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED;
364 HANDLE h = ::CreateFile(lpszPortName, desiredAccess, 0, NULL, OPEN_EXISTING, flag, NULL);
365 _GetLastError(
"CreateFile");
379 virtual bool WritePort(
size_t& _writtenSize,
size_t len, LPCVOID P, HANDLE h)
const
382 ::WriteFile(h, P,
ToDword(len), &dwWritten, m_writeOverlapped);
383 dwWritten = m_writeOverlapped.GetResult(h, INFINITE);
384 if ( dwWritten == INVALID_SIZE )
388 _writtenSize = dwWritten;
402 virtual bool ReadPort(
size_t& _redSize, LPVOID _P,
size_t len, HANDLE h)
const
405 ::ReadFile(h, _P,
ToDword(len), &dwRed, m_readOverlapped);
406 dwRed = m_readOverlapped.GetResult(h, m_propertyEx.
receiveTimeout);
407 if ( dwRed == INVALID_SIZE )
417 IListener* m_pListener;
418 TProperty m_propertyEx;
420 mutable COverlapped m_readOverlapped;
421 mutable COverlapped m_writeOverlapped;
422 mutable COverlapped m_eventOverlapped;
CThreadStatus & ReferThreadStatus(void)
[参照] 監視スレッド状態参照.
void SetListener(IListener *P)
[設定] リスナー登録.
virtual bool SetReceiveTimeout(DWORD to)
[設定] 受信待ち時間設定.
virtual bool Open(void)
[処理] オープン.
virtual bool WritePort(size_t &_writtenSize, size_t len, LPCVOID P, HANDLE h) const
[通知] ポート書き込み.
virtual bool ReadPort(size_t &_redSize, LPVOID _P, size_t len, HANDLE h) const
[通知] ポート読み込み.
virtual HANDLE CreatePort(LPCTSTR lpszPortName) const
[通知] ポート作成.
virtual void Close(void)
[処理] クローズ.
virtual DWORD Run(void)
[動作] スレッド処理本体
virtual size_t Receive(size_t size, LPVOID _P)
[処理] 受信.
virtual const TProperty & GetProperty(void) const
[取得] 性能取得
void SetListenEvent(DWORD event)
[設定] 監視するイベント指定.
HANDLE GetHandle(void) const
[取得] ハンドル取得
bool SetRunner(IRunner *pRunner)
[設定] ランナー、設定
bool Stop(DWORD dwWait=15000)
[設定] スレッド停止 スレッドに対して停止要求します。
bool Start(LPCTSTR lpszName=NULL)
[設定] スレッド開始
DWORD ToDword(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
void Zero(V &value)
[設定] ゼロクリア.
virtual ~IListener(void)
デストラクタ
virtual void OnRs232cEvent(DWORD event)=0
[通知] イベント通知.
bool IsRunnable(void) const
[確認] 実行可能か否か
DWORD receiveTimeout
受信待ち時間。 INFINITE ならブロックされる。