TJvhiddeviceController 物件如何同時使用數個HID? |
尚未結案
|
joeen63
一般會員 ![]() ![]() 發表:8 回覆:5 積分:2 註冊:2007-04-05 發送簡訊給我 |
目前使用 TJvhiddeviceController 做USB HID , 也可以通訊了,如果想要同時接數個HID裝置,要如何做呢?
__fastcall TDevInThread::TDevInThread(TJvHidDevice *MyDev) : TThread(False) { Dev = MyDev; // Initialize variables. } //--------------------------------------------------------------------------- void __fastcall TDevInThread::HandleReport(void) { MainForm->ShowInputReport(); // Show input report. } //--------------------------------------------------------------------------- void __fastcall TDevInThread::Execute(void) { DWORD dwRetVal; dwRetVal = WAIT_IO_COMPLETION; while(!Terminated) { // Read input report. if(!Dev->ReadFileEx(&Report, Dev->Caps.InputReportByteLength, &OvDummy)) break; // Wait read to complete. do{ dwRetVal = SleepEx(100, true); }while(!Terminated && (dwRetVal != WAIT_IO_COMPLETION)); // Handle input report. if(!Terminated) { dwReportLen = Dev->HidOverlappedReadResult; Synchronize(HandleReport); } } // Cancel pending read. if(dwRetVal != WAIT_IO_COMPLETION) Dev->CancelIO(omhRead); } void __fastcall TMainForm::USBHidCtlDeviceChange(TObject *Sender) { int i; if(DevList == NULL) // Create device list. DevList = new TList(); else { for(i=0;i ((TJvHidDevice *)DevList->Items[i])->Free(); DevList->Clear(); // Clear device list. } // StateMemo->Clear(); // Clear device list box. USBHidCtl->Enumerate(); // Enumerate all USB HID devices. } //--------------------------------------------------------------------------- bool __fastcall TMainForm::USBHidCtlEnumerate(TJvHidDevice *HidDev, const int Idx) { if((HidDev->Attributes.VendorID == 0x0483) && (HidDev->Attributes.ProductID == 0x5750)) { MainForm->USBFindTimer->Enabled = false; MainForm->USBDevTimer->Enabled = true; Port_OPEN = true; MainForm->Image1->Visible = false; MainForm->Image2->Visible = true; USB_Num = Idx; } else { MainForm->USBFindTimer->Enabled = true; Port_OPEN = false; // MainForm->Image1->Visible = true; // MainForm->Image2->Visible = false; } TJvHidDevice *Dev; USBHidCtl->CheckOutByIndex(Dev, Idx); DevList->Add(Dev); // Add device to device list. return true; } //--------------------------------------------------------------------------- void __fastcall TMainForm::USBDevTimerTimer(TObject *Sender) { MainForm->USBDevTimer->Enabled = false; TJvHidDevice *Dev = (TJvHidDevice *)DevList->Items[USB_Num]; DevInThread = new TDevInThread((TJvHidDevice *)DevList->Items[USB_Num]); // Create device input thread. } //--------------------------------------------------------------------------- void __fastcall TMainForm::ShowInputReport(void) { for(DWORD i = 0; i < DevInThread->dwReportLen; i ) Buffer_tmp[i] = DevInThread->Report.bData[i]; if(Buffer_tmp[0] == 'O' && Buffer_tmp[1] == 'K') CMD_Flag = true; } 以上是目前有使用的程式,請問要如何修改? 謝謝. |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |