Comments (4)
Because your codec is only "@" which specify the bit order but not the data type. The library believe that your payload is 0 bytes long because of that, then start parsing 0040 like a 2nd DID. I guess I could throw an exception when the pack string is 0 bytes long.
try a pack string like "L" for 32 bits DID or "H" for 16 bits. see https://docs.python.org/2/library/struct.html#byte-order-size-and-alignment
from python-udsoncan.
Hi @pylessard, im currently also facing this issue for reading wrong VIN number DID 0xF190, i used your example code as below
import udsoncan
from udsoncan.connections import IsoTPSocketConnection
from udsoncan.client import Client
import udsoncan.configs
import struct
class MyCustomCodecThatShiftBy4(udsoncan.DidCodec):
def encode(self, val):
val = (val << 4) & 0xFFFFFFFF # Do some stuff
return struct.pack('<L', val) # Little endian, 32 bit value
def decode(self, payload):
val = struct.unpack('<L', payload)[0] # decode the 32 bits value
return val >> 4 # Do some stuff (reversed)
def __len__(self):
return 4 # encoded payload is 4 byte long.
config = dict(udsoncan.configs.default_client_config)
config['data_identifiers'] = {
'default' : '>H', # Default codec is a struct.pack/unpack string. 16bits little endian
0x1234 : MyCustomCodecThatShiftBy4, # Uses own custom defined codec. Giving the class is ok
0x1235 : MyCustomCodecThatShiftBy4(), # Same as 0x1234, giving an instance is good also
0xF190 : udsoncan.AsciiCodec(15) # Codec that read ASCII string. We must tell the length of the string
}
# IsoTPSocketconnection only works with SocketCAN under Linux. Use another connection if needed.
conn = IsoTPSocketConnection('vcan0', rxid=0x123, txid=0x456)
with Client(conn, request_timeout=2, config=config) as client:
response = client.read_data_by_identifier([0xF190])
print(response.service_data.values[0xF190]) # This is a dict of DID:Value
# Or, if a single DID is expected, a shortcut to read the value of the first DID
vin = client.read_data_by_identifier_first(0xF190)
print(vin) # 'ABCDE0123456789' (15 chars)
And below is exception output i received:
[UnexpectedResponseException] : ReadDataByIdentifier service execution returned a valid response but unexpected. Details : Server returned values for data identifier 0x3536 that was not requested and no Codec was defined for it. Parsing must be stopped.
[UnexpectedResponseException] : ReadDataByIdentifier service execution returned a valid response but unexpected. Details : Server returned values for data identifier 0x3536 that was not requested and no Codec was defined for it. Parsing must be stopped.
Server sent an invalid payload : bytearray(...)
What's wrong? Please help me to answer this. Thank you!
from python-udsoncan.
First of all, the examples are examples. It does not mean that they will work in the field as is.
UDS protocol defines some interface but also leaves a lot of freedom to the ECU manufacturer, meaning they can change the data meaning at will.
To debug your issue, look at the raw can log.
My guess here is that the ECU is returning a DID longer than 15 chars and the extra bytes is interpreted as the beginning of the next DID.
from python-udsoncan.
First of all, the examples are examples. It does not mean that they will work in the field as is. UDS protocol defines some interface but also leaves a lot of freedom to the ECU manufacturer, meaning they can change the data meaning at will.
To debug your issue, look at the raw can log.
My guess here is that the ECU is returning a DID longer than 15 chars and the extra bytes is interpreted as the beginning of the next DID.
thank you so much for pointing it out, you guessed correctly, my DID response 17 chars, I normally read VIN number now.
from python-udsoncan.
Related Issues (20)
- DID codec behavior for DIDs not in DidConfig HOT 25
- ReadDataByIdentifier.py TimeoutException Did not receive response in time HOT 2
- send uds req with suppress postive response bit failed HOT 3
- Allow requesting a did without decoding it HOT 11
- Unexpected UDS Authentication message byte order(Subfunction 0x05,0x6) HOT 12
- IsoTPSocketConnection can not be closed with tpsock in blocking mode HOT 5
- struct.error on change_session interpret_response HOT 9
- PythonIsoTpConnection [cilent.py]send_request() tigger TimeoutException,then ISOTP rxthread_task run isotp_send() HOT 7
- IsoTPSocketConnection doesn't work with can-isotp versions 2 and up HOT 9
- Performance tests HOT 16
- When using CAN as a diagnostic channel,other application messages are sent periodically on the bus, calling the client.change_session interface will block at the self.conn.empty_rxqueue() interface. HOT 3
- cannot import name 'Literal' from 'typing' (/usr/lib/python3.7/typing.py) HOT 8
- Act as server and parse python-can messages HOT 6
- No data received: [TimeoutException] Problem HOT 12
- ReadDataByIdentifier: no codec.encode() ? HOT 6
- Security access SAPR response not correctly interpreted HOT 3
- WriteDataByIdentifier service execution returned a negative response IncorrectMessageLengthOrInvalidFormat (0x13) when data length is correct HOT 4
- Adding parameter to Communication Control Service(0x28) HOT 10
- SecurityAccess mishandes a level value of 0 HOT 3
- SocketConnection cannot be closed HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-udsoncan.