예제 #1
0
        /// <summary>
        /// 获取单个通道定义信息
        /// </summary>
        /// <param name="bDataInfo">包含通道定义信息的字节数组</param>
        /// <param name="start">起始下标</param>
        /// <returns>通道定义信息结构体对象</returns>
        private DataChannelInfo GetChannelInfo(byte[] bDataInfo, int start)
        {
            DataChannelInfo dci   = new DataChannelInfo();
            StringBuilder   sUnit = new StringBuilder();

            dci.sID     = BitConverter.ToInt32(bDataInfo, start);//通道起点为0,导致通道id取的都是第一个通道的id,把0改为start,
            dci.sNameEn = UnicodeEncoding.Default.GetString(bDataInfo, DataChannelOffset.NameEn + 1 + start, (int)bDataInfo[DataChannelOffset.NameEn + start]);
            dci.sNameCh = UnicodeEncoding.Default.GetString(bDataInfo, DataChannelOffset.NameCh + 1 + start, (int)bDataInfo[DataChannelOffset.NameCh + start]);
            for (int i = 1; i <= (int)bDataInfo[DataChannelOffset.Unit + start]; i++)
            {
                sUnit.Append(UnicodeEncoding.Default.GetString(bDataInfo, DataChannelOffset.Unit + i + start, 1));
            }
            dci.sUnit   = sUnit.ToString();
            dci.fScale  = BitConverter.ToSingle(bDataInfo, DataChannelOffset.Scale + start);
            dci.fOffset = BitConverter.ToSingle(bDataInfo, DataChannelOffset.Offset + start);

            return(dci);
        }
예제 #2
0
 /// <summary>
 /// 查询CIT通道信息--返回通道定义结构体列表,同时dciL全局变量赋值
 /// 返回:通道定义信息结构体对象列表
 /// </summary>
 /// <param name="sFile">CIT文件名(全路径)</param>
 /// <returns>返回结构体</returns>
 public List <DataChannelInfo> GetDataChannelInfoHead(string sFile)
 {
     using (FileStream fs = new FileStream(sFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         using (BinaryReader br = new BinaryReader(fs, Encoding.Default))
         {
             br.BaseStream.Position = 0;
             br.ReadBytes(DataOffset.DataHeadLength);
             byte[] bChannelData = br.ReadBytes(dhi.iChannelNumber * DataOffset.DataChannelLength);
             dciL = new List <DataChannelInfo>();
             for (int i = 0; i < dhi.iChannelNumber * DataOffset.DataChannelLength; i += DataOffset.DataChannelLength)
             {
                 DataChannelInfo dci = GetChannelInfo(bChannelData, i);
                 if (i == DataOffset.DataChannelLength)
                 {
                     dci.fScale = 4;
                 }
                 dciL.Add(dci);
             }
         }
     }
     return(dciL);
 }
예제 #3
0
        /// <summary>
        /// 把反方向检测转换为正方向检测
        /// </summary>
        /// <param name="citFileName"></param>
        public void ModifyCitReverseToForward(String citFileName)
        {
            DataHeadInfo           m_dhi  = GetDataInfoHead(citFileName);
            List <DataChannelInfo> m_dciL = GetDataChannelInfoHead(citFileName);


            //左高低与右高低对调
            ChannelExchange(m_dciL, "L_Prof_SC", "R_Prof_SC", false);
            ChannelExchange(m_dciL, "L_Prof_SC_70", "R_Prof_SC_70", false);
            ChannelExchange(m_dciL, "L_Prof_SC_120", "R_Prof_SC_120", false);

            DataChannelInfo m_dci_a = new DataChannelInfo();

            //左轨向与右轨向对调,然后幅值*(-1)
            ChannelExchange(m_dciL, "L_Align_SC", "R_Align_SC", true);
            ChannelExchange(m_dciL, "L_Align_SC_70", "R_Align_SC_70", true);
            ChannelExchange(m_dciL, "L_Align_SC_120", "R_Align_SC_120", true);


            //水平、超高、三角坑、曲率、曲率变化率*(-1)
            for (int i = 0; i < m_dciL.Count; i++)
            {
                if (m_dciL[i].sNameEn.Equals("Crosslevel"))
                {
                    m_dci_a        = m_dciL[i];
                    m_dci_a.fScale = m_dci_a.fScale * (-1);
                    m_dciL[i]      = m_dci_a;
                }

                if (m_dciL[i].sNameEn.Equals("Superelevation"))
                {
                    m_dci_a        = m_dciL[i];
                    m_dci_a.fScale = m_dci_a.fScale * (-1);
                    m_dciL[i]      = m_dci_a;
                }

                if (m_dciL[i].sNameEn.Equals("Short_Twist"))
                {
                    m_dci_a        = m_dciL[i];
                    m_dci_a.fScale = m_dci_a.fScale * (-1);
                    m_dciL[i]      = m_dci_a;
                }

                if (m_dciL[i].sNameEn.Equals("Curvature"))
                {
                    m_dci_a        = m_dciL[i];
                    m_dci_a.fScale = m_dci_a.fScale * (-1);
                    m_dciL[i]      = m_dci_a;
                }

                if (m_dciL[i].sNameEn.Equals("Curvature_Rate"))
                {
                    m_dci_a        = m_dciL[i];
                    m_dci_a.fScale = m_dci_a.fScale * (-1);
                    m_dciL[i]      = m_dci_a;
                }
            }

            try
            {
                #region 存取文件
                FileStream   fsRead    = new FileStream(citFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                FileStream   fsWrite   = new FileStream(citFileName + ".bak", FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                BinaryReader br        = new BinaryReader(fsRead, Encoding.UTF8);
                BinaryWriter bw1       = new BinaryWriter(fsWrite, Encoding.UTF8);
                byte[]       bHead     = br.ReadBytes(120);
                byte[]       bChannels = br.ReadBytes(65 * m_dhi.iChannelNumber);
                byte[]       bData     = new byte[m_dhi.iChannelNumber * 2];
                byte[]       bDataNew  = new byte[m_dhi.iChannelNumber * 2];
                byte[]       bTail     = br.ReadBytes(BitConverter.ToInt32(br.ReadBytes(4), 0));

                //bw1.Write(bHead);

                bw1.Write(GetBytesFromDataHeadInfo(m_dhi));//文件头
                //反向--转换为正向
                if (m_dhi.iRunDir == 0)
                {
                    bw1.Write(bChannels);
                }
                else
                {
                    bw1.Write(GetBytesFromChannelDataInfoList(m_dciL));
                }

                bw1.Write(bTail.Length);
                bw1.Write(bTail);

                long startPos = br.BaseStream.Position;//记录数据开始位置的文件指针

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    bw1.Write(br.ReadBytes(m_dhi.iChannelNumber * 2));
                    //br.BaseStream.Position += m_dhi.iChannelNumber * 2;
                }

                //
                bw1.Close();
                br.Close();
                fsWrite.Close();
                fsRead.Close();
                //删除bak
                Application.DoEvents();
                File.Delete(citFileName);
                Application.DoEvents();
                File.Move(citFileName + ".bak", citFileName);
                Application.DoEvents();
                #endregion
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            return;
        }