0

I am currently trying to make an application who realise the communication (receiving data) between an Android phone and a device.

The phone recognise the device, but I can not receive data from the device.

I'm using the package android.hardware.usb.

So, I found the device (deviceID, productID etc...), I found the interfaces and the endpoints, but I don't know how to send a request to the correct endpoint and receive data from the device. I identified all interfaces and endpoints and I saw which endpoint can send data from the device to the phone.

Does anyone know how you can receive data from a device by using UsbDeviceConnection ?

If I well understood, you have to create a new thread to carry all data transmissions, obtain UsbInterface and UsbEndpoint, send requests on endpoint with a UsbDeviceConnection and after all that you cand receive the data.

Thank you in advance.

Domizzi
  • 53
  • 1
  • 10
  • check this link http://stackoverflow.com/questions/29679318/reading-data-from-arduino-uno-r3-kit , it takes a bit of head banging to finally collect or write data on to a USB devices...Hope it helps – DJphy May 21 '15 at 11:22
  • Thank you for your answer. I'll try to see if the physicaloid library can help me to receive all data informations. – Domizzi May 21 '15 at 12:22
  • If physicalloid fails use the below mentioned answer(using USB host api)... – DJphy May 21 '15 at 13:36
  • Where is the answer ? I can't see. Thanks – Domizzi May 21 '15 at 13:40
  • Scroll down in the link.. – DJphy May 21 '15 at 13:40
  • what it is SUSBS in your code ? you didn't initialize it or something ? or it's the object of class UsbManager ? thanks – Domizzi May 21 '15 at 14:09
  • SUSBS is just a module name, the library that i have developed to COMM with a serial USB device..And also, u cannot just copy paste the code, i have declared so many variables there(i have mentioned to declare it as well in the answer).. Any IDE(like eclipse, netbeans) will help u determining the type of the variable..Take some time and work on it, i have taken days..Ha ha.. :) – DJphy May 21 '15 at 14:38
  • i usually delete all the prefixes(like SUSBS) before posting, i have forgotton to remove, yes its a UsbManager.. – DJphy May 21 '15 at 14:40
  • You can initialize the UsbManager like this, – DJphy May 21 '15 at 14:44
  • usbManager = (UsbManager) Context.getSystemService(Context.USB_SERVICE); – DJphy May 21 '15 at 14:45
  • ok, thank you. I initialized this before for the other things : recognizing the device, finding the endpoints etc ... – Domizzi May 21 '15 at 15:03
  • how did you store your data in a file ? did you create a filewriter ? – Domizzi May 29 '15 at 11:44
  • do u want to know how to write data into a file.... – DJphy May 29 '15 at 12:15
  • yes, the data that i receive from the device, how can I can store the data on my phone ... – Domizzi May 29 '15 at 12:19
  • u just browse how to write data into a text file in android...u will get, u have to mention permission in manifest also...Just check it there are a lot of answer. The data will be a string(from StringBuilder as mentioned in my example), just write it to the file using the code u get from this site... – DJphy May 29 '15 at 12:26
  • did you succeed to receive some data on your phone at the end ? did you put your application on google play ? thnk u – Domizzi May 29 '15 at 14:06
  • We dont put applications on Google play, we are a product development company, it doesn't go beyond out products... The Medical diagnostic system is integrated with Android and its working like a gem... – DJphy May 29 '15 at 14:12
  • I have one more question :) did you receive any data with your application ? you don't have a demo version you can send me ?? ;) – Domizzi Jun 04 '15 at 10:40
  • because my problem is that i receive only 2 bytes, but i'm sure that the device sends more :) – Domizzi Jun 04 '15 at 13:26
  • Okay put it in a while loop..Are u using Physicalloid??? – DJphy Jun 04 '15 at 13:29
  • no, i'm not using Physicalloid :) if i put it in a while loop I receive the same bytes many times ;) but the device sends a lot of different bytes normally – Domizzi Jun 04 '15 at 13:35
  • in my answer link here(http://stackoverflow.com/questions/29679318/reading-data-from-arduino-uno-r3-kit/29825670#29825670) go to this line stating "Ola, the USB device is now able to communicate. So let us read. Code: Read using seperate thread" follow the below mentioned answer there to read From USB device... – DJphy Jun 04 '15 at 13:49
  • so, I read the bytes coming from the device with my application ... I have a PC application also and I see that the bytes received with the PC application are different from the bytes received with my mobile application ... do you have any idea why they are different because it's not normal ??? I thought that the interface or the endpoints are the problem, but it is not that – Domizzi Jun 05 '15 at 10:16
  • i guess ur using Tera term, the data that u recieve on PC should match with the data u that u get on Android... What is ur USB device is it a Kit??? – DJphy Jun 05 '15 at 11:23
  • it's a mobile station used in the trains ... – Domizzi Jun 05 '15 at 11:44

0 Answers0