Comments (6)
Hi, you are not so far from it. In your case, you need to define a codec with a decode
method not encode and you must specify the codec object in your config, not a function. The payload comes in as a binary string. Something like that should do (untested).
class MyCustomCodec(DidCodec):
def decode(self, payload):
return (int(payload[0]) << 8 + int(payload[1])) * 0.01544
def __len__(self):
return 2
config['data_identifiers'] = {0x019E: MyCustomCodec}
from python-udsoncan.
Hello pylessard,
Thank you for your guidance.
It seems that I have to define a Class first, which contains the decode(formula) and the response length, then I can call this through the 'config'.
But I don't understand why it return (int(payload[0]) << 8 + int(payload(1))) * 0.01544, actually, I want to do something for the byte4 and byte5 of the response(0x05 0x62 0x01 0x9E 0x03 0x1F). Do the payload[0] and payload[1] represent byte4 and byte5?
Could you please help to explain again?
I tried to run below codes, but the error is TypeError: 'bytes' object is not callable
class MyCustomCodec(udsoncan.DidCodec):
def decode(self, payload):
return (int(payload[0]) << 8 + int(payload(1))) * 0.01544
def __len__(self):
return 2
config['data_identifiers'] = {0x019E: MyCustomCodec}
from python-udsoncan.
Hi,
The problem is because of the paranthesis used for byte 1. Use square bracket instead. My apologies, I wrote paranthesis in my answer (I work a lot with Matlab, and that software use paranthesis instead of square brackets). I updated my answer.
As for the byte offset, the library strip off the rest of the response. It only feeds the Did data to the Codec.
Regards
from python-udsoncan.
Hello pylessard,
Thanks for your help. Now it can work as I hope. :) Really appreciated.
I am new to Python and this library. I also didn't notice the parentheses issue previously.
By the way, I can find the encode
method in the example of ReadDataByIdentifier, I want to ask, in which case need to define this method?
from python-udsoncan.
Good,
Encode is when you use WriteDataByIdentifier
from python-udsoncan.
Understand, thanks :)
from python-udsoncan.
Related Issues (20)
- the logging module and can data are inconsistent HOT 12
- Expect `suppress_positive_response` response NRC HOT 12
- Add manufacturer specific sid HOT 1
- Pass data to request_seed via unlock_security_access HOT 5
- Socket timeout when trying to send data on second socket HOT 24
- Using J2534Connection: No data received HOT 8
- How to implement the canfd flash based on the python-can library HOT 4
- Logging configuration changes behavior of transfer buffers? HOT 4
- ascii DidCodec pass parameters HOT 1
- 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
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.