rzetterberg / elmobd

A Go library for talking to cars over OBD-II
MIT License
223 stars 41 forks source link

Does this library work with ELM327-emulator? #32

Closed jrcichra closed 3 months ago

jrcichra commented 4 years ago

Description

I'm trying to test this library against https://github.com/Ircama/ELM327-emulator. I got this error after doing the following:


justin@justin-3900x:~/git/ELM327-emulator$ python3 -m elm
2020-03-22 10:22:00,993 - root - INFO - 

ELM327 OBD-II adapter emulator started

Welcome to the ELM327 OBDII adapter emulator.
ELM327-emulator is running on /dev/pts/3
Type help or ? to list commands.

CMD> run 
Error executing command: name 'run' is not defined
CMD> help

Available commands include the following list (type help <topic>
for more information on each command). Besides, any Python
command is accepted. Autocompletion is fully allowed.
================================================================
color     default  engineoff  history  pause   quit   resume    wait
counters  delay    help       merge    prompt  reset  scenario

CMD> scenario 
AT         car        default    engineoff  
CMD> scenario car
Emulator scenario switched to 'car'
ATZ> ATZ

------
func main() {
    serialPath := flag.String(
        "serial",
        "/dev/pts/3", // "/dev/ttyUSB0",
        "Path to the serial device to use",
    )

    flag.Parse()

    dev, err := elmobd.NewDevice(*serialPath, true)

    if err != nil {
        fmt.Println("Failed to create new device", err)
        return
    }

justin@justin-3900x:~/git/smartcar/containers/obdii$ ./obdii 
Failed to create new device Write echo mismatch: "ATZ" not suffix of ""
justin@justin-3900x:~/git/smartcar/containers/obdii$ 

# Environment
- [ ] **Operating system:** Ubuntu 19.10
- [ ] **Go version**: 1.13
- [ ] **Git commit**: 334e700512ddaaf69fcd31a95542b31a01de8218
- [ ] **ELM327 device version**: https://github.com/Ircama/ELM327-emulator 
jrcichra commented 4 years ago

Here's what I'm seeing stepping through with VSCode debugging:

image

jrcichra commented 4 years ago

I'm betting it's because the mentioned library does not start with echoing...

rzetterberg commented 4 years ago

Hey @jrcichra!

I have never used an emulator before, but I have been wanting to add an emulator in the testing suite. So thanks for bring that to my attention.

Yes, the problem you are encountering has to do with the library expecting the device to echo back all commands that you send to it.

The library does two things when it is initialized:

Resetting a device will cause the device to use the default factory settings, one of which is enabling echoing. This is the default behavior of a real ELM327-device according to the data sheet.

The goal of this library was to make it easy to use, hence the resetting, automatic protocol discovery, echo verification etc. However, lately I have been thinking about changing how the library works, so that only the user of the library decides which commands are sent to the device, and not the library. This (your problem) is another reason why changing how the library works is a good idea.

What I will do is change how the library works, and then I'm sure you will be able to use the emulator. After that we can look at how we could integrate the emulator in the test suite.

jrcichra commented 4 years ago

I'm thinking now, if the data sheet for ELM327 should have echoing on by default, it makes more sense to fix the emulator, not this codebase.

I like the ease of use this library presents. Maybe we can add checks for non-standard ELM327 behaviors and account for them.