public int GetChannelNumberByChannelName(string FileName, string EnName, string CnName) { List <CITDataProcess.DataChannelInfo> dci = cdp.GetDataChannelInfoHeadNew(FileName); int ChannelNumber = -1; for (int i = 0; i < dci.Count; i++) { if ((dci[i].sNameEn.Contains(EnName) && (EnName != "")) || (dci[i].sNameCh.Contains(CnName)) && (CnName != "")) { ChannelNumber = i + 1; break; } } return(ChannelNumber); }
private void ReadCIT(String citFilePath) { if (numericUpDown1.Value <= 0) { MessageBox.Show("容许跳变值为 0"); return; } try { autoIndexClsList.Clear(); dataGridView1.Rows.Clear(); CITDataProcess.DataHeadInfo m_dhi = cdp.GetDataInfoHead(citFilePath); List <CITDataProcess.DataChannelInfo> m_dcil = cdp.GetDataChannelInfoHeadNew(citFilePath); FileStream fs = new FileStream(citFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryReader br = new BinaryReader(fs, Encoding.Default); br.BaseStream.Position = 0; br.ReadBytes(120); br.ReadBytes(65 * m_dhi.iChannelNumber); br.ReadBytes(BitConverter.ToInt32(br.ReadBytes(4), 0)); int iChannelNumberSize = m_dhi.iChannelNumber * 2; byte[] b = new byte[iChannelNumberSize]; long milePos = 0; int km_pre = 0; int meter_pre = 0; int km_currrent = 0; int meter_current = 0; int meter_between = 0; int km_index = 0; int meter_index = 2; long iArray = (br.BaseStream.Length - br.BaseStream.Position) / iChannelNumberSize; for (int i = 0; i < iArray; i++) { milePos = br.BaseStream.Position; b = br.ReadBytes(iChannelNumberSize); if (m_dhi.sDataVersion.StartsWith("3.")) { b = CITDataProcess.ByteXORByte(b); } if (i == 0) { //km_pre = (int)(BitConverter.ToInt16(b, km_index) / m_dcil[km_index].fScale + m_dcil[km_index].fOffset); //meter_pre = (int)(BitConverter.ToInt16(b, meter_index) / m_dcil[meter_index].fScale + m_dcil[meter_index].fOffset); km_pre = (int)(BitConverter.ToInt16(b, km_index)); meter_pre = (int)(BitConverter.ToInt16(b, meter_index)); } else { //km_currrent = (int)(BitConverter.ToInt16(b, km_index) / m_dcil[km_index].fScale + m_dcil[km_index].fOffset); //meter_current = (int)(BitConverter.ToInt16(b, meter_index) / m_dcil[meter_index].fScale + m_dcil[meter_index].fOffset); km_currrent = (int)(BitConverter.ToInt16(b, km_index)); meter_current = (int)(BitConverter.ToInt16(b, meter_index)); meter_between = (km_currrent - km_pre) * 4000 + (meter_current - meter_pre); if (Math.Abs(meter_between) > numericUpDown1.Value) { AutoIndexClass autoIndexCls = new AutoIndexClass(); autoIndexCls.milePos = milePos; autoIndexCls.km_current = km_currrent; autoIndexCls.meter_current = meter_current; autoIndexCls.km_pre = km_pre; autoIndexCls.meter_pre = meter_pre; autoIndexCls.meter_between = meter_between; autoIndexClsList.Add(autoIndexCls); } km_pre = km_currrent; meter_pre = meter_current; } } br.Close(); fs.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }