- UID
- 1029342
- 性别
- 男
|
/*
*写入数据为MCD设备状态通知,把标识位放在第1位
*/
int MCDHid::writeToHid()
{
return 0;
}
int MCDHid::readFromHid()
//int readFromHid()
{
if(_hidDevice.HidDevice != INVALID_HANDLE_VALUE)
{
int result = 0;
DWORD numberOfBytesRead;
result = ReadFile(_hidDevice.HidDevice,
&_inputReportBuffer,
_hidDevice.Caps.InputReportByteLength,
&numberOfBytesRead,
(LPOVERLAPPED)&_hIDOverlapped);
_inputReportByteLength = _hidDevice.Caps.InputReportByteLength;
}
int waitResult = 0;
waitResult = WaitForSingleObject(
_hEventObject,
10);
switch(waitResult)
{
case WAIT_OBJECT_0: break;
case WAIT_TIMEOUT:
{
CancelIo(_hidDevice.HidDevice);
break;
}
default:
{
break;
}
}
ResetEvent(_hEventObject);
return 0;
}
/**************************************************************************
*启动一个读取数据线程,读取数据为拨打电话号码
*启动一个写入数据线程, 写入数据为MCD设备状态通知,现在还没有写数据
***************************************************************************/
void *getDataThread(void *pParam)
{
MCDBox *ht = (MCDBox *)pParam;
MCDHid *hr = &(MCDHid::getInstance());
while(hr->getUsbCommRunning())//USB设备running,并且有摘机信号
{
hr->readFromHid();
//readFromHid();
//printf("获取缓冲区的数据\n");
if(hr->getDataWaitProcess() > 0)//可以定义_dataWaitProcess为一次拨号数据的长度
{
unsigned long i = 0;
for(i = 0; i < 9; i++)
{
ht->_inputReportBuffer = hr->_inputReportBuffer;
//printf("read data from device is:%d\n",ht->_inputReportBuffer[1]);
}
ht->processData();
memset(hr->_inputReportBuffer,0,sizeof(hr->_inputReportBuffer));
//printf("数据处理!\n");
}
int status = 0;
//PHIDP_PREPARSED_DATA PreparsedData ;
//status = HidD_GetPreparsedData(_hidDevice.HidDevice,&PreparsedData);
status = HidD_GetAttributes(
hr->getHidDevice()->HidDevice,
&hr->getHidDevice()->Attributes);
if(!status)
{
hr->setUsbCommRunning(false);
memset(ht->_inputReportBuffer,0,sizeof(ht->_inputReportBuffer));
ht->_inputReportBuffer[2] = HID_DEVICE_REMOVE;
ht->processData();
printf("设备移走!");
//return false;
break;
}
//HidD_FreePreparsedData (PreparsedData);
// PreparsedData = NULL;
Sleep(100);
}
return 0;
} |
|