包含C#,VB,VC,labwindows源码
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);
}
评论