64 : m_hUpPipe(INVALID_HANDLE_VALUE), m_hDownPipe(INVALID_HANDLE_VALUE), m_sendTimeout(0)
65 , m_reportId(0), m_property(_T(
"HID"), TNBVIW_KIND_USB, 100)
96 DWORD x = (m_sendTimeout != 0) ? FILE_FLAG_OVERLAPPED : 0;
97 HANDLE hDown = ::CreateFile(
99 (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, x, 0);
100 if ( hDown == INVALID_HANDLE_VALUE )
102 _GetLastError(
"CreateFile");
103 ::SetLastError(ERROR_NOT_FOUND);
106 HANDLE hUp = ::CreateFile (
107 m_hidName.
GetPathName(), (GENERIC_READ | GENERIC_WRITE),
108 (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
109 if ( hUp == INVALID_HANDLE_VALUE )
111 _GetLastError(
"CreateFile");
117 TRACE0(
"CHid::Openしました\n" );
119 m_property.
typeId = TNBVIW_KIND_USB + (
reinterpret_cast<ULONG_PTR
>(
this) & 0xFFFF);
133 if ( m_hUpPipe != INVALID_HANDLE_VALUE )
135 m_CloseHandle(m_hUpPipe);
136 m_hUpPipe = INVALID_HANDLE_VALUE;
138 if ( m_hDownPipe != INVALID_HANDLE_VALUE )
140 m_CloseHandle(m_hDownPipe);
141 m_hDownPipe = INVALID_HANDLE_VALUE;
152 return m_hDownPipe != INVALID_HANDLE_VALUE;
163 if ( ::GetLastError() == ERROR_DEVICE_NOT_CONNECTED )
220 virtual size_t Send(
size_t size, LPCVOID P)
227 size_t sentTotalSize = 0;
230 work[0] = m_reportId;
231 const BYTE* lpbData =
static_cast<const BYTE*
>(P);
233 bool isSuccess =
true;
237 if ( (size - sentTotalSize) < sizeOutputReport )
239 sendSize = size - sentTotalSize;
240 memset(work, 0, sizeOutputReport);
244 sendSize = sizeOutputReport -1;
247 MemCopy(&work[1], &lpbData[sentTotalSize], sendSize);
252 DWORD dwWriteLen = 0;
253 if ( m_Write(m_hDownPipe, work,
ToDword(sizeOutputReport), &dwWriteLen) )
255 if ( sizeOutputReport == dwWriteLen )
261 if ( _GetLastError(
"WriteFile") == ERROR_DEVICE_NOT_CONNECTED )
273 sentTotalSize += sendSize;
274 if ( size <= sentTotalSize )
279 return isSuccess ? size : INVALID_SIZE;
290 virtual size_t Receive(
size_t size, LPVOID _P)
299 if ( r != INVALID_SIZE && r != 0 )
306 MemCopy(
static_cast<BYTE*
>(_P), work.
Ref() + 1, r);
310 if ( ::GetLastError() == ERROR_DEVICE_NOT_CONNECTED )
359 return ERROR_NOT_FOUND;
497 return r ?
CStr(s) : _T(
"");
510 return r ?
CStr(s) : _T(
"");
523 return r ?
CStr(s) : _T(
"");
537 return r ?
CStr(s) : _T(
"");
549 return r ? numberBuffers : 0;
565 bool m_CloseHandle(HANDLE h)
568 if ( ! ::GetHandleInformation(h, &f) )
570 _GetLastError(
"GetHandleInformation");
573 return !! ::CloseHandle(h);
575 bool m_Write(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten)
577 if ( m_sendTimeout == 0 )
579 return !! ::WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, NULL);
581 OVERLAPPED overLapped;
583 HANDLE hEvent = ::CreateEvent(NULL, FALSE, TRUE, NULL);
584 ::ResetEvent(hEvent);
585 overLapped.hEvent = hEvent;
586 BOOL r = ::WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, &overLapped);
591 else if ( ::GetLastError() == ERROR_IO_PENDING )
595 switch ( ::WaitForSingleObject(overLapped.hEvent, m_sendTimeout) )
598 r = ::GetOverlappedResult(hFile, &overLapped, lpNumberOfBytesWritten, FALSE);
609 ::CloseHandle(hEvent);
616 TProperty m_property;
620 friend class CUsbHidTest;
#define loop(VAR, CNT)
loop構文.
size_t Read(LPVOID _P, DWORD wait=0)
[読込] 読込み.
void Detach(void)
[設定] デタッチ.
void Attach(HANDLE hFile, size_t size)
[設定] アタッチ.
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
static CStrT Fmt(const TCHAR *lpszFormat,...)
[作成] 書式付き文字列作成
TYP * GetBuffer(size_t iLength=0)
[操作] 書き込みバッファ要求.
BOOLEAN HidD_SetFeature(HANDLE hidDeviceObject, PVOID pReportBuffer, ULONG reportBufferLength)
[送信] 機能レポート送信
BOOLEAN HidD_SetNumInputBuffers(HANDLE hidDeviceObject, ULONG numberBuffers)
[設定] 入力バッファ数設定.
BOOLEAN HidD_GetFeature(HANDLE hidDeviceObject, PVOID pReportBuffer, ULONG reportBufferLength) const
[受信] 機能レポート受信
BOOLEAN HidD_GetNumInputBuffers(HANDLE hidDeviceObject, PULONG pNumberBuffers) const
[取得] 入力バッファ数取得.
BOOLEAN HidD_SetOutputReport(HANDLE hidDeviceObject, PVOID pReportBuffer, ULONG reportBufferLength)
[送信] Outputレポート送信
BOOLEAN HidD_GetProductString(HANDLE hidDeviceObject, PVOID pBuffer, ULONG bufferLength) const
[取得] Product 文字列取得
BOOLEAN HidD_GetInputReport(HANDLE hidDeviceObject, PVOID pReportBuffer, ULONG reportBufferLength) const
[受信] Inputレポート受信
BOOLEAN HidD_GetManufacturerString(HANDLE hidDeviceObject, PVOID pBuffer, ULONG bufferLength) const
[取得] Manufacturer 文字列取得
BOOLEAN HidD_FlushQueue(HANDLE hidDeviceObject)
[処理] キューフラッシュ.
BOOLEAN HidD_GetIndexedString(HANDLE hidDeviceObject, ULONG stringIndex, PVOID pBuffer, ULONG bufferLength) const
[取得] INDEXED 文字列取得
BOOLEAN HidD_GetSerialNumberString(HANDLE hidDeviceObject, PVOID pBuffer, ULONG bufferLength) const
[取得] SerialNumber 文字列取得
size_t GetOutputReportByteLength(void) const
[取得] Outputレポート長取得
bool IsEmpty(void) const
[確認] 情報有無確認
const CStr & GetPathName(void) const
[取得] パスネーム取得
size_t GetInputReportByteLength(void) const
[取得] Inputレポート長取得
DWORD SetPathName(LPCTSTR lpszPathName)
[設定] パスネーム設定.
WORD GetProductId(void) const
[取得] プロダクトID取得
WORD GetVendorId(void) const
[取得] ベンダID取得
size_t GetFeatureReportByteLength(void) const
[取得] Featureレポート長取得
virtual EState Check(void) const
[確認] チェック.
virtual ~CUsbHid(void)
デストラクタ
CStr GetManufacturerString(void) const
[取得] Manufacturer 文字列取得
virtual bool SetReceiveTimeout(DWORD to)
[設定] 受信待ち時間設定.
bool SetFeature(size_t dataSize, LPCVOID lpcvData)
[送信] SetFeature
virtual bool Open(void)
[処理] オープン.
bool SetOutputReport(size_t dataSize, LPCVOID lpcvData)
[送信] SetOutputReport
CStr GetProductString(void) const
[取得] Product 文字列取得
virtual bool CanSend(void) const
[確認] 送信可能確認.
void SetReportId(BYTE id)
[設定] レポートID設定.
CByteVector GetInputReport(void) const
[受信] GetInputReport
virtual void Purge(void)
[処理] パージ.
const CUsbHidPathName & GetName(void) const
[取得] パスネーム情報取得
CStr GetSerialNumberString(void) const
[取得] SerialNumber 文字列取得
virtual bool IsConnect(void) const
[確認] 接続確認.
DWORD SetHidPathName(LPCTSTR lpszPathName)
[設定] USB-HIDデバイス指定.
void SetSendTimeout(DWORD to)
[設定] タイムアウト付き送信モード.
virtual void Close(void)
[処理] クローズ.
DWORD SetHidPathName(const CUsbHidPathName &hidName)
[設定] USB-HIDデバイス指定.
virtual bool CanReceive(void) const
[確認] 受信可能確認.
virtual bool IsOpened(void) const
[確認] オープン確認.
virtual size_t Receive(size_t size, LPVOID _P)
[処理] 受信.
CByteVector GetFeature(void) const
[受信] GetFeature
virtual const TProperty & GetProperty(void) const
[取得] 性能取得.
bool SetReceiveBufferCount(DWORD c)
[設定] 入力バッファ数設定.
virtual size_t GetReceivingDataSize(void) const
[確認] 受信データ確認.
CStr GetIndexedString(INDEX index) const
[取得] INDEXED 文字列取得
size_t GetFeatureReportByteLength(void) const
[取得] Featureレポート長取得
DWORD GetReceiveBufferCount(void) const
[取得] 入力バッファ数取得.
virtual size_t Send(size_t size, LPCVOID P)
[処理] 送信.
TYP * GetBuffer(size_t size=0)
[操作] データアドレス取得
void ReleaseBuffer(void)
[操作] データの管理を元に戻す.
void Invalid(void)
[操作] 無効状態にする
const TYP * Ref(void) const
[取得] ポインタ取得
DWORD ToDword(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
TNB::CStrT< TCHAR > CStr
文字列クラス
void Zero(V &value)
[設定] ゼロクリア.
void MemCopy(T *_pDst, const void *pSrc, size_t len)
[複製] メモリコピー
size_t sendPacketSize
送信パケットサイズ。INVALID_SIZE なら制限なし。
DWORD receiveTimeout
受信待ち時間。 INFINITE ならブロックされる。
size_t receivePacketSize
受信パケットサイズ。INVALID_SIZE なら制限なし。