示例#1
0
        /// <summary>
        /// timer's tick in it we recive and update the data sent to the PC then update them to the htable
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timerRecieve_Tick(object sender, EventArgs e)
        {
            
            PVCI_CAN_OBJ[] sendbuf = new PVCI_CAN_OBJ[200];
            int NumValue = 0;
            NumValue = VCI_Receive(2, 0, 0, sendbuf);/////////////////Get the msg from the CAN NetWork
            showCan(0, 1, sendbuf, NumValue);
            int len=sendbuf.GetLength(0);
            /////Check the Oil Height And Update the Oil Height 
            if (sendbuf[0].ID[0]==Convert.ToByte(0)) {
                CurrentBuff = sendbuf[len-1];
                if (htable.ContainsKey(OilHeight)) {
                    htable[OilHeight] = HexArr2Int(CurrentBuff.Data);
                }
            }
            ////Check the Pressure Data
            ////

            if ((int)sendbuf[0].ID[0] == 0& (int)sendbuf[0].ID[1] == 0 & (int)sendbuf[0].ID[2] == 0 & (int)sendbuf[0].ID[3] == 8)

            {
                CurrentBuff = sendbuf[0];
                if (htable.ContainsKey(pressure))
                {
                    htable[temp]=Convert.ToInt32(CurrentBuff.Data[0] );
                    htable[pressure] = Convert.ToInt32(CurrentBuff.Data[4]); //HexArr2Int(CurrentBuff.Data);
                    htable[OilHeight] = Convert.ToInt32(CurrentBuff.Data[5]);
                    htable[speed] = Convert.ToInt32(CurrentBuff.Data[6]);

                    ////sychnize data
                    ///
                    htable[temptogo] = Convert.ToInt32(htable[temp]);
                    htable[pressuretogo] =Convert.ToInt32( htable[pressure]);
                    htable[OilHeighttogo] =Convert.ToInt32( htable[OilHeight]);
                    htable[speedtogo] =Convert.ToInt32( htable[speed]);

                }
            }
            //////Check the Speed data
            /////
            //if ((sendbuf[0].ID[0] ==8)& (sendbuf[0].ID[1] == 8) & (sendbuf[0].ID[2] == 8) & sendbuf[0].ID[3] ==0)
            //{
            //    CurrentBuff = sendbuf[0];
            //    if (htable.ContainsKey(speed))
            //    {
            //        htable[speed] = HexArr2Int(CurrentBuff.Data)/1000;
            //    }
            //}
            bool t;
            byte a=250;
            t= (a == HexToInt("F")*16+HexToInt("A"));
            ///Check the GearState
            if (sendbuf[0].ID[0] == 3)
            {
                CurrentBuff = sendbuf[len - 1];
                if (htable.ContainsKey(gear))
                {
                    htable[gear] = HexArr2Int(CurrentBuff.Data);
                }
            }
            ///Give speedcomand
            ///
            if(Convert.ToInt32(htable[speedtogo])!=LastSpeed){
                string tempstr;
                tempstr = htable[speedtogo].ToString();
                transmitVariableCan(SpeedID, Convert.ToInt32(htable[speedtogo]), 3);
                transmitVariableCan(SelSpeedID, Convert.ToInt32(htable[speedtogo]), Convert.ToInt32(htable[speedtogo]), 0, 1);
                LastSpeed = (int)htable[speedtogo];
            }
            ///Give PRESSURECONMAND
            ///
            if (Convert.ToInt32(htable[pressuretogo]) !=LastPressure)
            {
                int tempint;
                tempint = Convert.ToInt32( htable[pressuretogo]);
                transmitVariableCan(PressureID, tempint, tempint, 4, 5);
                
                LastPressure = (int)htable[pressuretogo];
            }
            ///Give TempComand
            if (Convert.ToInt32(htable[temptogo]) !=LastTemp)
            {
                string tempstr;
                tempstr = htable[temptogo].ToString();
                transmitVariableCan(TempID, Convert.ToInt32(htable[temptogo]), 0);
              
                LastTemp = (int)htable[temptogo];
            }
            ///Give OilheightComand
            if (Convert.ToInt32(htable[OilHeighttogo]) != LastOilHeight)
            {
                int tempstr;
                tempstr = Convert.ToInt32(htable[OilHeighttogo]);
                transmitVariableCan(OilHeightID, tempstr, 1);
             //   TransmitACanMsg(OilHeightID,tempstr);
                LastOilHeight = (int)htable[OilHeighttogo];
            }
            ///update the view
            ///
            UpdateSpeedMeter();
            if (Form1.htable.Contains(OilHeight))
            {
                int x = Convert.ToInt32(Form1.htable[OilHeight]);
                if ((16 * x - 5.27) > 0)
                {
                    label10.Text =x.ToString();
                    if (Convert.ToInt32(label10.Text) <= OilHeightVpOnMain.Maximum)
                    {
                        OilHeightVpOnMain.Value = Convert.ToInt32(label10.Text);
                    }
                }
                else {
                    label10.Text = "0";
                    OilHeightVpOnMain.Value = 0;
                }
            }
            int y = Convert.ToInt32(Form1.htable[temp]);
            if (Convert.ToInt32(y * 0.51 - 6) >= 0)
            {
                label9.Text = (Convert.ToInt32(y * 0.51 - 46)).ToString();
            }
            else
            {
                label9.Text = "0";
            }
            TempVpOnMain.Value = Convert.ToInt32(label9.Text);
            label12.Text = Convert.ToInt32(Form1.htable[pressure]).ToString();
            if (Convert.ToInt32(label12.Text) <= PressureProgressBar.Maximum)
            {
                PressureProgressBar.Value = Convert.ToInt32(label12.Text);
            }
            //  TempVpOnMain.Value = (int)Form1.htable[pressure]/TempVpOnMain.Maximum;
            //DrawBar(sendbuf[sendbuf.GetLength(0)-1]);

        }
