// 13. ChannelGatherParam HandleRef data为ChannelGatherParamA429Rx类型 public uint ChannelGatherParam(ref ChannelGatherParamA429Rx gatherParameter, ParamOptionA429 paramOpt) { IntPtr ptr = _channelGatherParamRxIntPtr; byte[] bytes = _channelGatherParamRxInitArray; //获取数据前清空,内存中的数据 if (paramOpt == ParamOptionA429.BHT_L1_PARAM_OPT_GET) { //获取数据前清空,内存中的数据 Marshal.Copy(bytes, 0, ptr, bytes.Length); } else { //若设置,把ref类型参数中的数据写入到内存中 byte[] parameterBytes = UtilityConvertor.StructToBytes(gatherParameter); Marshal.Copy(parameterBytes, 0, ptr, bytes.Length); } //调用方法,获取数据 uint ret = NativeMethods429.ChannelGatherParam(DeviceID, ChannelID, ptr, paramOpt); //转换非托管数据为托管数据 gatherParameter = null; if (ret == Normal) { gatherParameter = (ChannelGatherParamA429Rx)Marshal.PtrToStructure(ptr, typeof(ChannelGatherParamA429Rx)); } return(ret); }
/// <summary> /// 把保存的数据保存到指定位置。 /// </summary> public void Save() { if (IsSimulateState && CanCollectData) { List <string> outPutList = new List <string>(); foreach (var keyValue in _dataDictionary) { string key = keyValue.Key; foreach (SimulateData data in keyValue.Value) { outPutList.Add(key + "~" + UtilityConvertor.ReversibleByteArrayToString(data.Bytes)); } } File.WriteAllLines(_dataPath, outPutList); } }
/// <summary> /// 初始化仿真器。 /// 主要工作为: /// 1、获取仿真器要产生的(也是要获取的)仿真数据的位置。 /// 2、把仿真数据放到内存里面的DataDictionary /// </summary> public void Initialize(string dir) { IsSimulateState = (bool)App.Instance.Parameter.GetParaData(ParameterNames.IsSimulateBoardState).Value; CanCollectData = (bool)App.Instance.Parameter.GetParaData(ParameterNames.CanCollectBoardData).Value; if (!IsSimulateState) { return; } //1、获取仿真器要产生的(也是要获取的)仿真数据的位置。 _dataPath = dir + "\\Config\\SimulateData.bin"; //2、把仿真数据放到内存里面的DataDictionary if (File.Exists(_dataPath) && IsSimulateState) { string[] rows = File.ReadAllLines(_dataPath); foreach (var row in rows) { string[] keyValue = row.Split('~'); if (keyValue.Length == 2) { string key = keyValue[0]; string[] strArray = key.Split('+'); string ip = strArray[0]; byte[] bytes = UtilityConvertor.ReversibleStringByteToArray(keyValue[1]); if (!_dataDictionary.ContainsKey(key)) { _dataDictionary.Add(key, new List <SimulateData>()); } _dataDictionary[key].Add(new SimulateData(bytes, ip)); } } } }