예제 #1
0
파일: CANController.cs 프로젝트: CFind/HCAN
 public CanMsg(TPCANMsg msg, TPCANTimestamp timestamp, int index)
 {
     this.msg          = msg;
     this.timestamp    = timestamp;
     this.index        = index;
     this.recieveCount = 0;
 }
예제 #2
0
        /// <summary>
        /// Inserts a new entry for a new message in the Message-ListView
        /// </summary>
        /// <param name="newMsg">The messasge to be inserted</param>
        /// <param name="timeStamp">The Timesamp of the new message</param>
        private void InsertMsgEntry(TPCANMsg newMsg, TPCANTimestamp timeStamp)
        {
            MessageStatus msgStsCurrentMsg;
            ListViewItem  lviCurrentItem;

            lock (m_LastMsgsList.SyncRoot)
            {
                // We add this status in the last message list
                //
                msgStsCurrentMsg = new MessageStatus(newMsg, timeStamp, lstMessages.Items.Count);
                m_LastMsgsList.Add(msgStsCurrentMsg);

                // Add the new ListView Item with the Type of the message
                //
                lviCurrentItem = lstMessages.Items.Add(msgStsCurrentMsg.TypeString);
                // We set the ID of the message
                //
                lviCurrentItem.SubItems.Add(msgStsCurrentMsg.IdString);
                // We set the length of the Message
                //
                lviCurrentItem.SubItems.Add(newMsg.LEN.ToString());
                // We set the data of the message.
                //
                lviCurrentItem.SubItems.Add(msgStsCurrentMsg.DataString);
                // we set the message count message (this is the First, so count is 1)
                //
                lviCurrentItem.SubItems.Add(msgStsCurrentMsg.Count.ToString());
                // Add time stamp information if needed
                //
                lviCurrentItem.SubItems.Add(msgStsCurrentMsg.TimeString);
            }
        }
예제 #3
0
 public void Update(TPCANMsg canMsg, TPCANTimestamp canTimestamp)
 {
     m_Msg          = canMsg;
     m_oldTimeStamp = m_TimeStamp;
     m_TimeStamp    = canTimestamp;
     m_bWasChanged  = true;
     m_Count       += 1;
 }
예제 #4
0
 public MessageStatus(TPCANMsg canMsg, TPCANTimestamp canTimestamp, int listIndex)
 {
     m_Msg          = canMsg;
     m_TimeStamp    = canTimestamp;
     m_oldTimeStamp = canTimestamp;
     m_iIndex       = listIndex;
     m_Count        = 1;
     m_bShowPeriod  = true;
     m_bWasChanged  = false;
 }
예제 #5
0
        public void recieveCANMessagePEAK(TPCANMsg msg, TPCANTimestamp time)
        {
            string id = msg.ID.ToString();     //can_msg[2].Remove(0, 3);
            // string time = time; //Convert.ToInt32(can_msg[1]).ToString();
            string lengt = msg.LEN.ToString(); //can_msg[3].Remove(0, 2);

            string bytes = "";

            for (int i = 0; i < msg.LEN; i++)
            {
                bytes += Convert.ToString(msg.DATA[i], 16);

                if (i != msg.LEN - 1)
                {
                    bytes += ",";
                }
            }



            update_can_log(id, lengt, bytes, time.millis.ToString());
            update_vscp_mon(Convert.ToInt32(msg.ID), lengt, bytes, time.millis.ToString());
        }
