Open ofauchon opened 2 months ago
Got curious and tried this out, given example of reading fault codes from ECU works, but limited support of baud rates is troublesome, using suggested 10400 for cluster:
Version 0.97.0-beta (https://github.com/gmenounos/kw1281test/releases) Args: /dev/ttyUSB0 10400 1 GetSKC OSVersion: Unix 6.8.11.300 .NET Version: 8.0.4 Culture: en-US Opening Linux serial port /dev/ttyUSB0 Caught: System.IO.IOException Unknown/invalid baudrate Unhandled exception: System.IO.IOException: Unknown/invalid baudrate at BitFab.KW1281Test.Interface.LinuxInterface.SetBaudRate(Int32 baudRate) in /home/sveshais/Downloads/kw1281test-linux-native-interface/Interface/LinuxInterface.cs:line 211 at BitFab.KW1281Test.Interface.LinuxInterface..ctor(String portName, Int32 baudRate) in /home/sveshais/Downloads/kw1281test-linux-native-interface/Interface/LinuxInterface.cs:line 127 at BitFab.KW1281Test.Program.OpenPort(String portName, Int32 baudRate) in /home/sveshais/Downloads/kw1281test-linux-native-interface/Program.cs:line 501 at BitFab.KW1281Test.Program.Run(String[] args) in /home/sveshais/Downloads/kw1281test-linux-native-interface/Program.cs:line 259 at BitFab.KW1281Test.Program.Main(String[] args) in /home/sveshais/Downloads/kw1281test-linux-native-interface/Program.cs:line 31
Thanks for testing this feature. I'll try to improve the code so it can handle custom baudrates.
Some informations here: https://www.downtowndougbrown.com/2013/11/linux-custom-serial-baud-rates/
Support for 10400 baud in particular should be retained. The cluster that I have on my bench (1J0919991BX) uses 10400 baud. The VW Premium 5 radio from Delco also uses 10400 baud.
Many radios have a feature where they will connect to the cluster using KWP1281 in order to automatically unlock from SAFE mode. I disassembled the code for this in several radios and found they were hardcoded to expect 10400 baud from the cluster, which suggests that 10400 baud is widely used in the clusters.
KW1281 protocol requires a special 5 bauds byte transmission to wake up device (eg:ECU) on the K-Line. Such very low baud rates are generally not supported by OSes and uart chipsets.
The trick is to bit bang this first 'init' byte at 5 bauds: Break signals are used to drive the UART TX Line low during transmission.
Although this trick works properly on Windows, .Net Linux implementation don't seem to handle properly line breaks
Here comes the new LinuxInterface...
This new interface implements UART access in a more direct/low level way (without using .Net framework). As the code uses "libc" calls, it could break the build on Windows .
The workaround is to compile the driver only when building on Linux OS. This is done by detecting the OS through .csproj directives, and use macros (#if Linux) in the code.
This PR had been tested on Arch Linux, FT232 KLL Cable:
All comments/feedback welcome