Hi all sorry if this issue has been commented before, i have been 2 days looking on internet and here and not found any solution i try to make a hardware to connect to android in games of Unity with arduino, is a controller with buttons, joystick and sensor of movement i make great advances with PC but when i export to android, serial ports not work in PC I use: Code (CSharp): .... using System.IO.Ports; .... public class serial : MonoBehaviour { private SerialPort sp; void Start () { sp = new SerialPort ("COM1",115200, Parity.None, 8, StopBits.One); sp.Open (); sp.ReadTimeout = 1; } void Update() { if (sp.IsOpen) { try { moveObject(sp.ReadByte()); // here, in PC, call the function to use the serial data } catch ( System.Exception) { //here in Android is the problem, the funcion call the exception } } } I think the problem is because in Android, i cant work with ports like PC, i cant use the "port name" or something like this, I tested the device in Android with a terminal serial data, and the data is sending to android, but Unity app not is receiving the data any help will be great sorry by my english
NGC6543, I appreciate your works. Your sharing is very helpful. For the people who feels mik3y's source is difficult (like me, -Connecting other USB device needs modifying VendorID, ProductID on UsbId.java and proper *SerialDriver.java https://github.com/mik3y/usb-serial...c/main/java/com/hoho/android/usbserial/driver -Data acquiring from device, refering this can help: NGC6543's ~/usbserial/util/USBSerialForAndroid.java
Thanks for your kind words of advice! I'm not used to build native android app so it was a really painful work, though it helped me to get some slight knowledges about the system. For your information, the plugin sourcecode 'USBSerialForAndroid.java' might not handle the PendingIntention (Requesting user permission to access USB device) properly. If anyone know a proper way to do that please feel free to fix it, thanks.
Hi, NGC6543 The link https://www.dropbox.com/s/lwq0r9qwrrl71nu/USBSerialForAndroid_1.0.0.unitypackage?dl=0 does not work. Do you have the unity package for sale?
@Cbbigham informed that the base library has a bug regarding CdcAcmSerialDriver.java. related link : https://www.bountysource.com/issues/23844779-incorrect-endpoint-assignment-in-cdc-driver-with-fix A quick fix :
Hey @NGC6543 I'm looking to connect an Espruino Pico to a Samsung Galaxy S7. As I understand, the Pico is a standard CDC USB device. I have an OTG adapter connected to the phone with the Pico attached to the adapter. I'm having trouble with Unity recognizing the Pico. I downloaded the unitypackage that you provided in your latest Dropbox link. I made a build consisting of your example scene and ran it on my Galaxy S7 phone. I connected the Pico to my phone and pressed "Refresh Device List" and nothing happened. I connected the phone to adb and used logcat to see the debug output. When I pressed "Refresh Device List" again, logcat output the string "#### Device List" but nothing along with it. When I pressed "Connect to Device0", the text within Unity told me that the connection failed. Is there a step I was missing when setting up your unitypackage's code in Unity? Would there be problem with it being a newer Samsung phone? Or do you think it's the Pico? Thanks in advance, -Eric
Hey @TheBarGuy, sorry for the late reply. The example scene was only meant to be used by myself, sorry. But it should have detected your device, anyway.. I suggest you should refer to this reply(https://forum.unity3d.com/threads/serial-ports-in-android.363621/#post-3154882) above, and create your own library. The library has an example app that runs on your Android device. It detects your device (if it's supported). If it doesn't detect your device, maybe you should build your own custom plugins. Good luck! - Steve
Hey Steve, I figured that my device wasn't a standard device that would already be supported so I went ahead and followed the instructions that @heartily0421 provided in the post above. After adding my device's VID and PID to its corresponding white list (for CDC devices in my case) and built out a new .aar library, my device connected using your example. Thanks for the reply! -Eric
Unfortunately no, I didn't implemented it (I don't need it). Maybe I'll update the plugin later, but now I'm having a lot other things to do. I opened all the codes up there so, be my guest and implement Write() functionality!
I think applying source is in charge of users themselves. Your work is useful. Thank you for your sharing.