Esempio n. 1
0
        unsafe private void ReceiveUpData()
        {
            String idStr   = "";
            string dataStr = string.Empty;
            UInt32 res     = new UInt32();
            UInt32 canId   = 0;

            res = DllAdapte.VCI_GetReceiveNum(mDevType, mDevInd, canId);

            if (res == 0)
            {
                return;
            }

            //res = DllAdapte.VCI_Receive(mDevType, mDevInd, mCanInd, ref mRecObj[0],50, 100);
            UInt32 con_maxlen = 50;
            IntPtr pt         = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VCI_CAN_OBJ)) * (Int32)con_maxlen);

            res = DllAdapte.VCI_Receive(mDevType, mDevInd, canId, pt, con_maxlen, 100);

            for (UInt32 i = 0; i < res; i++)
            {
                VCI_CAN_OBJ obj = (VCI_CAN_OBJ)Marshal.PtrToStructure((IntPtr)((UInt32)pt + i * Marshal.SizeOf(typeof(VCI_CAN_OBJ))), typeof(VCI_CAN_OBJ));
                idStr = System.Convert.ToString((Int32)obj.ID, 16);

                if (idStr.Contains("1441abaa"))    // && mPauseFlag == 0
                {
                    if (obj.Data[1] == (byte)0xcc)
                    {
                        mUpCmd = UpgradeCmd.CmdUpgrade;
                        sendListBox.Items.Add("同主机Ping成功!");
                    }
                    else
                    {
                        mUpCmd = UpgradeCmd.CmdPing;
                    }
                }

                if (idStr.Contains("1442abaa"))     // && mPauseFlag == 0
                {
                    if (obj.Data[1] == (byte)0xcc)
                    {
                        mFrameSendFlag = 0;
                        mUpgradeFlag   = 0;
                        mUpCmd         = UpgradeCmd.CmdNone;
                        //timerSend.Enabled = false;  //重启后要先关闭发送定时器
                        sendListBox.Items.Add("主机重启成功!");
                    }
                }

                if (idStr.Contains("1443abaa"))      // && mPauseFlag == 0
                {
                    if (obj.Data[1] == (byte)0xcc)
                    {
                        mUpCmd = UpgradeCmd.CmdSendData;
                        sendListBox.Items.Add("发送升级地址成功!");
                    }
                    else if (obj.Data[1] == (byte)0x33)
                    {
                        mUpgradeFlag = 0;
                        mUpCmd       = UpgradeCmd.CmdNone;
                        sendListBox.Items.Add("升级下载地址不符合FLASH空间大小!");
                    }
                    else
                    {
                        mUpCmd = UpgradeCmd.CmdUpgrade;
                    }
                }

                if (idStr.Contains("1444abaa"))     // && mPauseFlag == 0
                {
                    if (obj.Data[1] == (byte)0x33)
                    {
                        mRevFrameNum        = 0;
                        mUpgradeFlag        = 0;
                        progressBar.Visible = false;
                        mUpCmd = UpgradeCmd.CmdRun;
                        sendListBox.Items.Add("升级成功!");
                        mBinReader.Close();
                        mBinStream.Close();
                    }
                    else if (obj.Data[1] == (byte)0xcc)
                    {
                        mUpCmd = UpgradeCmd.CmdSendData;
                    }
                    else
                    {
                        if (mSendDone == 1)
                        {
                            progressBar.Visible = false;
                            mSendDone           = 0; //标志复位
                            mUpgradeFlag        = 0;
                            //mUpCmd = UpgradeCmd.CmdRun;
                            sendListBox.Items.Add("数据发送完成但未收到主机应答信号!");
                        }
                        else
                        {
                            mUpgradeFlag = 0;
                            mUpCmd       = UpgradeCmd.CmdNone;
                            sendListBox.Items.Add("提示:主机在本帧中有丢失数据!");
                        }
                    }
                }

                if (obj.RemoteFlag == 0)
                {
                    byte len = (byte)(obj.DataLen % 9);

                    for (byte j = 0; j < len; j++)
                    {
                        if (j == 0)
                        {
                            dataStr += obj.Data[j].ToString("X2");
                        }
                        else
                        {
                            dataStr += " " + obj.Data[j].ToString("X2"); //System.Convert.ToString(obj.Data[j], 16);
                        }
                    }
                }

                if (mPauseFlag == 0)
                {
                    if (mFrameSendFlag == 1)
                    {
                        mRevFrameNum++;
                    }

                    RevListBox.Items.Add("报文ID: 0x" + idStr + "  接收数据: " + dataStr + "    接收帧数: " + mRevFrameNum.ToString("X4"));
                    RevListBox.SelectedIndex = RevListBox.Items.Count - 1;
                }

                dataStr = string.Empty;
            }

            Marshal.FreeHGlobal(pt);
        }
Esempio n. 2
0
        unsafe private void ReceiveDataHandle(UInt32 canId)
        {
            String str = "";
            UInt32 res = new UInt32();

            res = DllAdapte.VCI_GetReceiveNum(mDevType, mDevInd, canId);

            if (res == 0)
            {
                return;
            }

            //res = DllAdapte.VCI_Receive(mDevType, mDevInd, mCanInd, ref mRecObj[0],50, 100);
            UInt32 con_maxlen = 50;
            IntPtr pt         = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VCI_CAN_OBJ)) * (Int32)con_maxlen);

            res = DllAdapte.VCI_Receive(mDevType, mDevInd, canId, pt, con_maxlen, 100);

            for (UInt32 i = 0; i < res; i++)
            {
                VCI_CAN_OBJ obj = (VCI_CAN_OBJ)Marshal.PtrToStructure((IntPtr)((UInt32)pt + i * Marshal.SizeOf(typeof(VCI_CAN_OBJ))), typeof(VCI_CAN_OBJ));
                //str = "接收到数据: ";
                str += "  帧ID:0x" + System.Convert.ToString((Int32)obj.ID, 16);
                str += "  帧格式:";

                if (obj.RemoteFlag == 0)
                {
                    str += "数据帧 ";
                }
                else
                {
                    str += "远程帧 ";
                }

                if (obj.ExternFlag == 0)
                {
                    str += "标准帧 ";
                }
                else
                {
                    str += "扩展帧 ";
                }

                if (obj.RemoteFlag == 0)
                {
                    str += "数据: ";
                    byte len = (byte)(obj.DataLen % 9);

                    for (byte j = 0; j < len; j++)
                    {
                        if (j == 0)
                        {
                            str += obj.Data[j].ToString("X2");
                        }
                        else
                        {
                            str += " " + obj.Data[j].ToString("X2"); //System.Convert.ToString(obj.Data[j], 16);
                        }
                    }
                }

                if (mPauseFlag == 0)
                {
                    RevListBox.Items.Add(str);
                    RevListBox.SelectedIndex = RevListBox.Items.Count - 1;
                }

                str = string.Empty;
            }

            Marshal.FreeHGlobal(pt);
        }