dbc¶
-
dbc.
DATABASE_FLAG_J1939
= 1¶
Dbc¶
-
class
canlib.kvadblib.
Dbc
(filename=None, name=None, protocol=None)[source]¶ Holds a dbc database.
There are three ways to create a database:
- To load data from an existing database file, only set filename to the database filename.
- To add an empty database, set only name.
- To load data from an existing database file and give it a new name, set name to the new name and filename to the existing database filename.
Either a name or a filename must be given.
Parameters: - filename (str, optional) – The existing database file is read.
- name (str, optional) – The database name will be set.
Raises: KvdDbFileParse
– If the database file can’t be parsed.When parsing a database file fails,
get_last_parse_error
can be called:try: kvadblib.Dbc(filename="database.dbc") except kvadblib.KvdDbFileParse: print(kvadblib.get_last_parse_error())
Changed in version 1.10:
Dbc
now raises specific errors depending on the situation.-
delete_attribute_definition
(name)[source]¶ Delete attribute definition from database.
New in version 1.7.
-
delete_message
(message)[source]¶ Delete message from database.
Parameters: message ( Message
) – message to be deleted
-
flags
¶ Get the database flags.
E.g. DATABASE_FLAG_J1939
-
get_attribute_definition_by_name
(name)[source]¶ Find attribute definition using name.
Parameters: name (str) – name of attribute definition Returns an attribute definition object depending on type, e.g. if the type is AttributeType.INTEGER, an
IntegerAttributeDefinition
is returned.
-
get_attribute_value
(name)[source]¶ Return attribute value
If the attribute is not set on the database, we return the attribute definition default value.
New in version 1.6.
-
get_message
(id=None, name=None)[source]¶ Find message by id or name
If both id and name is given, both most match.
Note that bit 31 of the id indicates if the message has an extended id or not.
Parameters: - id (int) – message id to look for
- name (str) – message name to look for
Returns: Raises: KvdNoMessage
– If no match was found, or if none ofid
andname
were given.
-
get_message_by_id
(id, flags)[source]¶ Find message by id.
Parameters: - id (int) – message id to look for
- flags (int) – message flags, e.g.
kvadblib.MessageFlag.EXT
(Note thatkvadblib.MessageFlag.EXT
!=canlib.MessageFlag.EXT
)
Returns: Raises: KvdNoMessage
– If no match was found.
-
get_message_by_name
(name)[source]¶ Find message by name
Parameters: name (str) – message name to look for Returns: Message
Raises: KvdNoMessage
– If no match was found.
-
get_message_by_pgn
(can_id)[source]¶ Find message by PGN
Note
The
can_id
must have the “EXT” flag bit set (bit 30, 0x40000000)Parameters: can_id (int) – CAN id containing PGN to look for Returns: Message
Raises: KvdNoMessage
– If no match was found.New in version 1.18.
-
get_node_by_name
(name)[source]¶ Find node by name
Parameters: name (str) – node name to look for Returns: Node
Raises: KvdNoNode
– If no match was found.
-
messages
(show_all=True)[source]¶ Return a generator of all database messages.
If you would like to omit the special message ‘VECTOR__INDEPENDENT_SIG_MSG’, which is used to collect removed signals under, set show_all to False or use the Dbc iterator directly:
db = kvadblib.Dbc(filename='mydb.dbc') for message in db: print(msg)
Parameters: show_all ( bool
) – If true, all messages, including any special message such as ‘VECTOR__INDEPENDENT_SIG_MSG’ will be returnedChanged in version 1.8: Added argument show_all.
-
name
¶ The current database name (read-only)
Type: str
-
new_attribute_definition
(name, owner, type, definition)[source]¶ Create a new attribute definition in the database.
The owner specify where the attribute is applicable, e.g.
AttributeOwner.MESSAGE
specifies that this attribute is only applicable on messages (Message
).Parameters: - name (str) – a unique name.
- owner (
AttributeOwner
) – the owner type
Returns:
-
new_message
(name, id, flags=0, dlc=None, comment=None)[source]¶ Create a new message in the database.
Parameters: - name (str) – name of message
- id (int) – message id
- flags (int, optional) – message flags, e.g.
kvadblib.MessageFlag.EXT
Returns: canlib.kvadblib.message.Message
-
new_node
(name, comment=None)[source]¶ Create a new node in the database.
Parameters: - name (str) – name of message
- comment (str, optional) – message comment
Returns:
-
node_in_signal
(node, signal)[source]¶ Check if signal has been added to node.
Returns: True – signals contains node False: otherwise
-
protocol
¶ The database protocol
Type: ProtocolType
get_last_parse_error()¶
-
canlib.kvadblib.
get_last_parse_error
()[source]¶ Can be used to get the specific reason why
KvdDbFileParse
was raised.Returns: str
– Error message from the parser.New in version 1.10.