首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

USB HID设备读写代码实现c++(3)

USB HID设备读写代码实现c++(3)

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;
}
}
继承事业,薪火相传
返回列表