-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapter cable types supported on Linux-like OSes #35
Comments
The reason that only FTDI adapters are supported under Linux is that the kw1281 protocol wakes up a module in the car by sending the address of the module at 5 baud and then waiting to receive an acknowledgement at 9600 or 10400 baud. 5 baud is not supported by most serial APIs and even when supported, switching from 5 baud to a higher baud rate often takes too much time reprogram the UART chip timing, which results in missing the acknowledgement. To work around that problem, kw1281test simulates the 5 baud wakeup by sending a break or clearing a break on the serial line for 200ms per bit. This works fine on Windows but the Linux/macOS serial port API does not support sending a break signal for a specific amount of time: https://linux.die.net/man/4/tty_ioctl "Sending a break TCSBRK int arg At least that's my experience when I tried to get kw1281test working under macOS and Linux using a regular serial port. The FTDI Linux/macOS driver supports more precise timing of the break signal. Of course if your experience is different and you successfully get it to work with a CH340 cable, please let me know. |
Thanks for the clarification. Great there are people like you who have both car and IT knowledge – FOSS car diagnostics tends to be a niche because most FOSS devs don’t seem to have cars, and most DIY car mechanics seem to shun computers. Anyways, I have little experience with that kind of low-level bit banging. Having (re-)read the part on KW1281 initialization at https://www.blafusel.de/obd/obd2_kw1281.html, a few approaches came to my mind:
|
@mvglasow It would be very much appreciated if you could get it working on CH340, so I don't mean to put a damper on that. RS232 KKL Interface USB to RS232 with FT232 I am operating with the above ECUFix cable and SH-RS232A combination and have confirmed in the past that it also works with FT232BM and a cable using an external EEPROM. So, I hope that the operation with CH340 will be successful. |
@accept Thanks, getting a serial KKL cable and separate USB-serial adapter really sounds like an option. Fortunately, I got my cable these days and it is FTDI. Nonetheless, having to disable USB-serial kernel modules or messing with USB device identification is not particularly nice. So, if the regular serial driver stack were supported on Linux, that would be a huge plus. |
Back on topic: I have had a chance to look at another tool, buried in the source code of AndrOBD and to my knowledge never published as a tool in its own right – however the author claims to have used it successfully. It is written in Java and relies on the RXTX library for serial communication, which ultimately translates into calls to the serial API. Said tool sends the bits of the slow-init sequence by turning break on or off, then sleeping for 200 ms before sending the next bit. As I understand the manpages on Ubuntu 22.04, this should translate into calls to Alternatively,
Calling that with an |
Thanks for doing the research on this. I'm pretty sure I tried this a year or two ago and discovered that macOS would not allow precise timing of TIOCSBRK/TIOCCBRK (I have a logic analyzer so I can see the timing of what shows up on the k-line when I run kw1281test). When I get some free time I'll try again and see if I get better results. |
I think AndrOBD may not be that useful for examples of how to implement the 5-baud wakeup. AndrOBD relies on an ELM327 adapter, which has built-in 5-baud initialization. If you discover otherwise, please let me know and point me at the relevant source code. |
That does seem to be implemented in the Linux source code, so I'll see if I can implement it: https://github.com/torvalds/linux/blob/master/drivers/tty/tty_io.c
|
AndrOBD proper relies on the ELM327 and therefore does not need any of the baud-switching tricks. However, it is built on top of a JRE application the author built a few years earlier, which is intended for use with a dumb USB or serial KKL cable and has support for both OBD-II and KW1281. Some parts of the source code were reused in AndrOBD; the app itself can be found in the |
New LinuxInterface may solve the problem. |
According to the documentation, on Windows the cable needs to present a COM port and is addressed as such, whereas on Unix-like OSes (Linux and Mac) only FTDI adapters are supported (as far as I understand), which are addressed by the adapter ID.
Looking at the source code, I am getting a different picture: the string submitted on the command line is matched against a regex to determine if it is an alphanumeric string of exactly 8 characters. If so, it is a valid FTDI adapter ID and treated as such, i.e. kw1281test will open an FTDI interface with the given ID. Anything else is treated as a serial port.
Therefore, e.g.
COM3
would cause kw1281test to open a serial port with that name, which is what happens on Windows.However,
/dev/ttyUSB0
would also be treated as a standard serial port. Would I be able to make use of that on Linux/MacOS if my adapter presents itself as a serial port, by specifying its filesystem path, and thus be able to use any adapter that the OS sees as a serial port?If so, then CH340-based adapters should work on Linux – I have successfully used a USB to RS232 adapter based on the CH340 for serial console access on Linux (Ubuntu 18.04, 20.04 an 22.04 – the latter required a modification because of a Braille terminal using the same USB ID as my adapter, preventing it from being recognized as a serial port). In that case, the documentation should be amended to include that any adapter that creates a
/dev/tty*
node should work on Linux.PS: I have taken the risk and just ordered a USB KKL cable – no idea what chipset it uses, but I will report back on my Linux experience once it arrives.
The text was updated successfully, but these errors were encountered: