css-electronics / can_decoder Goto Github PK
View Code? Open in Web Editor NEWAPI module for decoding raw CAN bus data to physical values
License: MIT License
API module for decoding raw CAN bus data to physical values
License: MIT License
It seems the function "df_decoder.decode_frame(df_raw_1)" only supports decoding J1939 CAN with a J1939 dbc. Is it possible to get this function to support decoding standard CAN with a standard DBC (regular single frame CAN messages - no Transport protocol)?
Thanks for you help,
Hello Team,
I am working with the can_decoder recently and I have the following use case:
I have more than 1 CAN signals with the same names on the same CAN channel, however these signals are from different CAN frames, but the current decoder dataframe returns only the names of the Signals.
I need to get also the names of the CAN frames from the can_decoder( decoded from a DBC) so that I can push these CAN signals to InfluxDB, with a prefix of the CAN frame name in front of the signal and in that way to differentiate which CAN signal is part of which CAN frame.
Thanks.
Currently only decoding a .dbc
from its pathname is supported and I have a use case where I'd like to decode the contents of a .dbc
file as an in-memory binary stream
(see: link) function below:
can_decoder.load_dbc()
As of now, the function takes in a pathname containing the .dbc
file and then reads the file in as an in-memory binary stream
.
can_decoder/can_decoder/DBCLoader.py
Lines 26 to 27 in 5bb4d7a
An easy fix to support using both the pathname and in-memory
binary stream would be simply to remove the line below :
can_decoder/can_decoder/DBCLoader.py
Line 26 in 5bb4d7a
and have the user read data from a path as part of the client code like so:
with open(mdf_path, "rb") as handle:
dbc_file = can_decoder.load_dbc(handle)
df_decoder = can_decoder.DataFrameDecoder(dbc_file)
then users who want to pass in the in-memory binary stream
can then do:
decoded_str = base64.b64decode(...)
dbc_file = can_decoder.load_dbc(io.BytesIO(decoded_str))
CC: @dflyon
Hi,
I am using the dbc file from CSS electronics to decode CAN Data.
I have CAN data as following format:
CF00400#FFFFFFC080FFFFFF
first part is CAN Id (or frame id) : CF00400
second part (CAN data) : FFFFFFC080FFFFFF
How do I decode this CAN data using the can_decoder?
df_decoder.decode_frame(df_raw, columns_to_drop=["CAN ID", "Raw Value"])
How do I construct the df_raw based on above CAN data?
When decoding, this line can sometimes lead to the following error: "ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. ...โ
After looking into it, I believe the problem is, that for some signals not all lists (a) in in the data_list have the same number of columns. Having lines with different column numbers leads to the value error. The assignment "np.array(..)" cannot handle different numbers of columns.
e.g.: For one signal, the first "a" had 63 values, while the next "a" had only 19 values.
I solved it like this:
frame_data = pd.DataFrame([a for a in data_lists]).to_numpy(dtype=np.uint8)
This way, the the "missing columns" are replace with the default value of .to_numpy(dtype=np.uint8)
, which is "0".
Could you please verify this correction?
I have been using this code from the documentation to decode my MF4 files but for the past few days, the code has stopped working. Following is the code:
import can_decoder
import mdf_iter
mdf_path = "00000001.MF4"
dbc_path = "j1939.dbc"
db = can_decoder.load_dbc(dbc_path)
df_decoder = can_decoder.DataFrameDecoder(db)
with open(mdf_path, "rb") as handle:
mdf_file = mdf_iter.MdfFile(handle)
df_raw = mdf_file.get_data_frame()
df_phys = df_decoder.decode_frame(df_raw)
print(df_phys)
Now its showing error as follows:
Attribution Error: 'can_decoder' has no attribute 'load_dbc'
Hi
I am getting this below issue while running setup_decoding_rules.py file
arxml is not supported
Traceback (most recent call last):
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\site-packages\canmatrix\formats_init_.py", line 27, in
importlib.import_module("canmatrix.formats." + module)
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\importlib_init_.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in load_unlocked
File "", line 728, in exec_module
File "", line 219, in call_with_frames_removed
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\site-packages\canmatrix\formats\arxml.py", line 34, in
import lxml.etree
ModuleNotFoundError: No module named 'lxml'
kcd is not supported
Traceback (most recent call last):
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\site-packages\canmatrix\formats_init.py", line 27, in
importlib.import_module("canmatrix.formats." + module)
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\importlib_init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in load_unlocked
File "", line 728, in exec_module
File "", line 219, in call_with_frames_removed
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\site-packages\canmatrix\formats\kcd.py", line 35, in
import lxml.etree
ModuleNotFoundError: No module named 'lxml'
fibex is not supported
Traceback (most recent call last):
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\site-packages\canmatrix\formats_init.py", line 27, in
importlib.import_module("canmatrix.formats." + module)
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\importlib_init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in load_unlocked
File "", line 728, in exec_module
File "", line 219, in call_with_frames_removed
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\site-packages\canmatrix\formats\fibex.py", line 33, in
import lxml.etree
ModuleNotFoundError: No module named 'lxml'
xls is not supported
Traceback (most recent call last):
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\site-packages\canmatrix\formats_init.py", line 27, in
importlib.import_module("canmatrix.formats." + module)
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\importlib_init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in load_unlocked
File "", line 728, in exec_module
File "", line 219, in call_with_frames_removed
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\site-packages\canmatrix\formats\xls.py", line 34, in
import xlrd
ModuleNotFoundError: No module named 'xlrd'
xlsx is not supported
Traceback (most recent call last):
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\site-packages\canmatrix\formats_init.py", line 27, in
importlib.import_module("canmatrix.formats." + module)
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\importlib_init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in load_unlocked
File "", line 728, in exec_module
File "", line 219, in call_with_frames_removed
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\site-packages\canmatrix\formats\xlsx.py", line 32, in
import xlsxwriter
ModuleNotFoundError: No module named 'xlsxwriter'
yaml is not supported
Traceback (most recent call last):
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\site-packages\canmatrix\formats_init.py", line 27, in
importlib.import_module("canmatrix.formats." + module)
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\importlib_init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "C:\Users\kalaa\AppData\Local\Programs\Python\Python37\lib\site-packages\canmatrix\formats\yaml.py", line 32, in
import yaml
ModuleNotFoundError: No module named 'yaml'
Traceback (most recent call last):
File "C:\Users\kalaa\OneDrive\Desktop\can_decoder\examples\setup_decoding_rules.py", line 143, in
example_setup_decoding_rules_j1939()
File "C:\Users\kalaa\OneDrive\Desktop\can_decoder\examples\setup_decoding_rules.py", line 72, in example_setup_decoding_rules_j1939
decoded_result = decode_using_rules(handle, db)
File "C:\Users\kalaa\OneDrive\Desktop\can_decoder\examples\setup_decoding_rules.py", line 30, in decode_using_rules
mdf_file = mdf_iter.MdfFile(handle)
RuntimeError: Buffer error
Will this library handle overlapping signals in same message
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.