Mintoris
Oct 20, 2017, 12:28 PM *
Welcome, Guest.

login

register

Did you miss your activation email?


Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: 1 [2]
  Print  
Author Topic: USB support?  (Read 6455 times)
Chuck
Global Moderator
Hero Member
*****
Posts: 1837



« Reply #20 on: Mar 22, 2014, 06:04 PM »

Most of the network communications problems have been fixed. There are still a couple things, like HttpGet$() and HttpPost$(), that have to be re-written. I've been compiling to Android Api 17 which is 4.2.2. Api 19 is the latest, but I can't get the emulator to run it reliably. I think all the depreciation problems have been resolved. Time will tell, but everything seems to be running great.

I've made a start on USB communications. I have a serial USB library which has been used to communicate with Arduino processors. So my first goal is to get two Android devices communicating by USB and then get one of my Android devices to communicate with my Arduino. Once it works in testing I will design the Basic syntax. I expect it will be very close to Tcp and Bluetooth syntax.

-Chuck
Logged
memi205
Full Member
***
Posts: 22


« Reply #21 on: Mar 25, 2014, 08:58 AM »


Great! keep us informed, Chuck!

Michel
 Smiley
Logged
Chuck
Global Moderator
Hero Member
*****
Posts: 1837



« Reply #22 on: Mar 25, 2014, 12:16 PM »

I've finished all the upgrades required by the latest version of Android.  Kinda stuck since my host provider has blocked my IP address and I can't test the last few network commands I worked on. I'm working with my host provider to resolve the issue.

I have a USB library which has been used to communicate with Arduino processors, but haven't got to test it yet.
« Last Edit: Mar 25, 2014, 12:17 PM by Chuck » Logged
Chuck
Global Moderator
Hero Member
*****
Posts: 1837



« Reply #23 on: Mar 26, 2014, 05:25 PM »

USB communications is going to be a real pain in the butt. It's nowhere near as well supported as TCP or Bluetooth. Spent all day experimenting. I can get a list of USB ports, which doesn't include the main "charger" USB port. Apparently that main USB port is handled completely different than accessory USB ports. I've also got my Arduino Mega loaded with the USB loopback program. (Oh so simple on that end). And, I can identify the Arduino board on the Android side. Now apparently I have to tell the system to ask the user for permission each time I want to open a USB port for communication.
Logged
Chuck
Global Moderator
Hero Member
*****
Posts: 1837



« Reply #24 on: Mar 27, 2014, 02:41 PM »

Today I was able to get my tablet to connect to my Arduino and perform a full loopback test. I see now that you are not really connected to the Arduino, but to a USB to Serial converter module that happens to be built into the Arduino (FTDI). Each kind of converter requires a specific driver. The library supports the four most popular brands of converters. I also have a Prolific USB to serial converter. I can connect to it and the library supports it, but was unable to connect it to my PC because I lacked the proper RS232 9pin f/f crossover cable. After about an hour of looking the parts to make one, I rush ordered one for about $10.

Later I was able to build a 9 pin RS232 loopback connector. I used this to successfully test the Prolific USB to serial converter. It will connect to the PC (or anything) with no problems once I get the crossover cable.

The way it looks now I don't think we will be able to use the charger micro usb port. Unless someone can provide some java example code using that port. Accessory USB ports, like the full size USB port on my tablet, work fine.


-Chuck
« Last Edit: Mar 27, 2014, 03:08 PM by Chuck » Logged
memi205
Full Member
***
Posts: 22


« Reply #25 on: Mar 28, 2014, 09:29 AM »

Even if it only works with an accessory usb port, this is very good news.

In my case, I have an Android Stick with an accessory usb port and it will be very useful for my projects with microcontrollers.
I noticed that I could not connect my usb hub to the micro usb charging port. My usb hub only works with the accessory usb port. I think it's something similar to your problem...

Bye !

Michel
Logged
Chuck
Global Moderator
Hero Member
*****
Posts: 1837



« Reply #26 on: Mar 28, 2014, 04:43 PM »

Yes, I think it's going to work nicely. I just began hooking the USB library to Basic. It's a good thing I have the source code to the USB library since I'm having to extend it a bit. Up until now I've just been testing with the example code. It's really cool to be able to communicate with my Arduino. I'm going to have to write some demo programs.

-Chuck
Logged
Chuck
Global Moderator
Hero Member
*****
Posts: 1837



« Reply #27 on: Mar 28, 2014, 11:49 PM »

I've created a wrapper class for the USB communications. This will allow more than one USB port to be open at once, even though I can't test it. It should work in theory. I've also laid all the groundwork for the new commands.

