Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

77%
+5 −0
Q&A Programmatically import, edit and export DBC files

Credit go to @Lundin‭ for pointing me in the right direction. Kvaser has a CAN SDK free of charge. I added this to my VS22 C# project by adding "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser...

posted 10mo ago by HinkyDinky‭  ·  edited 10mo ago by HinkyDinky‭

Answer
#10: Post edited by user avatar HinkyDinky‭ · 2023-08-02T14:03:04Z (10 months ago)
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • **EDIT:**\
  • (Vector CANdb++) If you get unspecified syntax errors: make sure all message/signal names start with a letter and contain only letters, numbers and underscore!
  • (Vector CANdb++) If you get the error: "unknown symbol newly defined" make sure your are not defining two messages with e.g. the same ID.
  • If you want to live debug human readable J1939 messages, with offsets included, use [Busmaster](https://rbei-etas.github.io/busmaster/), it can convert the DBC file to DBF and then use the DBF to interpret the messages.
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • // This part sometimes gave me errors when opening with Vector leaving it out did not make a difference for me.
  • //kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd //VFrameFormat_attr);
  • //kv.SetAttributeDefinitionType(VFrameFormat_attr, //kv.AttributeType.AttributeEnumeration);
  • //kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • //kv.SetAttributeDefinitionOwner(VFrameFormat_attr, //kv.AttributeOwner.AttributeOwnerMessage);
  • //for (int i = 0; i < 4; i++)
  • //kv.SetAttributeDefinitionString(VFrameFormat_attr, //VFrameFormat_enum_names[i], i);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • **EDIT:**\
  • (Vector CANdb++) If you get unspecified syntax errors: make sure all message/signal names start with a letter and contain only letters, numbers and underscore!
  • (Vector CANdb++) If you get the error: "unknown symbol newly defined" make sure your are not defining two messages with e.g. the same ID.
  • If you want to live debug human readable J1939 messages, with offsets included, use [Busmaster](https://rbei-etas.github.io/busmaster/), it can convert the DBC file to DBF and then use the DBF to interpret the messages.
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • // This part sometimes gave me errors when opening with Vector's CANdb++ or Kvaser's database editor 3, leaving it out did not make a difference for me.
  • //kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd //VFrameFormat_attr);
  • //kv.SetAttributeDefinitionType(VFrameFormat_attr, //kv.AttributeType.AttributeEnumeration);
  • //kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • //kv.SetAttributeDefinitionOwner(VFrameFormat_attr, //kv.AttributeOwner.AttributeOwnerMessage);
  • //for (int i = 0; i < 4; i++)
  • //kv.SetAttributeDefinitionString(VFrameFormat_attr, //VFrameFormat_enum_names[i], i);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
#9: Post edited by user avatar HinkyDinky‭ · 2023-08-02T13:59:10Z (10 months ago)
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • **EDIT:**
  • If you get unspecified syntax errors: make sure all message/signal names start with a letter and contain only letters, numbers and underscore!
  • If you get the error: "unknown symbol newly defined" make sure your are not defining two messages with e.g. the same ID.
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i], i);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • **EDIT:**\
  • (Vector CANdb++) If you get unspecified syntax errors: make sure all message/signal names start with a letter and contain only letters, numbers and underscore!
  • (Vector CANdb++) If you get the error: "unknown symbol newly defined" make sure your are not defining two messages with e.g. the same ID.
  • If you want to live debug human readable J1939 messages, with offsets included, use [Busmaster](https://rbei-etas.github.io/busmaster/), it can convert the DBC file to DBF and then use the DBF to interpret the messages.
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • // This part sometimes gave me errors when opening with Vector leaving it out did not make a difference for me.
  • //kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd //VFrameFormat_attr);
  • //kv.SetAttributeDefinitionType(VFrameFormat_attr, //kv.AttributeType.AttributeEnumeration);
  • //kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • //kv.SetAttributeDefinitionOwner(VFrameFormat_attr, //kv.AttributeOwner.AttributeOwnerMessage);
  • //for (int i = 0; i < 4; i++)
  • //kv.SetAttributeDefinitionString(VFrameFormat_attr, //VFrameFormat_enum_names[i], i);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
#8: Post edited by user avatar HinkyDinky‭ · 2023-07-26T10:06:43Z (10 months ago)
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i], i);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
  • **If you get unspecified syntax errors remove non-text characters from signal names!**
  • **If you get the error: "unknown symbol newly defined" make sure your are nto defining 2 messages with e.g. the same ID.**
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • **EDIT:**
  • If you get unspecified syntax errors: make sure all message/signal names start with a letter and contain only letters, numbers and underscore!
  • If you get the error: "unknown symbol newly defined" make sure your are not defining two messages with e.g. the same ID.
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i], i);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
#7: Post edited by user avatar HinkyDinky‭ · 2023-07-26T10:04:05Z (10 months ago)
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i], i);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
  • **If you get unspecified syntax errors remove non-text characters from signal names!**
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i], i);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
  • **If you get unspecified syntax errors remove non-text characters from signal names!**
  • **If you get the error: "unknown symbol newly defined" make sure your are nto defining 2 messages with e.g. the same ID.**
