私はアンドロイドデバイスとWindowsドライバを持っています。 アクセサリモードで自分のバイナリプロトコルを使用して通信する必要があります。 カスタムUSBドライバを作成せずにこのデバイスにデータを送信することはできますか?USB経由でWindows PCからアンドロイドデバイスと通信する
答えて
USBは、'ユニバーサル'であり、多種多様なデバイス(マスストレージ、カメラなど)を扱うことができるため、複雑なプロトコルです。だからあなたのアンドロイドデバイスでは、libusbまたはそのような標準ライブラリを使用するための基本的なUSB構造を実装する必要があります。 ほとんどの場合、アンドロイドはUSBポートを備えたプロセッサで使用されているため、これが当てはまると考えることができます。
http://www.beyondlogic.org/usbnutshell/usb1.shtmlを参照してください。
あなたがのlibusbを使用することができますようにあなたのAndroidデバイス上のUSB構造が見えるものを知っている場合は、次にlibusb -v
を使用してAndroidデバイスのimpmenetsウルUSBデバイスクラス、インタフェース、構成、エンドポイントに関する詳細な情報を得ることができますまたは別のライブラリを使用して、USB構造内の特定のエンドポイントにデータを書き込むlibusb_bulk_transfer()
、libusb_control_transfer()
http://libusb.sourceforge.net/api-1.0/io.html
あなたがusb4java使用できるJavaでプログラミングしたい場合はしかし、これは一般的なUSB構造がデバイスであるhttp://usb4java.org/quickstart/libusb.html
ビットフレーク状である - >(設定) - >インタフェース - >エンドポイント
だから、エンドポイントにデータを書き込むための方法は次のとおりです。
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つに書き込むには上記のコードを参照してください。
- 1. USB経由でアンドロイドアプリとPCアプリケーションとの通信
- 2. PCからPCへのUSB通信
- 3. iOSデバイスからUSB経由でWindows PCにファイルを転送
- 4. USBデバッグなしでUSB経由でPCからアンドロイドアプリをインストール
- 5. USBポート経由でWindowsコンピュータと通信するiOSアプリを通信することは可能ですか?
- 6. USB接続経由でアンドロイドデバイスから.protoファイルを送信する方法
- 7. AndroidアプリはUSB経由でデスクトップアプリケーションと通信できますか?
- 8. LIVE USBブートによるUSB経由でのシリアル通信
- 9. Android(アクセサリーモード)とWindows PC(ホスト)とのUSB通信
- 10. Androidデバイス、USBポート経由でデバイスと通信する
- 11. OS XからUSB経由のiOS通信に?
- 12. 「USB仮想シリアルポート」経由でUSBデバイスと通信するにはC?
- 13. OpenCV MatをPCからAndroid経由でSocket経由で送信する方法
- 14. Raspberry Pi 2とインターネット経由のPCとの通信
- 15. WP7:USB経由の電話からPCへのTCP接続
- 16. USB経由でiPhoneファイルシステムにアクセスする方法(Windowsから)
- 17. Windowsでネットワーク経由でドライバと通信する
- 18. アンドロイドデバイスからWifi経由でプリンタにアクセス
- 19. PC BがPC Dと通信できない理由は?
- 20. USB経由でAndroidからの簡単なコマンドを送信
- 21. 私のインターネット接続をPCからアンドロイドにUSB経由で共有することは可能ですか?
- 22. iPadとMacまたはPCとの間のUSB通信
- 23. ios appとwindows appからiphone hddにアクセスする方法(USB経由)
- 24. Windowsアプリケーションでusb PCカメラからライブ画像を表示する
- 25. ArduinoでUSBポートを使わずにPCと通信できますか?
- 26. PCからACR1255U-J1と通信してISOを送信する14443
- 27. GAE経由で通信するAndroidクライアント
- 28. Raspberry Pi:I2C経由で通信する
- 29. JavaをUSBポート経由でデバイスと通信するにはどうすればよいですか?
- 30. USB経由でsdcardではなくPCにファイルを保存するには