-Chuck
Logged
Chuck
Global Moderator
Hero Member
*****
Posts: 1837



« Reply #28 on: Mar 29, 2014, 02:14 PM »

I added and tested the first few Basic USB commands today. They are:

devices$() = UsbGetDevices$() - return a string array listing all the usb devices available.

device$ = UsbGetFirstDevice$() - returns the name of the first usb device.

vendorID = UsbGetVendorID(device$) - returns the vendor ID of the specified device$
productID = UsbGetProductID(device$) - returns the vendor's Product ID of the specified device$

driver$ = UsbGetDriverName$(device$) - returns the name of the driver used to communicate to the specified device$. If this function returns an empty string, then the device has no driver and is not supported.

Tomorrow I will be adding the open, close, read and write commands.
« Last Edit: Mar 29, 2014, 02:28 PM by Chuck » Logged
memi205
Full Member
***
Posts: 22


« Reply #29 on: Mar 29, 2014, 07:40 PM »

Very cool !!!

Michel
Logged
Chuck
Global Moderator
Hero Member
*****
Posts: 1837



« Reply #30 on: Mar 30, 2014, 05:06 PM »

I added these commands today:

UsbOpen channel, device$, baud, dataBits, stopBits, parity, rwTimeout

UsbClose channel

UsbGetState(channel)

UsbGetError$(channel)

UsbRead channel, data$, maxBytes

UsbReadln channel, data$

UsbReadUTF channel, data$

UsbWrite channel, data$

UsbWriteln channel, data$

UsbWriteUTF channel, data

I was able to write and test a USB serial loopback diagnostics program.

-Chuck
Logged
mjcoon
Sr. Member
****
Posts: 116


« Reply #31 on: Mar 31, 2014, 12:34 AM »

I added these commands today: ...

Hi Chuck, would I be right in guessing that USB support will only be useful on devices that offer USB-host or at least USB ToGo?

Cheers, Mike.
Logged
Chuck
Global Moderator
Hero Member
*****
Posts: 1837



« Reply #32 on: Mar 31, 2014, 09:46 AM »


Hi Chuck, would I be right in guessing that USB support will only be useful on devices that offer USB-host or at least USB ToGo?


Yes, you must have a USB host port. This would be an accessory USB port. The micro "charger" usb port will not work.

-Chuck
Logged
Chuck
Global Moderator
Hero Member
*****
Posts: 1837



« Reply #33 on: Apr 03, 2014, 04:27 PM »

The last couple days I've been doing more exhaustive testing of the USB serial communications. Finished writing the USB Serial Diagnostics program which I have now posted to the forum. Found and corrected a problem where characters were being dropped. USB tests perfect now.

Was finally able to add the UsbGetSize(connection) method so you can now see how many bytes are waiting to be read.

While I was working on serial communications I thought I should extend Bluetooth to match the other serial communication methods.

I added the following commands:

BTRead connection, data$, maxData
BTReadln connection, data$
BTReadUTF connection, data$

BTWrite connection, data$ - (this command did not change)
BTWriteln connection, data$
BTWriteUTF connection, data$

A new r/w timeout value was added to the following commands.

BTConnect channel, address$ {, rwTimeout, UUID$}

BTListen channel {, rwTimeout, UUID$}

I wrote a new Bluetooth Diagnostics program and these new Bluetooth read/write commands tested perfect. They should give you a lot more control over Bluetooth communications.
Logged
Witace12
Jr. Member
**
Posts: 7


« Reply #34 on: Nov 06, 2014, 03:29 AM »

Very cool thread!!!
Logged

mjcoon
Sr. Member
****
Posts: 116


« Reply #35 on: Aug 06, 2017, 01:36 AM »


Hi Chuck, would I be right in guessing that USB support will only be useful on devices that offer USB-host or at least USB ToGo?


Yes, you must have a USB host port. This would be an accessory USB port. The micro "charger" usb port will not work.

-Chuck
Ah, I note that the manual also says "accessory": "USB Serial Communication allows the transmission of data using an accessory USB port...". But I think this is not Android terminology because the Overview says: "Use UsbDevice to communicate with the hardware peripheral if the Android-powered device is acting as the USB host. Use UsbAccessory if the peripheral is acting as the USB host." It might confuse other literal-minded readers!

I have another question about Mintoris's USB Serial Communication: the call UsbGetDriverName$() must, I think, correspond to an underlying Android object field. But I can find no use of "driver" in Android documentation. So what is the actual underlying Android object field?

Regards, Mike.
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
Page created in 0.035 seconds with 17 queries.