@@ -109,6 +109,49 @@ Security algorithm implementation
109109
110110-----
111111
112+
113+
114+ .. _reading_a_did :
115+
116+ Reading a DID with ReadDataByIdentifier
117+ ---------------------------------------
118+
119+ This example shows how to configure the client with a DID configuration and request the server with ReadDataByIdentifier
120+
121+ .. code-block :: python
122+
123+ import udsoncan
124+ from udsoncan.Connection import IsoTPConnection
125+ from udsoncan.client import Client
126+ import udsoncan.configs
127+
128+ class MyCustomCodecThatShiftBy4 (udsoncan .DidCodec ):
129+ def encode (self , val ):
130+ val = (val << 4 ) & 0x FFFFFFFF # Do some stuff
131+ return struct.pack(' <L' , val) # Little endian, 32 bit value
132+
133+ def decode (self , payload ):
134+ val = struct.unpack(' <L' , payload)[0 ] # decode the 32 bits value
135+ return val >> 4 # Do some stuff (reversed)
136+
137+ def __len__ (self ):
138+ return 4 # encoded paylaod is 4 byte long.
139+
140+
141+ config = dict (udsoncan.configs.default_client_config)
142+ config[' data_identifiers' ] = {
143+ 0x 1234 : MyCustomCodecThatShiftBy4, # Uses own custom defined codec. Giving the class is ok
144+ 0x 1235 : MyCustomCodecThatShiftBy4(), # Same as 0x1234, giving an instance is good also
145+ 0x F190 : udsoncan.AsciiCodec(15 ) # Codec that read ASCII string. We must tell the length of the string
146+ }
147+
148+ conn = IsoTPConnection(' vcan0' , rxid = 0x 123 , txid = 0x 456 )
149+ with Client(conn, request_timeout = 2 , config = config) as client:
150+ vin = client.read_data_by_identifier(0x F190 )
151+ print (vin) # 'ABCDE0123456789' (15 chars)
152+
153+
154+
112155 .. _iocontrol_composite_did :
113156
114157InputOutputControlByIdentifier Composite DID
0 commit comments