Esempio n. 1
0
 private FXReadCommentResult ReadCommentInside()
 {
     FXReadCommentResult result = new FXReadCommentResult();
     try
     {
         FXRegionInfoResult regionInfo = ReadParamRegionInside();
         FXRegionInfo infoAddr = regionInfo.Items[(int)FXParamType.CommentRegisterFrom];
         FXRegionInfo infoLen = regionInfo.Items[(int)FXParamType.CommentRegisterBlockLen];
         int commentAddr = Convert.ToInt32(infoAddr.ValueStr, 16) + 0x8000;              //获得注释起始地址
         int commentLen = Convert.ToInt32(infoLen.ValueStr, 16) * 1000;                         //一块是1000字节
         if (!this.mSerialPort.IsOpen)
             this.mSerialPort.Open();
         int commentOffset = 0;
         List<byte[]> cmdList;
         List<byte[]> readResultList;
         while (true)
         {
             cmdList = this.CreateRegionCMDList(FXSeriesCmd.ReadProgram, commentAddr + commentOffset, COMMENTREADLEN, null);         //每次读取20长度,直到读到第一个就是00结束
             readResultList = this.mSerialPort.Read(cmdList);
             string aaa = BitConverter.ToString(readResultList[0]);
             if (readResultList[0][0] == (byte)FXSeriesControl.NAK)          //如果设备返回NAK,那直接返回
             {
                 result.Msg = "device return NAK";
                 break;
             }
             string str = Utils.BytesToStrInRightOrder(false, readResultList[0]);
             if (str.StartsWith("00"))               //如果读到的字符串以00开头,说明没有注释了,可以直接返回
                 break;
             FXCommentInfo comment = new FXCommentInfo();        //添加这个注释
             comment.SetComment(str);
             result.Comments.Add(comment);
             commentOffset += COMMENTREADLEN;
             if (commentOffset + COMMENTREADLEN > commentLen)          //如果已经超过注释区大小了,那么可以直接返回
                 break;
         }
         this.mSerialPort.Close();
     }
     catch (System.Exception ex)
     {
         result.Msg = ex.Message;
     }
     return result;
 }