나는 안드로이드 장치와 윈도우 드라이버를 가지고 있습니다. 액세서리 모드에서 내 자신의 바이너리 프로토콜을 사용하여 통신해야합니다. 맞춤형 USB 드라이버를 작성하지 않고이 장치로 데이터를 보낼 수 있습니까?USB를 통해 Windows PC에서 안드로이드 장치와 통신하기
답변
USB는 'universal'이고 대용량 저장 장치, 카메라 등 다양한 장치를 처리 할 수 있기 때문에 복잡한 프로토콜입니다. 그래서 당신의 안드로이드 장치는 libusb 또는 그와 비슷한 표준 라이브러리를 사용하기 위해 기본 USB 구조를 구현해야합니다. 대부분의 경우 안드로이드는 USB 포트가있는 프로세서에서 사용되기 때문에 이런 경우라고 생각할 수 있습니다.
http://www.beyondlogic.org/usbnutshell/usb1.shtml을 참조하십시오.
당신이 libusb를 사용할 수 있습니다처럼 안드로이드 장치에 USB 구조가 어떻게 생겼는지 알고있는 경우는 다음 libusb -v
를 사용하여 안드로이드 장치 impmenets UR USB 장치 클래스, 인터페이스, 구성, 엔드 포인트에 대한 자세한 정보를 얻을 수 있습니다 또는 다른 라이브러리가 예를 들어 usb 구조의 특정 끝점에 데이터를 씁니다. libusb_bulk_transfer()
, libusb_control_transfer()
http://libusb.sourceforge.net/api-1.0/io.html
당신이 자바는 그러나이 색다른 비트가 usb4java 사용할 수있는 프로그램하려면
http://usb4java.org/quickstart/libusb.html일반적인 USB 구조 장치 -> (구성) -> 인터페이스 - > 엔드 포인트
그래서 엔드 포인트에 데이터를 기록하는 방법은 다음과 같습니다
libusb_init(NULL);
libusb_open_device_with_vid_pid(NULL, vendor_id, product_id);
libusb_claim_interface(devh, 0);
libusb_bulk_transfer(dev_handle, (2 | LIBUSB_ENDPOINT), data,
4, &p, 0); //example
... release interface...
...
libusb_close(devh);
libusb_exit(NULL);
여기
그래서 같은 장치가이 USB 구조/기능이 안드로이드 실행 http://www.dreamincode.net/forums/topic/148707-introduction-to-using-libusb-10/
#include <iostream>
#include <libusb.h>
using namespace std;
int main() {
libusb_device **devs; //pointer to pointer of device, used to
retrieve a list of devices
libusb_device_handle *dev_handle; //a device handle
libusb_context *ctx = NULL; //a libusb session
int r; //for return values
ssize_t cnt; //holding number of devices in list
r = libusb_init(&ctx); //initialize the library for the session we
just declared
if(r < 0) {
cout<<"Init Error "<<r<<endl; //there was an error
return 1;
}
libusb_set_debug(ctx, 3); //set verbosity level to 3, as suggested in
the documentation
cnt = libusb_get_device_list(ctx, &devs); //get the list of devices
if(cnt < 0) {
cout<<"Get Device Error"<<endl; //there was an error
return 1;
}
cout<<cnt<<" Devices in list."<<endl;
dev_handle = libusb_open_device_with_vid_pid(ctx, 5118, 7424);
//these are vendorID and productID I found for my usb device
if(dev_handle == NULL)
cout<<"Cannot open device"<<endl;
else
cout<<"Device Opened"<<endl;
libusb_free_device_list(devs, 1); //free the list, unref the devices
in it
unsigned char *data = new unsigned char[4]; //data to write
data[0]='a';data[1]='b';data[2]='c';data[3]='d'; //some dummy values
int actual; //used to find out how many bytes were written
if(libusb_kernel_driver_active(dev_handle, 0) == 1) { //find out if
kernel driver is attached
cout<<"Kernel Driver Active"<<endl;
if(libusb_detach_kernel_driver(dev_handle, 0) == 0) //detach it
cout<<"Kernel Driver Detached!"<<endl;
}
r = libusb_claim_interface(dev_handle, 0); //claim interface 0 (the
first) of device (mine had jsut 1)
if(r < 0) {
cout<<"Cannot Claim Interface"<<endl;
return 1;
}
cout<<"Claimed Interface"<<endl;
cout<<"Data->"<<data<<"<-"<<endl; //just to see the data we want to
write : abcd
cout<<"Writing Data..."<<endl;
r = libusb_bulk_transfer(dev_handle, (2 | LIBUSB_ENDPOINT_OUT), data,
4, &actual, 0); //my device's out endpoint was 2, found with trial-
the device had 2 endpoints: 2 and 129
if(r == 0 && actual == 4) //we wrote the 4 bytes successfully
cout<<"Writing Successful!"<<endl;
else
cout<<"Write Error"<<endl;
r = libusb_release_interface(dev_handle, 0); //release the claimed
interface
if(r!=0) {
cout<<"Cannot Release Interface"<<endl;
return 1;
}
cout<<"Released Interface"<<endl;
libusb_close(dev_handle); //close the device we opened
libusb_exit(ctx); //needs to be called to end the
delete[] data; //delete the allocated memory for data
return 0;
}
에서 복사 C++ 예입니다. 장치의 USB 기능 (대용량 저장 장치, RNDIS, ...과 같은 장치 클래스)을 조사하려면 장치의 끝점 중 하나에 사용자 지정 데이터를 쓰려면 위의 코드를 참조하십시오 (libusb -v
).
- 1. USB를 통해 안드로이드 앱과 통신하기
- 2. 안드로이드를 통해 시리얼 USB 장치와 통신하기
- 3. 안드로이드 장치와 USB를 통해 통신하는 USB 호스트 인 Windows PC
- 4. usb를 통해 android와 시리얼 장치 사이에서 통신하기
- 5. 안드로이드의 ADB는 USB를 통해 장치와 어떻게 대화합니까?
- 6. 여러 장치와 통신하기 WCF
- 7. Android : 호스트로 작동하는 USB 장치와 통신하기
- 8. USB 장치와 통신하기
- 9. controlTransfer를 사용하여 USB 장치와 통신하기
- 10. android에서 맞춤형 USB 장치와 통신하기
- 11. 함수를 사용하여 USB 장치와 통신하기
- 12. IOKit을 사용하여 USB 장치와 통신하기
- 13. usb를 통해 안드로이드 장치에 연결
- 14. iOS 장치가 아닌 iOS 장치와 통신하기
- 15. 리눅스의 메모리 매핑 된 장치와 통신하기
- 16. USB를 통해 PC와 통신
- 17. 소켓을 통해 안드로이드 및 윈도우 통신하기
- 18. 안드로이드 : USB를 통해 Windows 공유를 마운트하는 일반적인 방법
- 19. USB를 통해 안드로이드 애플 리케이션과 PC 응용 프로그램 사이의 통신
- 20. 안드로이드 모바일 GSM 모뎀으로 PC에서 SMS를 보내거나받을 수 있습니까?
- 21. Windows PC에서 USB를 감지하지 못하게 할 방법이 있습니까?
- 22. Android에서 USB 연결을 통해 PC와 통신하기
- 23. usb를 통해 안드로이드 장치 정보 가져 오기
- 24. 안드로이드 - USB를 통해 의료 기기에서 데이터 읽기
- 25. 원격 데스크톱 Windows CE로 ... USB를 통해?
- 26. USB 연결없이 안드로이드 장치와 통신하는 방법. 가능성이 직렬 포트를 통해
- 27. USB를 통해 데이터를 읽는 Android 앱
- 28. USB를 통해 아날로그 데이터 입력
- 29. PC에서 안드로이드 장치 로컬 호스트를 통해 열기
- 30. 블루투스를 통해 PC에서 안드로이드 폰으로 파일 보내기