/* * Once a database is loaded, this method will be called * to add all the messages to the ComboBox. */ public List <Message> LoadMessages() { Kvadblib.MessageHnd mh; Kvadblib.Status status; Kvadblib.NodeHnd nh; List <Message> messages = new List <Message>(); status = Kvadblib.GetFirstMsg(dh, out mh); while (status == Kvadblib.Status.OK) { string name; int id; int dlc; string nodeName; Kvadblib.MESSAGE flags; status = Kvadblib.GetMsgName(mh, out name); status = Kvadblib.GetMsgId(mh, out id, out flags); status = Kvadblib.GetMsgDlc(mh, out dlc); status = Kvadblib.GetMsgSendNode(mh, out nh); status = Kvadblib.GetNodeName(nh, out nodeName); Kvadblib.AttributeHnd ah; int attEunmVal = 8; status = Kvadblib.GetAttributeByName(dh, "GenMsgSendType", out ah); //获取ah用于存储对应message的ah status = Kvadblib.GetMsgAttributeByName(mh, "GenMsgSendType", ref ah); //获取对应message的attribute信息 Kvadblib.GetAttributeValueEnumeration(ah, out attEunmVal); int GenMsgCycleTime = 0; status = Kvadblib.GetAttributeByName(dh, "GenMsgCycleTime", out ah); //获取ah用于存储对应message的ah status = Kvadblib.GetMsgAttributeByName(mh, "GenMsgCycleTime", ref ah); //获取对应message的attribute信息 Kvadblib.GetAttributeValueInt(ah, out GenMsgCycleTime); Message message = new Message(); message.id = id; message.name = name; message.dlc = dlc; message.tx_node = nodeName; message.GenMsgSendType = this.GenMsgSendType[attEunmVal]; message.GenMsgCycleTime = GenMsgCycleTime; message.CycleCount = 0; messages.Add(message); status = Kvadblib.GetNextMsg(dh, out mh); } return(messages); }
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); }