Does anyone have any experience with using the USB for io
I am doing this for a hobby type device where I am using the Android as a cheap why to get GPS and other hardware services (since I already have the phone). I have used an unofficial kernel called AdbWinUsb that disconnects the USB from its usual use and makes it into an io port. Has anyone else out there done this before successfully? I have code to write out to the serial port: import java.io.DataInputStream; import android.os.Bundle; import android.os.Messenger;
DataInputStream os;
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("chmod 777 /dev/ttyMSM0\n");
....
String data = "echo \"Hello World\" > /dev/ttyMSM0";
os.writeBytes(data + "\n");
os.flush();
and this works great.
Then in another thread, I need to set up the read, but I can't write to the port to set it up as I did in the output....
process = Runtime.getRuntime().exec("su");
os = new DataInputStream(process.getInputStream());
char xx = os.readChar();
The readChar doesn't 开发者_如何学编程work because it is not set up. Is this correct? So what do I do?
There is no reference to any serial or USB port in the code you have posted.
Pushing "Test" into the stdin of whatever process 'su' gives you isn't going to accomplish much of anything. You'll have better luck using su to chmod the device file of whatever device driver you have loaded to talk to whatever you plugged into the USB port (you do have a device driver loaded for that device, right?) and then talk to it from java, or to run a command line executable which proxies it's stdin/stdout to the device file for you.
What exactly have you plugged into the usb port?
If you can tolerate a higher external hardware cost, either the new, official ADK from google for recent android releases or the 3rd party IOIO (which should at least with modifications work on just about anything) may manage to abstract away more of the difficulty and connect you to more sources of support, though frankly having the accessory as the USB host is an unfortunate backwardness to have to resort to.
I've just ordered a cheap bluetooth to rs232/ttl converter, then I'll use a PIC with UART to interface with the rs232. It seemed simpler, it means I don't need to know much about Bluetooth (or USB)
精彩评论