/* * Constructs a form for creating messages. * Consists of one TextBox for every signal in the loaded message. */ private List <Signal> LoadSignals(int dlc) { Kvadblib.SignalHnd sh; Kvadblib.Status status = Kvadblib.GetFirstSignal(msgHandle, out sh); List <Signal> signals = new List <Signal>(); while (status == Kvadblib.Status.OK) { string name; string unit; double min, max, scale, offset, val; //byte[] data = new byte[dlc]; //Construct the text for the label status = Kvadblib.GetSignalName(sh, out name); status = Kvadblib.GetSignalUnit(sh, out unit); status = Kvadblib.GetSignalValueLimits(sh, out min, out max); status = Kvadblib.GetSignalValueScaling(sh, out scale, out offset); //status = Kvadblib.GetSignalValueFloat(sh, out val, data, dlc); //Signal s = new Signal(name, max, min, min, scale); Signal s = new Signal(name, max, min, min, scale); signals.Add(s); status = Kvadblib.GetNextSignal(msgHandle, out sh); } return(signals); }
private void DumpMessage(int id, string idStr, byte[] data, int dlc, int flags, long time) { Kvadblib.Status status; Kvadblib.MessageHnd mh = new Kvadblib.MessageHnd(); Kvadblib.SignalHnd sh = new Kvadblib.SignalHnd(); //Flips the EXT bit if the EXT flag is set if ((flags & Canlib.canMSG_EXT) != 0) { id ^= -2147483648; } //Find the database message whose id matches the one //from the incoming message status = Kvadblib.GetMsgById(dbhandle, id, out mh); outputBox.AppendText(string.Format("Reading message with id {0}", idStr) + Environment.NewLine); //Print the message info if (status == Kvadblib.Status.OK) { string msgName; status = Kvadblib.GetMsgName(mh, out msgName); outputBox.AppendText(string.Format("Message received: {0}", msgName) + Environment.NewLine); int msgId; Kvadblib.MESSAGE msgFlags; status = Kvadblib.GetMsgId(mh, out msgId, out msgFlags); outputBox.AppendText(string.Format("Id: {0}, flags: {1}", msgId, msgFlags) + Environment.NewLine); //Iterate through all the signals and print their name, value and unit status = Kvadblib.GetFirstSignal(mh, out sh); while (status == Kvadblib.Status.OK) { string signalname; status = Kvadblib.GetSignalName(sh, out signalname); string unit; status = Kvadblib.GetSignalUnit(sh, out unit); double value; status = Kvadblib.GetSignalValueFloat(sh, out value, data, dlc); outputBox.AppendText(string.Format("Signal - {0}: {1} {2}", signalname, value, unit) + Environment.NewLine); status = Kvadblib.GetNextSignal(mh, out sh); } } }
public static List <CanMessage> OpenCanDB(string fullFilePath) { Kvadblib.Hnd db_handle; Kvadblib.Status status; status = Kvadblib.Open(out db_handle); status = Kvadblib.Create(db_handle, "MyTestDB", fullFilePath); if (status == Kvadblib.Status.Err_DbFileOpen) { throw new Exception("Could not open CAN database file"); // TODO: Handle more gracefully } if (status == Kvadblib.Status.Err_DbFileParse) { string errorMessage; status = Kvadblib.GetLastParseError(out errorMessage); throw new Exception("Could not parse file. Error: \n" + errorMessage); } List <CanMessage> Messages = new List <CanMessage>(); // Get the first message in the database Kvadblib.MessageHnd messageHandle; status = Kvadblib.GetFirstMsg(db_handle, out messageHandle); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetFirstMsg failed: " + status.ToString()); // TODO: Handle more gracefully } // Go through all messages in the database while (status == Kvadblib.Status.OK) { string tempMessageName; string tempMessageQualifiedName; string tempMessageComment; int tempMessageID; Kvadblib.MESSAGE tempFlags; int tempMessageDlc; // Get the properties for each message status = Kvadblib.GetMsgName(messageHandle, out tempMessageName); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetMsgName failed: " + status.ToString()); // TODO: Handle more gracefully } status = Kvadblib.GetMsgQualifiedName(messageHandle, out tempMessageQualifiedName); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetMsgQualifiedName failed: " + status.ToString()); } status = Kvadblib.GetMsgComment(messageHandle, out tempMessageComment); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetMsgComment failed: " + status.ToString()); // TODO: Handle more gracefully } status = Kvadblib.GetMsgIdEx(messageHandle, out tempMessageID); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetMsgId failed: " + status.ToString()); // TODO: Handle more gracefully } status = Kvadblib.GetMsgFlags(messageHandle, out tempFlags); if (status != Kvadblib.Status.OK) { throw new Exception("GetMsgFlags failed: " + status.ToString()); // TODO: Handle more gracefully } status = Kvadblib.GetMsgDlc(messageHandle, out tempMessageDlc); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetMsgDlc failed: " + status.ToString()); // TODO: Handle more gracefully } CanMessage tempCanMessage = new CanMessage { Comment = tempMessageComment, DLC = tempMessageDlc, Flags = tempFlags, ID = tempMessageID, Name = tempMessageName, QualifiedName = tempMessageQualifiedName, }; Messages.Add(tempCanMessage); // Go through all signals for this message Kvadblib.SignalHnd signalHandle; status = Kvadblib.GetFirstSignal(messageHandle, out signalHandle); while (status == Kvadblib.Status.OK) { string tempSignalName; string tempSignalQualifiedName; string tempSignalComment; string tempSignalUnit; Kvadblib.SignalEncoding tempSignalEncoding; Kvadblib.SignalType tempSignalType; int tempStartbit = 0; int tempLength = 0; double tempMinval = 0; double tempMaxval = 0; double tempScaleFactor = 0; double tempOffset = 0; // Get the properties for each signal. status = Kvadblib.GetSignalName(signalHandle, out tempSignalName); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetSignalName failed: " + status.ToString()); // TODO: Handle more gracefully } status = Kvadblib.GetSignalQualifiedName(signalHandle, out tempSignalQualifiedName); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetSignalQualifiedName failed: " + status.ToString()); // TODO: Handle more gracefully } status = Kvadblib.GetSignalComment(signalHandle, out tempSignalComment); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetSignalComment failed: " + status.ToString()); // TODO: Handle more gracefully } status = Kvadblib.GetSignalUnit(signalHandle, out tempSignalUnit); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetSignalUnit failed: " + status.ToString()); // TODO: Handle more gracefully } status = Kvadblib.GetSignalEncoding(signalHandle, out tempSignalEncoding); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetSignalEncoding failed: " + status.ToString()); // TODO: Handle more gracefully } status = Kvadblib.GetSignalRepresentationType(signalHandle, out tempSignalType); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetSignalRepresentationType failed: " + status.ToString()); // TODO: Handle more gracefully } status = Kvadblib.GetSignalValueLimits(signalHandle, out tempMinval, out tempMaxval); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetSignalValueLimits failed: " + status.ToString()); // TODO: Handle more gracefully } status = Kvadblib.GetSignalValueScaling(signalHandle, out tempScaleFactor, out tempOffset); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetSignalValueScaling failed: " + status.ToString()); // TODO: Handle more gracefully } status = Kvadblib.GetSignalValueSize(signalHandle, out tempStartbit, out tempLength); if (status != Kvadblib.Status.OK) { throw new Exception("kvaDbGetSignalValueSize failed: " + status.ToString()); // TODO: Handle more gracefully } CanSignal tempCanSignal = new CanSignal { Comment = tempSignalComment, Encoding = tempSignalEncoding, Length = tempLength, MaxValue = tempMaxval, MinValue = tempMinval, Name = tempSignalName, Offset = tempOffset, QualifiedName = tempSignalQualifiedName, ScaleFactor = tempScaleFactor, StartBit = tempStartbit, Type = tempSignalType, Unit = tempSignalUnit, }; tempCanMessage.Signals.Add(tempCanSignal); status = Kvadblib.GetNextSignal(messageHandle, out signalHandle); } status = Kvadblib.GetNextMsg(db_handle, out messageHandle); } // All done; close database Kvadblib.Close(db_handle); return(Messages); }