/// <summary> /// dll库文件中的取值函数封装 /// </summary> private DataFrame GetData() { if (this.ReceiveCount != 0) { Like.CAN_DataFrame temp = new Like.CAN_DataFrame(); temp.arryData = new byte[8]; uint res = Like.CAN_ChannelReceive(this._handle, this.Channel, ref temp); if (res == 1) { DataFrame resualt = Conver2ClassDataFrame(temp); Debug.WriteLine("读取\t一帧数据\t成功", resualt.ReceiveTime.ToString()); if (EventSendHander != null) { EventReceiveHander(this, resualt); } return resualt; } else { Debug.WriteLine("读取\t一帧数据\t失败"); return null; } } else { if (this.IsRuning) { Debug.WriteLine("缓冲区暂未接收到数据"); return null; } else { Debug.WriteLine("对应CAN通道未开启"); return null; } } }
/// <summary> /// 把DataFrame对象转为结构本CAN_DataFrame /// </summary> private Like.CAN_DataFrame Conver2StructDataFrame(DataFrame data) { Like.CAN_DataFrame res = new Like.CAN_DataFrame(); res.arryData = new byte[8]; Array.Copy(data.Date, res.arryData, data.Date.Length); res.nDataLen = data.DataLength; res.nSendType = (byte)data.SendType; res.uID = data.ID; if (data.IsExternFrame) res.bExternFlag = 1; else res.bExternFlag = 0; if (data.IsRemoteFrame) res.bRemoteFlag = 1; else res.bRemoteFlag = 0; res.uTimeFlag = 0; return res; }