#6: Post edited by user avatar HinkyDinky‭ · 2023-07-20T11:50:05Z (10 months ago)
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i], i);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i], i);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
  • **If you get unspecified syntax errors remove non-text characters from signal names!**
#5: Post edited by user avatar HinkyDinky‭ · 2023-07-12T11:22:25Z (10 months ago)
Fixed bug
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • //for (int i = 0; i < 4; i++)
  • //kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i]); // this line causes kv.WriteFile() to throw an accessviolationexception, except on the first time. I have no idea why :(
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i], i);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
#4: Post edited by user avatar HinkyDinky‭ · 2023-07-12T10:58:11Z (10 months ago)
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i]);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • //for (int i = 0; i < 4; i++)
  • //kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i]); // this line causes kv.WriteFile() to throw an accessviolationexception, except on the first time. I have no idea why :(
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
#3: Post edited by user avatar HinkyDinky‭ · 2023-07-10T09:23:30Z (10 months ago)
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, kv.SignalEncoding.Intel);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i]);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, encoding);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i]);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
#2: Post edited by user avatar HinkyDinky‭ · 2023-07-10T06:06:55Z (10 months ago)
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where you executable is).
  • I ported an .C example application to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, kv.SignalEncoding.Intel);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i]);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
  • Credit go to @Lundin‭ for pointing me in the right direction.
  • Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
  • and
  • "...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.
  • AND (this I was stuck on)
  • Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where your executable is).
  • I ported a C example application from Kvaser to C# and it seems to work:
  • ```
  • using kv = Kvaser.KvadbLib.Kvadblib;
  • List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };
  • void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
  • {
  • kv.AddMsg(dbHnd, out msgHnd);
  • kv.SetMsgName(msgHnd, msgName);
  • kv.SetMsgDlc(msgHnd, dlc);
  • kv.SetMsgIdEx(msgHnd, msgID);
  • kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
  • }
  • void add_sig_to_msg
  • (
  • kv.MessageHnd msgHnd,
  • string sigName,
  • string comment,
  • string unit,
  • kv.SignalEncoding encoding,
  • kv.SignalType type,
  • byte startBit,
  • byte length,
  • double minVal,
  • double maxVal,
  • out kv.SignalHnd sigHnd
  • )
  • {
  • kv.AddSignal(msgHnd, out sigHnd);
  • kv.SetSignalName(sigHnd, sigName);
  • kv.SetSignalComment(sigHnd, comment);
  • kv.SetSignalUnit(sigHnd, unit);
  • kv.SetSignalEncoding(sigHnd, kv.SignalEncoding.Intel);
  • kv.SetSignalRepresentationType(sigHnd, type);
  • kv.SetSignalValueSize(sigHnd, startBit, length);
  • kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
  • }
  • kv.Open(out kv.Hnd dbHnd);
  • kv.Create(dbHnd, "local", null);
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
  • kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
  • kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
  • kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
  • kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");
  • kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
  • kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
  • kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
  • kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
  • for (int i = 0; i < 4; i++)
  • kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i]);
  • add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
  • add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);
  • kv.WriteFile(dbHnd, "./testDBC.dbc");
  • ```
