private void TextInput(short[] data)//cache_buffer数据写文件 { string s = Directory.GetCurrentDirectory(); System.IO.File.WriteAllText(@s + "//实时数据.txt", string.Empty);//先清空txt foreach (var b in data) { LogClass.WriteInforLognotime(b.ToString() + " ", "实时数据"); } }
public void CollectionDatasyn()//异步采集函数(0异常) { int noupdata = 0; int updata = 0; int i = 0; ret = 0; ret = WD_DASK.WD_AI_ContReadChannel((ushort)m_dev, 0, buf_id, buffernum, scantlv, samptvl, WD_DASK.ASYNCH_OP); do { iscompleted = false; ret = WD_DASK.WD_AI_AsyncCheck((ushort)m_dev, out stopped, out access_cnt);//stop为true代表异步模拟输入结束,执行异步操作 //此函数消耗时间约0.006ms,此函数调用一次,只做一次检测 //参数2 true时,代表异步模拟输入结束或发生错误,可以取数据了。false代表异步输入还没有结束 if (ret < 0)//函数出错 { MessageBox.Show("WD_AI_AsyncCheck error!\r\n" + ret.ToString()); break; } if (stopped == 1) //异步输入结束,处理数据 { for (short x = 0; x < buffernum; x++) //数据放回内存数组 { cache_buffer[x] = data_buffer[x]; } timeCount++; //时间增加 if (timeCount > startTime && timeCount <= endTime) { storeData.Add(cache_buffer); } if (timeCount == endTime) { // 保存数据 foreach (short[] temData in storeData) { TextInput(temData); LogClass.WriteInforLognotime("\r\n", "实时数据"); } DataList.Text += "数据保存完成\r\n";; } ret = WD_DASK.WD_AI_ContReadChannel((ushort)m_dev, 0, buf_id, buffernum, scantlv, samptvl, WD_DASK.ASYNCH_OP); //在指定的频道以接近指定的速率,执行连续不断的ad转换,双缓存模式的连续不断的ad转换仅仅支持post触发和延时触发模式 //参数1 执行该操作的卡id //参数2 模拟频道id //参数3 由buffersetup函数返回的一个参数,id索引的缓存数组,包含了捕获的数据 //参数4 扫描的总个数,应该是8的倍数 //参数5 扫描间隔的长度/计数值 1-65535 //参数6 采样间隔的长度/计数值 1-65535 //参数7 声明同步或者异步执行。打开pre-/middle trigger时,该函数是异步执行的 //同步转换时,函数会阻塞,直到ad转换完成。异步转换时,函数正常返回 stopped = 0; //置0 } } while (true); }