// C:\Users\Jack\Desktop\trader\KLine\rb1609_d1.txt public void OpenChartFile(string fileName) { if (!String.IsNullOrEmpty(fileName)) { int m1 = fileName.LastIndexOf(@"\"); int m2 = fileName.LastIndexOf(@"_"); int m3 = fileName.IndexOf(@".txt"); String pathCtp = fileName.Substring(0, fileName.LastIndexOf(@"\")); // string[] subLines = pathCtp.Split('\\'); stockName = fileName.Substring(m1 + 1, m2 - m1 - 1); String period = fileName.Substring(m2 + 1, m3 - m2 - 1); label_symbol.Text = stockName + @" 周期: " + period; DataStock = LoadCtpInfo(fileName); DataStock.Reverse(); //for last 300 xEnd = 0; xBegin = Math.Min(xInitShowBars, DataStock.Count - 1); //xShowBars = xInitShowBars; ReFreshMe(ref xBegin, ref xEnd, ref xShowBars, 0); } }
public void DataUpdate(byte[] readBuffer, int offset, int length) // 接收采集板发来的16进制数据,并将其转换成双字节数组 { //temp_lst = new List<int[]>(); //_temp_lst = new List<int[]>(); var curSumData = new int[16]; for (var bufferIndex = 0; bufferIndex < length; bufferIndex += 32) { var dataArray = new int[16]; for (var arrayIndex = 0; arrayIndex < 16; arrayIndex++) { dataArray[arrayIndex] = (readBuffer[bufferIndex + 2 * arrayIndex + 1] << 8) | readBuffer[bufferIndex + 2 * arrayIndex]; curSumData[arrayIndex] += dataArray[arrayIndex]; } //_temp_lst.Add(DataArray); _dataLock.WaitOne(); CurrentData = dataArray; _dataLock.ReleaseMutex(); if (DataStock == null) { continue; } if (!_dataStoreSwitch) { continue; } if (_dataStoreCount == 0 || DataStock.Count < _dataStoreCount) { _stockLock.WaitOne(); DataStock.Add(dataArray); _stockLock.ReleaseMutex(); } else { _dataStoreSwitch = false; _dataStoreCount = 0; } } _preAvLock.WaitOne(); _curAvLock.WaitOne(); _preAverageData = _curAverageData; for (var i = 0; i < curSumData.Length; i++) { _curAverageData[i] = curSumData[i] / 32; //DataLock.WaitOne(); //CurrentData[i] = CurSumData[i] / 32; //DataLock.ReleaseMutex(); } //DataLock.WaitOne(); //if (CurrentData[10] > 30000) //{ // for (int i = 0; i < 16; i ++) // { // temp_lst = _temp_lst; // } //} //DataLock.ReleaseMutex(); _curAvLock.ReleaseMutex(); _preAvLock.ReleaseMutex(); }