找传奇、传世资源到传世资源站!

周立功CAN通讯源码,读写操

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

包含C#,VB,VC,labwindows源码

from clipboard
from clipboard
 unsafe private void timer_rec_Tick(object sender, EventArgs e)
        {
            UInt32 res = new UInt32();
            res=VCI_GetReceiveNum(m_devtype,m_devind,m_canind);
            if(res==0)
                return;
            //res = VCI_Receive(m_devtype, m_devind, m_canind, ref m_recobj[0],50, 100);            /////////////////////////////////////
            UInt32 con_maxlen = 50;
            IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VCI_CAN_OBJ)) * (Int32)con_maxlen);
            res = VCI_Receive(m_devtype, m_devind, m_canind, pt, con_maxlen, 100);
            ////////////////////////////////////////////////////////            String str = "";
            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);
                    byte j = 0;
                    if (j < len)
                        str = " " System.Convert.ToString(obj.Data[0], 16);
                    if (j < len)
                        str = " " System.Convert.ToString(obj.Data[1], 16);
                    if (j < len)
                        str = " " System.Convert.ToString(obj.Data[2], 16);
                    if (j < len)
                        str = " " System.Convert.ToString(obj.Data[3], 16);
                    if (j < len)
                        str = " " System.Convert.ToString(obj.Data[4], 16);
                    if (j < len)
                        str = " " System.Convert.ToString(obj.Data[5], 16);
                    if (j < len)
                        str = " " System.Convert.ToString(obj.Data[6], 16);
                    if (j < len)
                        str = " " System.Convert.ToString(obj.Data[7], 16);                }
                listBox_Info.Items.Add(str);
                listBox_Info.SelectedIndex = listBox_Info.Items.Count - 1;
            }            Marshal.FreeHGlobal(pt);
        }

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复