- UID
- 1029342
- 性别
- 男
|
3.mcdHid.cpp
/*
mcdhid.cpp
function: open HID device ,close HID device ,read data from HID device , write data to HID device
author:
date:
version:
*/
#include
#include
#include
#include "mcdhid.h"
#include "MCDInterface.h"
#include "mcdbox.h"
#include "pthread.h"
void *getDataThread(void *pParam);
#define VENDOR_ID 0x1241//test device vendorId
#define PRODUCT_ID 0xe001//test device productId
#define CLIENT_RUNNING_MSG
MCDHid::MCDHid()
{
_hidDeviceName = "MCD Human Interface Device";
_fUsbCommRunning = false;
_offHookSignal = false;
_dataWaitProcess = 1;
memset(_inputReportBuffer,0,sizeof(_inputReportBuffer));
memset(_outputReportBuffer,0,sizeof(_outputReportBuffer));
}
MCDHid::MCDHid(MCDHid & mcdHid)
{
copy(mcdHid);
}
MCDHid & MCDHid:perator=(MCDHid & mcdHid)
{
copy(mcdHid);
return *this;
}
void MCDHid::copy(MCDHid & mcdHid)
{
_hidDeviceName = mcdHid._hidDeviceName;
_hEventObject = mcdHid._hEventObject;
_hIDOverlapped = mcdHid._hIDOverlapped;
_hidDevice = mcdHid._hidDevice;
_fUsbCommRunning = mcdHid._fUsbCommRunning;
_offHookSignal = mcdHid._offHookSignal;
_dataWaitProcess = mcdHid._dataWaitProcess;
_inputReportByteLength = mcdHid._inputReportByteLength;
_outputReportByteLength = mcdHid._outputReportByteLength;
for(int i = 0; i<sizeof(_inputreportbuffer); i++)
{
_inputReportBuffer = mcdHid._inputReportBuffer;
}
for(int i = 0; i<sizeof(_outputreportbuffer); i++)
{
_inputReportBuffer = mcdHid._outputReportBuffer;
}
}
MCDHid::~MCDHid()
{
}
unsigned long MCDHid:penMCDHid()
{
if(findMCDHid())
{
//采用重叠传输方式
//if( _hEventObject == 0)
// {
_hEventObject = CreateEvent(
NULL,
true,
true,
"");
_hIDOverlapped.hEvent = _hEventObject;
_hIDOverlapped.Offset = 0;
_hIDOverlapped.OffsetHigh =0;
// }
return MCD_RETURN_SUCCESS;
}
else
return MCD_RETURN_NO_FOUND_HID;
}
void MCDHid::closeMCDHid()
{
CloseHandle(_hidDevice.HidDevice);
_hidDevice.HidDevice = INVALID_HANDLE_VALUE;
}
void MCDHid::startComm(void *pParam)
{
int thr_id;
pthread_t m_processT;
if((thr_id=pthread_create(&m_processT, NULL, getDataThread, pParam) != 0))
{
//printf("pthread_create error:%s\n", strerror(thr_id));
return;
}
} |
|