示例#2
0
        public void TransmitACanMsg(string IDtoSend,string data) {
            PVCI_CAN_OBJ sendbuf = new PVCI_CAN_OBJ();
            sendbuf.ID = new byte[4];
            sendbuf.Data = new byte[8];
            sendbuf.Reserved = new byte[3];
            string[] str5 = new string[32];
            byte[] buf = new byte[50];
            byte[] SendID = new byte[10];
            string strtemp, strtemp1;
           // string str1;
            int len, datanum = 0, IDnum = 0, newflag = 1;
            string strSendID = IDtoSend;//textBoxID.Text.ToString();
            char[] m_strSendID = strSendID.ToCharArray();

            len = m_strSendID.Length;
            for (int i = 0; i < len; i++)
            {
                strtemp = m_strSendID[i].ToString();
                if (strtemp == " ")
                    newflag = 1;
                else if (newflag == 1)
                {
                    newflag = 0;
                    strtemp = m_strSendID[i].ToString();
                    if (i == (len - 1))
                    {
                        str5[IDnum] = "0" + strtemp;

                    }
                    else
                    {
                        strtemp1 = m_strSendID[i + 1].ToString();

                        if (strtemp1 == " ")
                            str5[IDnum] = "0" + strtemp;
                        else
                            str5[IDnum] = strtemp + strtemp1;
                    }

                    SendID[IDnum] = (byte)Str2Hex(str5[IDnum]);
                    IDnum++;
                    if (IDnum >= 4)
                        break;
                }
            }
            newflag = 1;

            string strSendData =data;
            char[] m_strSendData = strSendData.ToCharArray();
            len = m_strSendData.Length;
            //m_strSendData.GetLength();
            for (int i = 0; i < len; i++)
            {
                
                strtemp = m_strSendData[i].ToString();
                if (strtemp == " ")
                    newflag = 1;
                else if (newflag == 1)
                {

                    newflag = 0;
                    strtemp = m_strSendData[i].ToString();
                    if (i == (len - 1))
                    {
                        str5[datanum] = "0" + strtemp;

                    }
                    else
                    {
                        strtemp1 = m_strSendData[i + 1].ToString();

                        if (strtemp1 == " ")
                        {
                            str5[datanum] = "0" + strtemp;

                        }
                        else
                            str5[datanum] = strtemp + strtemp1;

                    }
                    buf[datanum] = (byte)Str2Hex(str5[datanum]);
                    datanum++;
                    if (datanum >= 8)
                        break;
                }
            }

            byte m_nSendFrameType = 0;
            byte m_nSendFrameFormat = 0;
            byte m_radioIDFormat = 0;
            sendbuf.ExternFlag = 1;// m_nSendFrameType;//1
            sendbuf.DataLen = (byte)datanum;//8
            sendbuf.RemoteFlag = m_nSendFrameFormat;//0
            if (m_nSendFrameFormat == 1)//if remote frame, data is invalid
                for (int i = 0; i < datanum; i++)
                    buf[i] = 0;
            byte[] SendID2 = new byte[4];

            if ((sendbuf.ExternFlag) == 1)//Extend ID progress
            {
                if (m_radioIDFormat != 0)//将直接ID值进行转换到CAN2.0B格式
                {
                    SendID[0] &= 0x1F;
                    SendID2[0] = (byte)((SendID[0] << 3) | (SendID[1] >> 5));
                    SendID2[1] = (byte)((SendID[1] << 3) | (SendID[2] >> 5));
                    SendID2[2] = (byte)((SendID[2] << 3) | (SendID[3] >> 5));
                    SendID2[3] = (byte)(SendID[3] << 3);
                    for (int i = 0; i < 4; i++)
                        sendbuf.ID[i] = SendID2[i];
                    //	sendbuf->ID=(SendID2[0]<<24)+(SendID2[1]<<16)+(SendID2[2]<<8)+SendID2[3];
                }
                else
                {
                    SendID[3] = (byte)(SendID[3] & 0xF8);//the last 3 bits is invalid,clear to 0
                    for (int i = 0; i < 4; i++)
                        sendbuf.ID[i] = SendID[i];
                    //	sendbuf->ID=(SendID[0]<<24)+(SendID[1]<<16)+(SendID[2]<<8)+SendID[3];

                }
            }
            else//Basic CAN
            {

                if (m_radioIDFormat != 0)//Direct id value to SJA1000 format
                {
                    SendID[2] &= 0x07;
                    SendID2[0] = (byte)((SendID[2] << 5) | (SendID[3] >> 3));
                    SendID2[1] = (byte)(SendID[3] << 5);
                    for (int i = 0; i < 2; i++)
                        sendbuf.ID[i] = SendID2[i];
                    //sendbuf->ID=(SendID2[0]<<24)+(SendID2[1]<<16)+(SendID2[2]<<8)+SendID2[3];

                }
                else
                {
                    SendID[1] = (byte)(SendID[1] & 0xE0);//the last 5 bits is invalid, clear to 0
                    for (int i = 0; i < 2; i++)
                        sendbuf.ID[i] = SendID[i];
                    //	sendbuf->ID=(SendID[0]<<24)+(SendID[1]<<16)+(SendID[2]<<8)+SendID[3];

                }
            }

            for (int i = 0; i < datanum; i++)
                sendbuf.Data[i] = buf[i];


            int flag=0;
          
                flag = VCI_Transmit(2, 0, 0, ref sendbuf);//CAN DATA SEND
            
            PVCI_CAN_OBJ[] TempBuf = new PVCI_CAN_OBJ[50];
            for (int i = 0; i < TempBuf.GetLength(0); i++) {
                TempBuf[i] = sendbuf;
            }
                //TempBuf[1] = sendbuf;
                showCan(0, 0, TempBuf, 1);
        }
