Пример #1
0
        /*
         * 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);
        }
Пример #2
0
        /*
         * 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);
        }
Пример #3
0
        /*
         * Constructs a message from the form and sends it
         * to the channel
         */
        private bool SendMessage(int dlc, List <Signal> signals)
        {
            byte[] data = new byte[dlc];

            Kvadblib.Status    status = Kvadblib.Status.OK;
            Kvadblib.SignalHnd sh;
            bool error = false;

            foreach (Signal s in signals)
            {
                double min, max;
                status = Kvadblib.GetSignalByName(msgHandle, s.name, out sh);

                if (status != Kvadblib.Status.OK)
                {
                    error = true;
                    break;
                }

                Kvadblib.GetSignalValueLimits(sh, out min, out max);

                status = Kvadblib.StoreSignalValuePhys(sh, data, dlc, s.Value);

                //Check if the signal value was successfully stored and that it's in the correct interval
                if (status != Kvadblib.Status.OK || s.Value < min || s.Value > max)
                {
                    error = true;
                    break;
                }
            }

            if (!error)
            {
                Canlib.canWriteWait(chanHandle, msgId, data, dlc, msgFlags, 50);
            }
            return(error);
        }