#1: Initial revision by user avatar HinkyDinky‭ · 2023-07-06T15:00:47Z (10 months ago)
Credit go to @Lundin‭ for pointing me in the right direction.
Kvaser has a [CAN SDK](https://www.kvaser.com/developer/canlib-sdk/) free of charge. I added this to my VS22 C# project by adding
"...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.KvaDbLib.dll"
and
"...\Kvaser\Canlib\dotnet\x64\netstandard2.0\Kvaser.CanLib.dll" to my project references.

AND (this I was stuck on)

Copying "...\Kvaser\Canlib\bin_x64\kvaDbLib.dll" to your application folder (where you executable is).


I ported an .C example application to C# and it seems to work:

```
using kv = Kvaser.KvadbLib.Kvadblib;

List<string> VFrameFormat_enum_names = new() { "StandardCAN", "ExtendedCAN", "reserved", "J1939PG" };

void add_msg_to_db(kv.Hnd dbHnd, string msgName, int dlc, int msgID, out kv.MessageHnd msgHnd)
{
    kv.AddMsg(dbHnd, out msgHnd);
    kv.SetMsgName(msgHnd, msgName);
    kv.SetMsgDlc(msgHnd, dlc);
    kv.SetMsgIdEx(msgHnd, msgID);
    kv.SetMsgFlags(msgHnd, kv.MESSAGE.J1939);
}

void add_sig_to_msg
(
    kv.MessageHnd msgHnd, 
    string sigName, 
    string comment, 
    string unit, 
    kv.SignalEncoding encoding, 
    kv.SignalType type, 
    byte startBit, 
    byte length,
    double minVal,
    double maxVal,
    out kv.SignalHnd sigHnd
)
{
    kv.AddSignal(msgHnd, out sigHnd);
    kv.SetSignalName(sigHnd, sigName);
    kv.SetSignalComment(sigHnd, comment);
    kv.SetSignalUnit(sigHnd, unit);
    kv.SetSignalEncoding(sigHnd, kv.SignalEncoding.Intel);
    kv.SetSignalRepresentationType(sigHnd, type);
    kv.SetSignalValueSize(sigHnd, startBit, length);
    kv.SetSignalValueLimits(sigHnd, minVal, maxVal);
}

kv.Open(out kv.Hnd dbHnd);
kv.Create(dbHnd, "local", null);

kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd ProtocolType_attr);
kv.SetAttributeDefinitionType(ProtocolType_attr, kv.AttributeType.AttributeString);
kv.SetAttributeDefinitionName(ProtocolType_attr, "ProtocolType");
kv.SetAttributeDefinitionOwner(ProtocolType_attr, kv.AttributeOwner.AttributeOwnerDb);
kv.SetAttributeDefinitionString(ProtocolType_attr, "J1939");

kv.AddAttributeDefinition(dbHnd, out kv.AttributeDefHnd VFrameFormat_attr);
kv.SetAttributeDefinitionType(VFrameFormat_attr, kv.AttributeType.AttributeEnumeration);
kv.SetAttributeDefinitionName(VFrameFormat_attr, "VFrameFormat");
kv.SetAttributeDefinitionOwner(VFrameFormat_attr, kv.AttributeOwner.AttributeOwnerMessage);
for (int i = 0; i < 4; i++)
    kv.SetAttributeDefinitionString(VFrameFormat_attr, VFrameFormat_enum_names[i]);

add_msg_to_db(dbHnd, "TEST_MSG_000", 8, 0xC0FFEE, out kv.MessageHnd msgHand);
add_sig_to_msg(msgHand, "TEST_SIG_000", "I am a comment", "banana", kv.SignalEncoding.Intel, kv.SignalType.Unsigned, 0, 16, 0, 65535, out kv.SignalHnd sigHnd);

kv.WriteFile(dbHnd, "./testDBC.dbc");
```