You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`OBDCommand`s are objects used to query information from the vehicle. They contain all of the information neccessary to perform the query, and decode the cars response. Python-OBD has [built in tables](Command Tables.md) for the most common commands. They can be looked up by name, or by mode & PID.
2
+
3
+
```python
4
+
import obd
5
+
6
+
c = obd.commands.RPM
7
+
8
+
# OR
9
+
10
+
c = obd.commands['RPM']
11
+
12
+
# OR
13
+
14
+
c = obd.commands[1][12] # mode 1, PID 12 (RPM)
15
+
```
16
+
17
+
The `commands` table also has a few helper methods for determining if a particular name or PID is present.
18
+
19
+
---
20
+
21
+
### has_command(command)
22
+
23
+
Checks the internal command tables for the existance of the given `OBDCommand` object. Commands are compared by mode and PID value.
24
+
25
+
```python
26
+
import obd
27
+
obd.commands.has_command(obd.commands.RPM) # True
28
+
```
29
+
30
+
---
31
+
32
+
### has_name(name)
33
+
34
+
Checks the internal command tables for a command with the given name. This is also the function of the `in` operator.
35
+
36
+
```python
37
+
import obd
38
+
39
+
obd.commands.has_name('RPM') # True
40
+
41
+
# OR
42
+
43
+
'RPM'in obd.commands # True
44
+
```
45
+
46
+
---
47
+
48
+
### has_pid(mode, pid)
49
+
50
+
Checks the internal command tables for a command with the given mode and PID.
`portstr`: The UNIX device file or Windows COM Port for your adapter. The default value (`None`) will auto select a port.
26
26
27
-
`baudrate`: The baudrate at which to set the serial connection. This can vary from adapter to adapter. Typical values are: 9600, 38400, 19200, 57600, 115200
27
+
`baudrate`: The baudrate at which to set the serial connection. This can vary from adapter to adapter. Typical values are: 9600, 38400, 19200, 57600, 115200. The default value (`None`) will auto select a baudrate.
28
28
29
-
`protocol`: Forces python-OBD to use the given protocol when communicating with the adapter. See `protocol_id()` for possible values. The default value (`None`) will auto select a protocol.
29
+
`protocol`: Forces python-OBD to use the given protocol when communicating with the adapter. See [protocol_id()](Connections.md/#protocol_id) for possible values. The default value (`None`) will auto select a protocol.
30
30
31
31
`fast`: Allows commands to be optimized before being sent to the car. Python-OBD currently makes two such optimizations:
32
32
@@ -41,7 +41,7 @@ Disabling fast mode will guarantee that python-OBD outputs the unaltered command
41
41
42
42
### query(command, force=False)
43
43
44
-
Sends an `OBDCommand` to the car, and returns a`OBDResponse` object. This function will block until a response is received from the car. This function will also check whether the given command is supported by your car. If a command is not marked as supported, it will not be sent to the car, and an empty `Response` will be returned. To force an unsupported command to be sent, there is an optional `force` parameter for your convenience.
44
+
Sends an `OBDCommand` to the car, and returns an`OBDResponse` object. This function will block until a response is received from the car. This function will also check whether the given command is supported by your car. If a command is not marked as supported, it will not be sent, and an empty `OBDResponse` will be returned. To force an unsupported command to be sent, there is an optional `force` parameter for your convenience.
45
45
46
46
*For non-blocking querying, see [Async Querying](Async Connections.md)*
Returns the string name for the currently connected port (`"/dev/ttyUSB0"`). If no connection was made, this function returns `"Not connected to any port"`.
91
-
92
-
---
93
-
94
-
### get_port_name()
95
-
96
-
**Deprecated:** use `port_name()` instead
90
+
Returns the string name for the currently connected port (`"/dev/ttyUSB0"`). If no connection was made, this function returns an empty string.
97
91
98
92
---
99
93
@@ -148,8 +142,17 @@ Closes the connection.
148
142
149
143
### supported_commands
150
144
151
-
Property containing a list of commands that are supported by the car.
145
+
Property containing a `set` of commands that are supported by the car.
146
+
147
+
If you wish to manually mark a command as supported (prevents having to use `query(force=True)`), add the command to this set. This is not necessary when using python-OBD's builtin commands, but is useful if you create [custom commands](Custom Commands.md).
0 commit comments