示例#3
0
        /// <summary>
        /// timer's tick in which we recive and update the data sent to the PC then update them to the htable
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timerRecieve_Tick(object sender, EventArgs e)
        {
            
            PVCI_CAN_OBJ[] sendbuf = new PVCI_CAN_OBJ[200];
            int NumValue = 0;
            NumValue = VCI_Receive(2, 0, 0, sendbuf);/////////////////Get the msg from the CAN NetWork
            showCan(0, 1, sendbuf, NumValue);
            int len=sendbuf.GetLength(0);

            if (sendbuf[0].DataLen > 0)
            {
                CurrentBuff = sendbuf[0];
                for (int i = 0; i < CurrentBuff.ID.GetLength(0); i++)
                {
                    CurrentBuff.ID[i] = (byte)((CurrentBuff.ID[i])>> 3);
                }
                ////////////////Recive the data from the dsp /////recive data of valid distance and draw on board ////the ID is 00 11 12 19
                if (CurrentBuff.ID[0] == 0x00 && CurrentBuff.ID[1] == 0x11 && CurrentBuff.ID[2] == 0x12 && CurrentBuff.ID[3] == 0x19)
                {
                    Int32[] temp = new Int32[8];
                    CurrentBuff = sendbuf[0];
                    for (int i = 0; i < 6; i++)
                    {
                        temp[i] = CurrentBuff.Data[i];
                    }
                    temp[0] = (temp[0] << 16);
                    temp[1] = (temp[1] << 8);
                    temp[2] = (temp[2]);
                    distance = temp[0] + temp[1] + temp[2];
                    angle = (temp[3]<<16) + (temp[4]<<8) + temp[5];
                    angle = angle * 360 /1152000;
                    valid_coord = new Coor();
                    valid_coord= pollor_to_Descart(distance, angle);
                    file_txt+="<Real X " + valid_coord.X.ToString() + " Y " + valid_coord.Y.ToString() + ">\n\r ";
                    //write_file("E:\\trail.txt","","X "+valid_coord.X.ToString()+"Y "+valid_coord.Y.ToString()+"\n\r");

                    //"D:\\trail.txt"
                    DrawCoorodinates( ORG_X+ (valid_coord.X)/100,ORG_Y+ (valid_coord.Y)/100);

                }

                ////////////////Recive the data from the dsp /////valid aim map point 00 11 12 1a
                if (CurrentBuff.ID[0] == 0x00 && CurrentBuff.ID[1] == 0x11 && CurrentBuff.ID[2] == 0x12 && CurrentBuff.ID[3] == 0x1a)
                {
                    Int32[] temp = new Int32[8];
                    CurrentBuff = sendbuf[0];
                    for (int i = 0; i < 6; i++)
                    {
                        temp[i] = CurrentBuff.Data[i];
                    }
                    temp[0] = (temp[0] << 16);
                    temp[1] = (temp[1] << 8);
                    temp[2] = (temp[2]);
                    x_map = temp[0] + temp[1] + temp[2];
                    y_map = (temp[3] << 16) + (temp[4] << 8) + temp[5];
                    //angle = angle * 360 / 1152000;
                    valid_coord = new Coor();
                    valid_coord = pollor_to_Descart(distance, angle);
                    file_txt += "<Map :X " + valid_coord.X.ToString() + " Y " + valid_coord.Y.ToString() + ">\n\r ";
                    //write_file("E:\\trail.txt","","X "+valid_coord.X.ToString()+"Y "+valid_coord.Y.ToString()+"\n\r");

                    //"D:\\trail.txt"
                    DrawCoorodinates_with_pen(ORG_X + (valid_coord.X) / 100, ORG_Y + (valid_coord.Y) / 100,new Pen(Color.Red));

                }
         
            }
            //  TempVpOnMain.Value = (int)Form1.htable[pressure]/TempVpOnMain.Maximum;
            //DrawBar(sendbuf[sendbuf.GetLength(0)-1]);

        }