예제 #6
0
        /// <summary>
        /// Processes a received message, in order to show it in the Message-ListView
        /// </summary>
        /// <param name="theMsg">The received PCAN-Basic message</param>
        /// <returns>True if the message must be created, false if it must be modified</returns>
        private void ProcessMessage(TPCANMsg theMsg, TPCANTimestamp itsTimeStamp)
        {
            // We search if a message (Same ID and Type) is
            // already received or if this is a new message
            //
            lock (m_LastMsgsList.SyncRoot)
            {
                foreach (MessageStatus msg in m_LastMsgsList)
                {
                    if ((msg.CANMsg.ID == theMsg.ID) && (msg.CANMsg.MSGTYPE == theMsg.MSGTYPE))
                    {
                        //id we need to parse
                        byte[] CanId        = BitConverter.GetBytes(msg.CANMsg.ID);
                        byte   MasterUnitId = 0;
                        MasterUnitId = (byte)((Convert.ToUInt16(ListBoxBmsIds.SelectedItem)));

                        //check if we allready evaluated this BMS ID
                        //var pos = listOfDetectedBms.Find(item => item == CanId[1]);
                        var pos = ListBoxBmsIds.Items.Contains(CanId[1]);
                        if (!pos)
                        {
                            listOfDetectedBms.Add(CanId[1]);
                            ListBoxBmsIds.Items.Add(CanId[1]);
                        }
                        boxNumberOfPacks.Text = listOfDetectedBms.Count.ToString();

                        /*boxDetectedPacks.Text ="";
                         * foreach(var DetectedBms in listOfDetectedBms)
                         * {
                         *  boxDetectedPacks.Text += DetectedBms.ToString();
                         * }*/



                        //if we are not reading right master remove all the values
                        if (CanId[3] == 0x18 && CanId[1] == MasterUnitId)
                        {
                            //show value group box
                            groupDataFromBms.Visible = true;



                            //PARSE status message
                            if (CanId[0] == 0x10)
                            {
                                byte statusByte0  = msg.CANMsg.DATA[0];
                                byte statusByte1  = msg.CANMsg.DATA[1];
                                byte Temperature1 = msg.CANMsg.DATA[2];
                                byte Temperature2 = msg.CANMsg.DATA[3];
                                byte Temperature3 = msg.CANMsg.DATA[4];
                                byte Temperature4 = msg.CANMsg.DATA[5];

                                boxTemp1.Text = Temperature1.ToString();
                                boxTemp2.Text = Temperature2.ToString();
                                boxTemp3.Text = Temperature3.ToString();
                                boxTemp4.Text = Temperature4.ToString();

                                //invididual cells
                                if (IsBitSet(statusByte0, 6))
                                {
                                    boxStatus0b6.BackColor = Color.Green;
                                }
                                else
                                {
                                    boxStatus0b6.BackColor = Color.Red;
                                }
                                if (IsBitSet(statusByte0, 0))
                                {
                                    boxStatus0b5.BackColor = Color.Green;
                                }
                                else
                                {
                                    boxStatus0b5.BackColor = Color.Red;
                                }
                                if (IsBitSet(statusByte0, 1))
                                {
                                    boxStatus0b4.BackColor = Color.Green;
                                }
                                else
                                {
                                    boxStatus0b4.BackColor = Color.Red;
                                }
                                if (IsBitSet(statusByte0, 2))
                                {
                                    boxStatus0b3.BackColor = Color.Green;
                                }
                                else
                                {
                                    boxStatus0b3.BackColor = Color.Red;
                                }
                                if (IsBitSet(statusByte0, 3))
                                {
                                    boxStatus0b2.BackColor = Color.Green;
                                }
                                else
                                {
                                    boxStatus0b2.BackColor = Color.Red;
                                }
                                if (IsBitSet(statusByte0, 4))
                                {
                                    boxStatus0b1.BackColor = Color.Green;
                                }
                                else
                                {
                                    boxStatus0b1.BackColor = Color.Red;
                                }
                                if (IsBitSet(statusByte0, 5))
                                {
                                    boxStatus0b0.BackColor = Color.Green;
                                }
                                else
                                {
                                    boxStatus0b0.BackColor = Color.Red;
                                }

                                //master status
                                if (IsBitSet(statusByte1, 0))
                                {
                                    boxStatus1b0.BackColor = Color.Green;                           //all full
                                }
                                else
                                {
                                    boxStatus1b0.BackColor = Color.Gray;
                                }
                                if (IsBitSet(statusByte1, 1))
                                {
                                    boxStatus1b1.BackColor = Color.Green;                           //one full
                                }
                                else
                                {
                                    boxStatus1b1.BackColor = Color.Gray;
                                }
                                if (IsBitSet(statusByte1, 2))
                                {
                                    boxStatus1b2.BackColor = Color.Orange;                           //empty
                                }
                                else
                                {
                                    boxStatus1b2.BackColor = Color.Gray;
                                }
                                if (IsBitSet(statusByte1, 3))
                                {
                                    boxStatus1b3.BackColor = Color.Red;                           //cut-off
                                }
                                else
                                {
                                    boxStatus1b3.BackColor = Color.Gray;
                                }
                                if (IsBitSet(statusByte1, 4))
                                {
                                    boxStatus1b4.BackColor = Color.Red;                           //overvoltage
                                }
                                else
                                {
                                    boxStatus1b4.BackColor = Color.Gray;
                                }
                            }
                            //voltages
                            if (CanId[0] == 0x11)
                            {
                                textBox0.Text = ((float)msg.CANMsg.DATA[0] / 100 + 2).ToString();
                                if (msg.CANMsg.DATA[0] == 0xff)
                                {
                                    textBox0.Text = "xxx";
                                }
                                textBox1.Text = ((float)msg.CANMsg.DATA[1] / 100 + 2).ToString();
                                if (msg.CANMsg.DATA[1] == 0xff)
                                {
                                    textBox1.Text = "xxx";
                                }
                                textBox2.Text = ((float)msg.CANMsg.DATA[2] / 100 + 2).ToString();
                                if (msg.CANMsg.DATA[2] == 0xff)
                                {
                                    textBox2.Text = "xxx";
                                }
                                textBox3.Text = ((float)msg.CANMsg.DATA[3] / 100 + 2).ToString();
                                if (msg.CANMsg.DATA[3] == 0xff)
                                {
                                    textBox3.Text = "xxx";
                                }
                                textBox4.Text = ((float)msg.CANMsg.DATA[4] / 100 + 2).ToString();
                                if (msg.CANMsg.DATA[4] == 0xff)
                                {
                                    textBox4.Text = "xxx";
                                }
                                textBox5.Text = ((float)msg.CANMsg.DATA[5] / 100 + 2).ToString();
                                if (msg.CANMsg.DATA[5] == 0xff)
                                {
                                    textBox5.Text = "xxx";
                                }
                            }

                            //balancing
                            if (CanId[0] == 0x12)
                            {
                                BoxPWM1.Text = msg.CANMsg.DATA[0].ToString();
                                if (msg.CANMsg.DATA[0] > 0)
                                {
                                    BoxPWM1.BackColor = Color.Green;
                                }
                                else
                                {
                                    BoxPWM1.BackColor = Color.LightGray;
                                }
                                BoxPWM2.Text = msg.CANMsg.DATA[1].ToString();
                                if (msg.CANMsg.DATA[1] > 0)
                                {
                                    BoxPWM2.BackColor = Color.Green;
                                }
                                else
                                {
                                    BoxPWM2.BackColor = Color.LightGray;
                                }
                                BoxPWM3.Text = msg.CANMsg.DATA[2].ToString();
                                if (msg.CANMsg.DATA[2] > 0)
                                {
                                    BoxPWM3.BackColor = Color.Green;
                                }
                                else
                                {
                                    BoxPWM3.BackColor = Color.LightGray;
                                }
                                BoxPWM4.Text = msg.CANMsg.DATA[3].ToString();
                                if (msg.CANMsg.DATA[3] > 0)
                                {
                                    BoxPWM4.BackColor = Color.Green;
                                }
                                else
                                {
                                    BoxPWM4.BackColor = Color.LightGray;
                                }
                                BoxPWM5.Text = msg.CANMsg.DATA[4].ToString();
                                if (msg.CANMsg.DATA[4] > 0)
                                {
                                    BoxPWM5.BackColor = Color.Green;
                                }
                                else
                                {
                                    BoxPWM5.BackColor = Color.LightGray;
                                }
                                BoxPWM6.Text = msg.CANMsg.DATA[5].ToString();
                                if (msg.CANMsg.DATA[5] > 0)
                                {
                                    BoxPWM6.BackColor = Color.Green;
                                }
                                else
                                {
                                    BoxPWM6.BackColor = Color.LightGray;
                                }
                            }
                            //Max voltage
                            if (CanId[0] == 0x13)
                            {
                                boxMaxV1.Text = ((float)msg.CANMsg.DATA[0] / 100 + 2).ToString();
                                boxMaxV2.Text = ((float)msg.CANMsg.DATA[1] / 100 + 2).ToString();
                                boxMaxV3.Text = ((float)msg.CANMsg.DATA[2] / 100 + 2).ToString();
                                boxMaxV4.Text = ((float)msg.CANMsg.DATA[3] / 100 + 2).ToString();
                                boxMaxV5.Text = ((float)msg.CANMsg.DATA[4] / 100 + 2).ToString();
                                boxMaxV6.Text = ((float)msg.CANMsg.DATA[5] / 100 + 2).ToString();
                            }
                            //Min voltage
                            if (CanId[0] == 0x14)
                            {
                                boxMinV1.Text = ((float)msg.CANMsg.DATA[0] / 100 + 2).ToString();
                                boxMinV2.Text = ((float)msg.CANMsg.DATA[1] / 100 + 2).ToString();
                                boxMinV3.Text = ((float)msg.CANMsg.DATA[2] / 100 + 2).ToString();
                                boxMinV4.Text = ((float)msg.CANMsg.DATA[3] / 100 + 2).ToString();
                                boxMinV5.Text = ((float)msg.CANMsg.DATA[4] / 100 + 2).ToString();
                                boxMinV6.Text = ((float)msg.CANMsg.DATA[5] / 100 + 2).ToString();
                            }
                            //Max balancing (PWM)
                            if (CanId[0] == 0x15)
                            {
                                boxMaxPwm1.Text = msg.CANMsg.DATA[0].ToString();
                                boxMaxPwm2.Text = msg.CANMsg.DATA[1].ToString();
                                boxMaxPwm3.Text = msg.CANMsg.DATA[2].ToString();
                                boxMaxPwm4.Text = msg.CANMsg.DATA[3].ToString();
                                boxMaxPwm5.Text = msg.CANMsg.DATA[4].ToString();
                                boxMaxPwm6.Text = msg.CANMsg.DATA[5].ToString();
                            }
                        }
                        else
                        {
                            //groupDataFromBms.Visible = false;
                        }
                        // Modify the message and exit
                        //
                        msg.Update(theMsg, itsTimeStamp);
                        return;
                    }
                }
                // Message not found. It will created
                //
                InsertMsgEntry(theMsg, itsTimeStamp);
            }
        }
