Skip to content

Commit 0629774

Browse files
authored
Doc improvement (#271)
1 parent e9a4a4f commit 0629774

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

doc/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ Here is an example of code to give an insight of the grammar.
5050
client.ecu_reset(ECUReset.ResetType.hardReset) # HardReset = 0x01
5151
except NegativeResponseException as e:
5252
print('Server refused our request for service %s with code "%s" (0x%02x)' % (e.response.service.get_name(), e.response.code_name, e.response.code))
53-
except InvalidResponseException, UnexpectedResponseException as e:
53+
except (InvalidResponseException, UnexpectedResponseException) as e:
5454
print('Server sent an invalid payload : %s' % e.response.original_payload)
5555

doc/source/udsoncan/examples.rst

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,62 @@ Examples
66
Different layers of intelligence (1 to 4)
77
-----------------------------------------
88

9-
In the following examples, we will request an ECU reset in 4 different ways. We will start by crafting a binary payload manually, then we will add a layer of interpretation making the code more comprehensive each time.
9+
In the following examples, we will request aa Routine Start with the RoutineControl service in 4 different ways.
10+
We will start by crafting a binary payload manually, then we will add a layer of interpretation making the code more comprehensive each time.
1011

1112
1. Raw Connection
1213
#################
1314

1415
.. code-block:: python
1516
16-
my_connection.send(b'\x11\x01\x77\x88\x99') # Sends ECU Reset, with subfunction = 1
17+
my_connection.send(b'\x31\x01\x12\x34') # Sends RoutineControl, with ControlType=1, Routine ID=0x1234
1718
payload = my_connection.wait_frame(timeout=1)
18-
if payload == b'\x51\x01':
19+
if payload == b'\x71\x01\x12\x34':
1920
print('Success!')
2021
else:
21-
print('Reset failed')
22+
print('Start of routine 0x1234 failed')
2223
2324
2. Request and Responses
2425
########################
2526

2627
.. code-block:: python
2728
28-
req = Request(services.ECUReset, subfunction=1, data=b'\x77\x88\x99')
29+
req = Request(services.RoutineControl, control_type=1, routine_id=0x1234) # control_type=1 --> StartRoutine
2930
my_connection.send(req.get_payload())
3031
payload = my_connection.wait_frame(timeout=1)
3132
response = Response.from_payload(payload)
32-
if response.service == service.ECUReset and response.code == Response.Code.PositiveResponse and response.data == b'\x01':
33+
if response.service == service.RoutineControl and response.code == Response.Code.PositiveResponse and response.data == b'\x01\x12\x34':
3334
print('Success!')
3435
else:
35-
print('Reset failed')
36+
print('Start of routine 0x1234 failed')
3637
3738
3. Services
3839
###########
3940

4041
.. code-block:: python
4142
42-
req = services.ECUReset.make_request(reset_type=1, data=b'\x77\x88\x99')
43+
req = services.RoutineControl.make_request(control_type=services.RoutineControl.ControlType.startRoutine, routine_id=0x1234)
4344
my_connection.send(req.get_payload())
4445
payload = my_connection.wait_frame(timeout=1)
4546
response = Response.from_payload(payload)
4647
services.ECUReset.interpret_response(response)
47-
if response.service == service.ECUReset and response.code == Response.Code.PositiveResponse and response.service_data.reset_type_echo == 1:
48+
if ( response.service == service.RoutineControl and response.code == Response.Code.PositiveResponse
49+
and response.service_data.control_type_echo == 1
50+
and response.service_data.routine_id_echo == 0x1234):
4851
print('Success!')
4952
else:
50-
print('Reset failed')
53+
print('Start of routine 0x1234 failed')
5154
5255
4. Client
5356
#########
5457

5558
.. code-block:: python
5659
5760
try:
58-
client.ecu_reset(reset_type=1, data=b'\x77\x88\x99')
61+
response = client.start_routine(routine_id=0x1234) # control_type_echo and routine_id_echo are validated by the client.
5962
print('Success!')
60-
except:
61-
print('Reset failed')
63+
except Exception:
64+
print('Start of routine 0x1234 failed')
6265
6366
-----
6467

@@ -73,7 +76,7 @@ Note that, in order to run this code, both ``python-can`` and ``can-isotp`` must
7376
.. code-block:: python
7477
7578
import can
76-
import can.interfaces.vector import VectorBus
79+
from can.interfaces.vector import VectorBus
7780
from udsoncan.connections import PythonIsoTpConnection
7881
from udsoncan.client import Client
7982
import udsoncan.configs
@@ -219,7 +222,7 @@ This example shows how to configure the client with a DID configuration and requ
219222
'default' : '>H', # Default codec is a struct.pack/unpack string. 16bits little endian
220223
0x1234 : MyCustomCodecThatShiftBy4, # Uses own custom defined codec. Giving the class is ok
221224
0x1235 : MyCustomCodecThatShiftBy4(), # Same as 0x1234, giving an instance is good also
222-
0xF190 : udsoncan.AsciiCodec(15) # Codec that read ASCII string. We must tell the length of the string
225+
0xF190 : udsoncan.AsciiCodec(17) # Codec that read ASCII string. We must tell the length of the string
223226
}
224227
225228
# IsoTPSocketconnection only works with SocketCAN under Linux. Use another connection if needed.
@@ -230,7 +233,7 @@ This example shows how to configure the client with a DID configuration and requ
230233
231234
# Or, if a single DID is expected, a shortcut to read the value of the first DID
232235
vin = client.read_data_by_identifier_first(0xF190)
233-
print(vin) # 'ABCDE0123456789' (15 chars)
236+
print(vin) # 'ABCDEFG0123456789' (17 chars)
234237
235238
-----
236239

0 commit comments

Comments
 (0)