コード例 #1
0
        private void timerRecieve_Tick(object sender, EventArgs e)
        {
            PVCI_CAN_OBJ[] sendbuf  = new PVCI_CAN_OBJ[20];
            int            NumValue = 0;

            NumValue = VCI_Receive(3, 0, 1, sendbuf);
            showCan(1, 1, sendbuf, NumValue);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Sust2014/Interface-C-Sharp
        public void Receive()
        {
            int ReceiveFlag;

            PVCI_CAN_OBJ[] databuf    = new PVCI_CAN_OBJ[300];
            PVCI_CAN_OBJ   receivebuf = new PVCI_CAN_OBJ();

            receivebuf.ID       = new byte[4];
            receivebuf.Data     = new byte[8];
            receivebuf.Reserved = new byte[3];

            receivebuf.DataLen = 8;
            PVCI_CAN_OBJ[] TempBuf = new PVCI_CAN_OBJ[50];
            ReceiveFlag = VCI_Receive(2, 0, 0, databuf);
            if (ReceiveFlag == 0)
            {
                MessageBox.Show("接收数据错误!");
            }
            else
            {
                for (int i = 0; i < 8; i++)
                {
                    receivebuf.Data[i] = databuf[0].Data[i];
                }

                byte[] ReceiveID_New = new byte[4];
                ReceiveID_New[0] = databuf[0].ID[0];
                ReceiveID_New[1] = databuf[0].ID[1];
                ReceiveID_New[2] = databuf[0].ID[2];
                ReceiveID_New[3] = databuf[0].ID[3];

                receivebuf.ID[0] = (byte)((ReceiveID_New[0] >> 1) | (ReceiveID_New[1] >> 1));

                TempBuf[0] = receivebuf;
                showCan(0, 1, TempBuf, 1);
            }
        }
コード例 #3
0
 public static extern int VCI_Transmit(uint DevType, uint DevIndex, uint CANIndex, ref PVCI_CAN_OBJ pSend);
コード例 #4
0
        private void showCan(byte byCanIndex, byte byOrientation, PVCI_CAN_OBJ [] buf, int nLength)
        {
            DateTime CurrentTime = new DateTime();

            for (uint i = 0; i < nLength; i++)
            {
                PVCI_CAN_OBJ temp    = buf[i];
                ListViewItem Item    = new ListViewItem();
                string       strNum  = Convert.ToString(m_nNum);
                string       strTime = DateTime.Now.ToString();//strHour + ":" + strMinute + "" + strSecond;
                int          foundS1 = strTime.IndexOf(" ");
                strTime = strTime.Remove(0, foundS1);

                string strCanIndex = Convert.ToString(byCanIndex);
                string strOrientation;
                if (byOrientation == 0)
                {
                    strOrientation = "发送";
                }
                else
                {
                    strOrientation = "接收";
                }
                byte   a      = temp.ID[0];
                string strID0 = Convert.ToString((buf[i]).ID[0]);
                string strID1 = Convert.ToString((buf[i]).ID[1]);
                string strID2 = Convert.ToString((buf[i]).ID[2]);
                string strID3 = Convert.ToString((buf[i]).ID[3]);
                string strID  = strID0 + " " + strID1 + " " + strID2 + " " + strID3;
                string strFrame;
                if ((buf[i]).RemoteFlag == 1)
                {
                    strFrame = "远程帧";
                }
                else
                {
                    strFrame = "数据帧";
                }
                string strType;
                if (buf[i].ExternFlag == 1)
                {
                    strType = "扩展帧";
                }
                else
                {
                    strType = "标准帧";
                }
                string strDataLen = Convert.ToString(buf[i].DataLen);
                string strData    = Convert.ToString(buf[i].Data[0]);
                for (int j = 1; j < 8; j++)
                {
                    string strTemp;
                    strTemp = Convert.ToString(buf[i].Data[j]);
                    strData = strData + " " + strTemp;
                }
                Item.SubItems.Clear();
                Item.SubItems[0].Text = strNum;
                Item.SubItems.Add(strTime);
                Item.SubItems.Add(strCanIndex);
                Item.SubItems.Add(strOrientation);
                Item.SubItems.Add(strID);
                Item.SubItems.Add(strFrame);
                Item.SubItems.Add(strType);
                Item.SubItems.Add(strDataLen);
                Item.SubItems.Add(strData);
                listViewRecieve.Items.Add(Item);
                m_nNum++;
            }
        }
コード例 #5
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            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 = 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 = TextBoxSend.Text.ToString();

            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 = 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;

            flag = VCI_Transmit(3, 0, 0, ref sendbuf);//CAN DATA SEND
            PVCI_CAN_OBJ[] TempBuf = new PVCI_CAN_OBJ[50];
            TempBuf[0] = sendbuf;
            showCan(0, 0, TempBuf, 1);
            if (flag != 1)
            {
                if (flag == -1)
                {
                    MessageBox.Show("fail,device not open\n");
                }
                else if (flag == 0)
                {
                    MessageBox.Show("fail\n");
                }
                return;
            }
            string str = "";

            for (int i = 0; i < sendbuf.DataLen; i++)                   //DATA
            {
                uint data = sendbuf.Data[i];
                str1 = Convert.ToString(data, 16);
                str += str1 + " ";
            }
            //    listView1.Items.Add(str).SubItems.Add("Send");
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: Sust2014/Interface-C-Sharp
        private void showCan(byte byCanIndex, byte byOrientation, PVCI_CAN_OBJ[] buf, int nLength)
        {
            DateTime CurrentTime = new DateTime();

            for (uint i = 0; i < nLength; i++)
            {
                PVCI_CAN_OBJ temp    = buf[i];
                ListViewItem Item    = new ListViewItem();
                string       strNum  = Convert.ToString(m_nNum);
                string       strTime = DateTime.Now.ToString();//strHour + ":" + strMinute + "" + strSecond;
                int          foundS1 = strTime.IndexOf(" ");
                strTime = strTime.Remove(0, foundS1);

                string strCanIndex = Convert.ToString(byCanIndex);
                string strOrientation;
                if (byOrientation == 0)
                {
                    strOrientation = "发送";
                }
                else
                {
                    strOrientation = "接收";
                }
                byte a = temp.ID[0];
                //string test_data ;
                string strID0 = Convert.ToString((buf[i]).ID[0], 16);
                //十进制转换为十六进制
                //test_data = Convert.ToString(buf[i].ID[1],16);
                string strID1 = Convert.ToString((buf[i]).ID[1], 16);
                string strID2 = Convert.ToString((buf[i]).ID[2], 16);
                string strID3 = Convert.ToString((buf[i]).ID[3], 16);
                //string strID = strID3 + " " + strID2 + " " + strID1 + " " + strID0;
                string strID;
                if (buf[i].ExternFlag == 1)
                {
                    strID = strID3 + " " + strID2 + " " + strID1 + " " + strID0;
                }
                else
                {
                    strID = strID1 + " " + strID0;
                }

                //选择发送的数据格式和数据类型
                string strFrame;
                buf[i].RemoteFlag = (byte)ComBoxFrameType.SelectedIndex;
                if ((buf[i]).RemoteFlag == 1)
                {
                    strFrame = "远程帧";
                }
                else
                {
                    strFrame = "数据帧";
                }
                string strType;
                buf[i].ExternFlag = (byte)ComBoxFrameFormat.SelectedIndex;
                if (buf[i].ExternFlag == 1)
                {
                    strType = "扩展帧";
                }
                else
                {
                    strType = "标准帧";
                }

                //数据长度
                string strDataLen = Convert.ToString(buf[i].DataLen);
                string strData;

                if (DataFormat == false)
                {
                    strData = Convert.ToString(buf[i].Data[0]);
                }
                else
                {
                    strData = Convert.ToString(buf[i].Data[0], 16);
                }
                for (int j = 1; j < 8; j++)
                {
                    string strTemp;
                    if (DataFormat == false)
                    {
                        strTemp = Convert.ToString(buf[i].Data[j]);
                    }
                    else
                    {
                        strTemp = Convert.ToString(buf[i].Data[j], 16);
                    }
                    strData = strData + " " + strTemp;
                }
                Item.SubItems.Clear();
                Item.SubItems[0].Text = strNum;
                Item.SubItems.Add(strTime);
                Item.SubItems.Add(strCanIndex);
                Item.SubItems.Add(strOrientation);
                Item.SubItems.Add(strID);
                Item.SubItems.Add(strFrame);
                Item.SubItems.Add(strType);
                Item.SubItems.Add(strDataLen);
                Item.SubItems.Add(strData);
                if (byOrientation == 0)
                {
                    Item.BackColor = Color.MediumSpringGreen;
                }
                else
                {
                    Item.BackColor = Color.Aqua;
                }
                //listViewRecieve.Items[listViewRecieve.Items.Count - 1].EnsureVisible();
                listViewRecieve.Items.Add(Item);
                listViewRecieve.Items[listViewRecieve.Items.Count - 1].EnsureVisible();
                m_nNum++;
            }
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: qiubailiang/src_docs
        private void showCan(byte byCanIndex,byte byOrientation, PVCI_CAN_OBJ []buf,int nLength)
        {
           DateTime CurrentTime = new DateTime();
            for(uint i=0;i<nLength;i++)
            {
                PVCI_CAN_OBJ temp = buf[i];
                ListViewItem Item = new ListViewItem();
                string strNum = Convert.ToString(m_nNum);
                string strTime = DateTime.Now.ToString();//strHour + ":" + strMinute + "" + strSecond;
                int foundS1 = strTime.IndexOf(" ");
                strTime= strTime.Remove(0, foundS1);

                string strCanIndex = Convert.ToString(byCanIndex);
                string strOrientation;
                if(byOrientation==0)
                    strOrientation ="发送";
                else
                    strOrientation="接收";
                byte a = temp.ID[0];
                string strID0 = Convert.ToString((buf[i]).ID[0]);
                string strID1 = Convert.ToString((buf[i]).ID[1]);
                string strID2 = Convert.ToString((buf[i]).ID[2]);
                string strID3 = Convert.ToString((buf[i]).ID[3]);
                string strID=strID0+" "+strID1+" "+strID2+" "+strID3;
                string strFrame;
                if ((buf[i]).RemoteFlag==1)
                    strFrame="远程帧";
                else
                    strFrame="数据帧";
                string strType;
                if(buf[i].ExternFlag==1)
                    strType="扩展帧";
                else
                    strType="标准帧";
                string strDataLen=Convert.ToString(buf[i].DataLen);
                string strData=Convert.ToString(buf[i].Data[0]);
                for(int j=1;j<8;j++)
                {
                    string strTemp;
                    strTemp=Convert.ToString(buf[i].Data[j]);
                    strData=strData+" "+strTemp;
                }    
                Item.SubItems.Clear();
                Item.SubItems[0].Text = strNum;
                Item.SubItems.Add(strTime);
                Item.SubItems.Add(strCanIndex);
                Item.SubItems.Add(strOrientation);
                Item.SubItems.Add(strID);
                Item.SubItems.Add(strFrame);
                Item.SubItems.Add(strType);
                Item.SubItems.Add(strDataLen);
                Item.SubItems.Add(strData);
                listViewRecieve.Items.Add(Item);
                m_nNum++;
            }
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: qiubailiang/src_docs
 public static extern int VCI_Transmit(uint DevType, uint DevIndex, uint CANIndex, ref PVCI_CAN_OBJ pSend);
コード例 #9
0
ファイル: Form1.cs プロジェクト: qiubailiang/src_docs
 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);
     showCan(0, 1, sendbuf, NumValue);
 }
コード例 #10
0
ファイル: Form1.cs プロジェクト: qiubailiang/src_docs
        private void buttonSend_Click(object sender, EventArgs e)
        {
            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 =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 = TextBoxSend.Text.ToString();
            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 = 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;

            flag = VCI_Transmit(2, 0, 0, ref sendbuf);//CAN DATA SEND
            PVCI_CAN_OBJ[] TempBuf = new PVCI_CAN_OBJ[50];
            TempBuf[0] = sendbuf;
            showCan(0, 0, TempBuf, 1);
            if (flag != 1)
            {
                if (flag == -1)
                    MessageBox.Show("fail,device not open\n");
                else if (flag == 0)
                    MessageBox.Show("fail\n");
                return;

            }
            string str = "";
            for (int i = 0; i < sendbuf.DataLen; i++)			//DATA
            {
                uint data = sendbuf.Data[i];
                str1 = Convert.ToString(data, 16);
                str += str1 + " ";

            }
        //    listView1.Items.Add(str).SubItems.Add("Send");
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: qiubailiang/src_docs
        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);
        }
コード例 #12
0
ファイル: Form1.cs プロジェクト: qiubailiang/src_docs
        /// <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]);

        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: qiubailiang/src_docs
        /// <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]);

        }