예제 #7
0
 public static extern uint ReadEx(out TPCANMsg msg, out TPCANTimestamp timestamp);
예제 #8
0
파일: PCAN.cs 프로젝트: fbstj/lib.cs
        /// <summary>Converts a PCANTimestamp into a TimeSpan</summary>
        public static TimeSpan Time(TPCANTimestamp ts)
        {
            long us = ts.micros + 1000 * ts.millis + (long)0xFFFFFFFF * 1000 * ts.millis_overflow;

            return(new TimeSpan(us * TimeSpan.TicksPerMillisecond / 1000));
        }
예제 #9
0
파일: Pcan_pci.cs 프로젝트: sbtree/MST
 public static extern uint ReadEx(out TPCANMsg msg, out TPCANTimestamp timestamp);
예제 #10
0
 public PCANMessage(TPCANMsg msg, TPCANTimestamp timestamp)
 {
     m_msg = msg;
     this.SetData(msg.DATA, msg.LEN);
     m_relativeTime = new TimeSpan(timestamp.micros * TICKSPERMICRO + (timestamp.millis + 0x100000000L * timestamp.millis_overflow) * TICKSPERMILLI);
 }
예제 #11
0
파일: Cebora.cs 프로젝트: sangrit-siit/HMI
        private MessageStatus DecodeMessage(TPCANMsg theMsg, TPCANTimestamp itsTimeStamp)
        {
            double Map(double value, double fromSrouce, double toSource, double fromTarget, double toTarget) => (value - fromSrouce) / (toSource - fromSrouce) * (toTarget - fromTarget) + fromTarget;

            MessageStatus StsMsg = new MessageStatus(theMsg, itsTimeStamp, 0);

            string retID   = StsMsg.IdString;
            string retLEN  = theMsg.LEN.ToString();
            string retDATA = StsMsg.DataString.Trim();

            char[]   splitter = { ' ' };
            string[] arData   = retDATA.Split(splitter);

            string ret1 = "";
            string ret2 = "";
            string ret3 = "";
            string ret4 = "";

            long value1 = 0;
            long value2 = 0;
            long value3 = 0;
            long value4 = 0;

            #region ID = 0x180
            if (StsMsg.IdString == "182h")
            {
                if (retLEN == "4")
                {
                    ret1 = arData[0];
                    ret2 = arData[1];
                    ret3 = arData[2];
                    ret4 = arData[3];

                    //Convert To Long
                    value1 = Convert.ToInt64(ret1, 16);
                    value2 = Convert.ToInt64(ret2, 16);
                    value3 = Convert.ToInt64(ret3, 16);
                    value4 = Convert.ToInt64(ret4, 16);

                    #region Convert To Binary
                    string Binary1 = Convert.ToString(value1, 2);
                    string Binary2 = Convert.ToString(value2, 2); //Error Number
                    string Binary3 = Convert.ToString(value3, 2);
                    string Binary4 = Convert.ToString(value4, 2);

                    if (Binary1.Length != 8)
                    {
                        int AddZero = 8 - Binary1.Length;
                        for (int j = 0; j < AddZero; j++)
                        {
                            Binary1 = "0" + Binary1;
                        }
                    }

                    if (Binary2.Length != 8)
                    {
                        int AddZero = 8 - Binary2.Length;
                        for (int j = 0; j < AddZero; j++)
                        {
                            Binary2 = "0" + Binary2;
                        }
                    }

                    if (Binary3.Length != 8)
                    {
                        int AddZero = 8 - Binary3.Length;
                        for (int j = 0; j < AddZero; j++)
                        {
                            Binary3 = "0" + Binary3;
                        }
                    }

                    if (Binary4.Length != 8)
                    {
                        int AddZero = 8 - Binary4.Length;
                        for (int j = 0; j < AddZero; j++)
                        {
                            Binary4 = "0" + Binary4;
                        }
                    }
                    #endregion Convert To Binary

                    #region Check Bit Data
                    if (Binary1.Length == 8)
                    {
                        string retBuf = Binary1;

                        if (retBuf.Substring(0, 1) == "1")//Reserved
                        {
                        }

                        mDigitalSignals["CommunicationReady"] = retBuf.Substring(1, 1) == "1" ? 1 : 0;

                        /*
                         * if (retBuf.Substring(1, 1) == "1")//Communication Ready
                         * {
                         *  Pic_Com_Ready.Image = PicOn.Image;
                         *  Status_CommunicationReady = true;
                         *
                         *  Pic_Com_State.Image = PicOn.Image;
                         *  // ParentForm.Pic_Com_State.Image = PicOn.Image;
                         * }
                         * else
                         * {
                         *  Pic_Com_Ready.Image = PicOff.Image;
                         *  Status_CommunicationReady = false;
                         *
                         *  Pic_Com_State.Image = PicOff.Image;
                         *  //ParentForm.Pic_Com_State.Image = PicOff.Image;
                         * }
                         */
                        mDigitalSignals["PowerSourceReady"] = retBuf.Substring(2, 1) == "1" ? 1 : 0;

                        /*
                         * if (retBuf.Substring(2, 1) == "1")//Power Source Ready
                         * {
                         *  Pic_Power_Source_Ready.Image = PicOn.Image;
                         *  Status_PowerSourceReady = true;
                         *
                         *  Pic_Power_Source_State.Image = PicOn.Image;
                         *  // ParentForm.Pic_Power_Source_State.Image = PicOn.Image;
                         *
                         * }
                         * else
                         * {
                         *  Pic_Power_Source_Ready.Image = PicOff.Image;
                         *  Status_PowerSourceReady = false;
                         *
                         *  Pic_Power_Source_State.Image = PicOff.Image;
                         *  //ParentForm.Pic_Power_Source_State.Image = PicOff.Image;
                         * }
                         */
                        mDigitalSignals["CollisionProtection"] = retBuf.Substring(3, 1) == "1" ? 1 : 0;

                        /*
                         * if (retBuf.Substring(3, 1) == "1")//Collision Protection.
                         * {
                         *  Pic_Collision_Protection.Image = PicOn.Image;
                         *  Status_CollisionProtection = true;
                         * }
                         * else
                         * {
                         *  Pic_Collision_Protection.Image = PicOff.Image;
                         *  Status_CollisionProtection = false;
                         * }
                         */
                        mDigitalSignals["MainCurrent"] = retBuf.Substring(4, 1) == "1" ? 1 : 0;

                        /*
                         * if (retBuf.Substring(4, 1) == "1") //Main Current
                         * {
                         *  Pic_Main_Current.Image = PicOn.Image;
                         *  Status_MainCurrent = true;
                         *
                         * }
                         * else
                         * {
                         *  Pic_Main_Current.Image = PicOff.Image;
                         *  Status_MainCurrent = false;
                         * }
                         */
                        mDigitalSignals["ProcessActive"] = retBuf.Substring(5, 1) == "1" ? 1 : 0;

                        /*
                         * if (retBuf.Substring(5, 1) == "1")//Process Active
                         * {
                         *  Pic_Process_Active.Image = PicOn.Image;
                         *  Status_ProcessActive = true;
                         *
                         *  Pic_Process_Active_Status.Image = PicOn.Image;
                         *  //ParentForm.Pic_Process_Active_Status.Image = PicOn.Image;
                         * }
                         * else
                         * {
                         *  Pic_Process_Active.Image = PicOff.Image;
                         *  Status_ProcessActive = false;
                         *
                         *  Pic_Process_Active_Status.Image = PicOff.Image;
                         *  // ParentForm.Pic_Process_Active_Status.Image = PicOff.Image;
                         * }
                         */

                        if (retBuf.Substring(6, 1) == "1")//Not Use
                        {
                        }

                        mDigitalSignals["CurrentFlow"] = retBuf.Substring(6, 1) == "1" ? 1 : 0;

                        /*
                         * if (retBuf.Substring(7, 1) == "1")//Current Flow
                         * {
                         *  Pic_Current_Flow.Image = PicOn.Image;
                         *  Status_CurrentFlow = true;
                         *
                         *  Pic_Current_Flow_Status.Image = PicOn.Image;
                         * }
                         * else
                         * {
                         *  Pic_Current_Flow.Image = PicOff.Image;
                         *  Status_CurrentFlow = false;
                         *
                         *  Pic_Current_Flow_Status.Image = PicOff.Image;
                         * }
                         */
                    }

                    mDigitalSignals["ErrorNum"] = Convert.ToInt16(value2);

                    /*
                     * txtErrorNum.Text = value2.ToString();
                     * ErrorNumber = value2.ToString();
                     */

                    if (Binary3.Length == 8)
                    {
                        string retBuf = Binary3;
                        mDigitalSignals["PulseSync"] = retBuf.Substring(0, 1) == "1" ? 1 : 0;

                        /*
                         * if (retBuf.Substring(0, 1) == "1")//Pulse Sync
                         * {
                         *  Pic_Pulse_Sync.Image = PicOn.Image;
                         *  Status_PulseSync = true;
                         * }
                         * else
                         * {
                         *  Pic_Pulse_Sync.Image = PicOff.Image;
                         *  Status_PulseSync = false;
                         * }
                         */
                        mDigitalSignals["PilotArc"] = retBuf.Substring(7, 1) == "1" ? 1 : 0;

                        /*
                         * if (retBuf.Substring(7, 1) == "1")//Pilot Arc
                         * {
                         *  Pic_Pilot_Arc.Image = PicOn.Image;
                         *  Status_PilotArc = true;
                         * }
                         * else
                         * {
                         *  Pic_Pilot_Arc.Image = PicOff.Image;
                         *  Status_PilotArc = false;
                         * }
                         */
                    }

                    if (Binary4.Length == 8)
                    {
                        string retBuf = Binary4;
                        mDigitalSignals["StickingRemedied"] = retBuf.Substring(0, 1) == "1" ? 1 : 0;

                        /*
                         * if (retBuf.Substring(0, 1) == "1")//Sticking Remedied
                         * {
                         *  Pic_Sticking_Remedied.Image = PicOn.Image;
                         *  Status_StickingRemedied = true;
                         * }
                         * else
                         * {
                         *  Pic_Sticking_Remedied.Image = PicOff.Image;
                         *  Status_StickingRemedied = false;
                         * }
                         */
                        mDigitalSignals["WireAvailable"] = retBuf.Substring(3, 1) == "1" ? 1 : 0;

                        /*
                         * if (retBuf.Substring(3, 1) == "1")//Wire Available.
                         * {
                         *  Pic_Wire_Available.Image = PicOn.Image;
                         *  Status_WireAvailable = true;
                         * }
                         * else
                         * {
                         *  Pic_Wire_Available.Image = PicOff.Image;
                         *  Status_WireAvailable = false;
                         * }
                         */
                    }
                    #endregion Check Bit Data
                }
            }
            #endregion ID = 0x180
            #region ID = 0x280
            if (StsMsg.IdString == "282h")
            {
                if (retLEN == "8")
                {
                    #region  A0 Cal
                    ret1   = arData[0];
                    ret2   = arData[1];
                    value1 = Convert.ToInt64(ret1, 16);
                    value2 = Convert.ToInt64(ret2, 16);

                    string Binary1 = Convert.ToString(value1, 2);
                    string Binary2 = Convert.ToString(value2, 2);


                    if (Binary1.Length != 8)
                    {
                        int AddZero = 8 - Binary1.Length;
                        for (int j = 0; j < AddZero; j++)
                        {
                            Binary1 = "0" + Binary1;
                        }
                    }

                    if (Binary2.Length != 8)
                    {
                        int AddZero = 8 - Binary2.Length;
                        for (int j = 0; j < AddZero; j++)
                        {
                            Binary2 = "0" + Binary2;
                        }
                    }

                    string BinaryA0 = Binary2 + Binary1;
                    long   valueA0  = Convert.ToInt64(BinaryA0, 2);
                    double retmap   = Map(Convert.ToDouble(valueA0), 0, 65536, 0, 100); //0-100V
                    mAnalogSignals["A0"] = retmap;

                    /*
                     * txtVoltageMea.Text = retmap.ToString("0.000");
                     * txtVoltageMea_status.Text = retmap.ToString("0.000");
                     * TxtA0Measure.Text = "Value : " + valueA0.ToString() + ", Binary : " + BinaryA0;
                     */
                    #endregion  A0 Cal

                    #region  A1 Cal
                    ret1   = arData[2];
                    ret2   = arData[3];
                    value1 = Convert.ToInt64(ret1, 16);
                    value2 = Convert.ToInt64(ret2, 16);

                    Binary1 = Convert.ToString(value1, 2);
                    Binary2 = Convert.ToString(value2, 2);


                    if (Binary1.Length != 8)
                    {
                        int AddZero = 8 - Binary1.Length;
                        for (int j = 0; j < AddZero; j++)
                        {
                            Binary1 = "0" + Binary1;
                        }
                    }

                    if (Binary2.Length != 8)
                    {
                        int AddZero = 8 - Binary2.Length;
                        for (int j = 0; j < AddZero; j++)
                        {
                            Binary2 = "0" + Binary2;
                        }
                    }

                    string BinaryA1 = Binary2 + Binary1;
                    long   valueA1  = Convert.ToInt64(BinaryA1, 2);
                    retmap = Map(Convert.ToDouble(valueA1), 0, 65536, 0, 500); //0-500A
                    mAnalogSignals["A1"] = retmap;

                    /*
                     * txtCurrentMea.Text = retmap.ToString("0.000");
                     * txtCurrentMea_status.Text = retmap.ToString("0.000");
                     * TxtA1Measure.Text = "Value : " + valueA1.ToString() + ", Binary : " + BinaryA1;
                     */
                    #endregion  A1 Cal

                    #region  A2 Cal
                    ret1   = arData[4];
                    ret2   = arData[5];
                    value1 = Convert.ToInt64(ret1, 16);
                    value2 = Convert.ToInt64(ret2, 16);

                    Binary1 = Convert.ToString(value1, 2);
                    Binary2 = Convert.ToString(value2, 2);


                    if (Binary1.Length != 8)
                    {
                        int AddZero = 8 - Binary1.Length;
                        for (int j = 0; j < AddZero; j++)
                        {
                            Binary1 = "0" + Binary1;
                        }
                    }

                    if (Binary2.Length != 8)
                    {
                        int AddZero = 8 - Binary2.Length;
                        for (int j = 0; j < AddZero; j++)
                        {
                            Binary2 = "0" + Binary2;
                        }
                    }

                    string BinaryA2 = Binary2 + Binary1;
                    long   valueA2  = Convert.ToInt64(BinaryA2, 2);
                    retmap = Map(Convert.ToDouble(valueA2), 0, 65536, 0, 5); //0-5A
                    mAnalogSignals["A2"] = retmap;

                    /*
                     * txtMotorCurrent.Text = retmap.ToString("0.000");
                     * txtMotorCurrent_Mea.Text = txtMotorCurrent.Text;
                     * TxtA2Measure.Text = "Value : " + valueA2.ToString() + ", Binary : " + BinaryA2;
                     */
                    #endregion  A2 Cal

                    #region  A3 Cal

                    ret1   = arData[6];
                    ret2   = arData[7];
                    value1 = Convert.ToInt64(ret1, 16);
                    value2 = Convert.ToInt64(ret2, 16);

                    Binary1 = Convert.ToString(value1, 2);
                    Binary2 = Convert.ToString(value2, 2);


                    if (Binary1.Length != 8)
                    {
                        int AddZero = 8 - Binary1.Length;
                        for (int j = 0; j < AddZero; j++)
                        {
                            Binary1 = "0" + Binary1;
                        }
                    }

                    if (Binary2.Length != 8)
                    {
                        int AddZero = 8 - Binary2.Length;
                        for (int j = 0; j < AddZero; j++)
                        {
                            Binary2 = "0" + Binary2;
                        }
                    }

                    string BinaryA3 = Binary2 + Binary1;
                    long   valueA3  = Convert.ToInt64(BinaryA3, 2);
                    retmap = Map(Convert.ToDouble(valueA3), 0, 65536, -12.5, 12.5);
                    mAnalogSignals["A3"] = retmap;

                    /*
                     * txtWireFeedSpeed.Text = retmap.ToString("0.000");
                     * txtWireFeedSpeed_Mea.Text = txtWireFeedSpeed.Text;
                     * TxtA3Measure.Text = "Value : " + valueA3.ToString() + ", Binary : " + BinaryA3;
                     */
                    #endregion  A3 Cal
                }
            }
            #endregion ID = 0x280

            #region ID = 0x380
            if (StsMsg.IdString == "382h")
            {
                if (retLEN == "8")
                {
                    ret1 = arData[0];
                }
            }
            #endregion ID = 0x380

            #region ID = 0x702
            if (StsMsg.IdString == "702h")
            {
                if (retLEN == "1")
                {
                    ret1   = arData[0];
                    mState = Convert.ToByte(ret1, 16);
                }
            }
            #endregion ID = 0x702
            return(StsMsg);
        }
예제 #12
0
파일: CANController.cs 프로젝트: CFind/HCAN
 public void Update(TPCANMsg msg, TPCANTimestamp timestamp)
 {
     this.msg       = msg;
     this.timestamp = timestamp;
     recieveCount++;
 }