lundi 10 août 2015

Can't set BAUD rate for USB-Serial device



I have an RK3066-based generic 2-DIN Android head unit (see here). I've managed to install a rooted image on it (Yay!).
I want to connect it to a vehicle CAN bus, and I'm trying with an ELM327-based USB to OBD2 adaptor (which includes CAN as one of its protocols).

When I plug it into Ubuntu desktop, I get a "/dev/ttyUSB0". I can access it with Putty terminal and send commands as per the ELM documentation. For primitive access from the command line, I can do this (just to see whether it works at a basic level, without any terminal program):


Code:


sudo stty -F /dev/ttyUSB0 speed 38400
sudo cat /dev/ttyUSB0


And in another terminal:


Code:


sudo sh -c "echo "\r\n">/dev/ttyUSB0"

This produces "> ?" in the first terminal, in line with the expected prompt from the device. Good!

However, I can't get it to work on my Android device.
When plugged in, dmesg reports a Prolific USB-Serial device found and added to /dev/ttyUSB0.
"ls /dev/ttyUSB0" shows that it exists and is owned by "radio".

"stty -F /dev/ttyUSB0 speed" shows the speed is set to 9600 (this is also the default on Ubuntu desktop, and if not changed, the above test doesn't work).

However, I can't change the speed, and the test of sending a character to the decide doesn't work.
I've tried changing the permissions of the serial device (see this post) but it didn't help. I also tried changing to 'radio' with "su radio" but that also didn't work.

Whenever I try "stty -F /dev/ttyUSB0 speed 38400" I get either:
stty: /dev/ttyUSB0: cannot perform all requested operations
Or:
stty: /dev/ttyUSB0: cannot perform all requested operations: No such file or directory

I also tried with a couple of terminal programs including the "Serial Port API sample" app. The device never responds, and I think it is for the same reason (the baud rate isn't set to 38400). Note I can select the baud rate in these programs but I don't think it is actually set - stty still reports 9600.

I feel like I am very close to at least talking to the ELM327 but I am missing something. The Torque app claims to have found the OBD2 adaptor, but I can't actually connect it to a vehicle right now so I don't know if it actually works. In any case I need to access it from my own app.

Wondering if anyone knows the answer to this problem... I can write my own app to access /dev/ttyUSB0 (in theory...) but don't want to waste my time if it's hopeless!



Aucun commentaire:

Enregistrer un commentaire