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); } } }
/* * Loads the selected message's signals to construct a form */ public List <Signal> LoadSignalsById(int MsgId) { List <Signal> result = new List <Signal>(); Kvadblib.MessageHnd mh; Kvadblib.Status status = Kvadblib.GetMsgById(dh, MsgId, out mh); if (status == Kvadblib.Status.OK) { Kvadblib.MESSAGE f; int dlc; msgHandle = mh; Kvadblib.GetMsgId(mh, out msgId, out f); Kvadblib.GetMsgDlc(mh, out dlc); msgId = ((MsgId & -2147483648) == 0) ? MsgId : MsgId ^ -2147483648; msgFlags = ((MsgId & -2147483648) == 0) ? 0 : Canlib.canMSG_EXT; hasMessage = true; result = LoadSignals(dlc); } return(result); }