Example #1
0
        private void GetOutputData(string dataType)
        {
            int    curPkg, totalPkg;
            string t65Response  = String.Empty;
            string tlvHexString = String.Empty;

            do
            {
                try
                {
                    serialPort.WriteAndReadMessage(PktType.STX, "T65", dataType, out t65Response);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                if (t65Response.ToUpper().StartsWith("T66F"))
                {
                    return;
                }
                else if (!Int32.TryParse(t65Response.Substring(3, 1), out curPkg) || !Int32.TryParse(t65Response.Substring(4, 1), out totalPkg))
                {
                    MessageBox.Show($"GetDataRecord failed. {t65Response}");
                    return;
                }

                int separatorIndex = t65Response.IndexOf(Convert.ToChar(0x1C));
                if (separatorIndex >= 0)
                {
                    tlvHexString += t65Response.Substring(separatorIndex + 1);
                }
            } while (curPkg < totalPkg);

            if (!string.IsNullOrEmpty(tlvHexString))
            {
                if (dataType == "0")
                {
                    dataRecord = TLVDataObject.ConvertToTLVList(tlvHexString);
                    foreach (TLVDataObject dataObj in dataRecord)
                    {
                        tbOnlineData.AppendText(dataObj.TagString() + "\t" + dataObj.ValueString() + Environment.NewLine);
                    }
                }
                else if (dataType == "1")
                {
                    discretionaryData = TLVDataObject.ConvertToTLVList(tlvHexString);
                    foreach (TLVDataObject dataObj in discretionaryData)
                    {
                        tbOnlineData.AppendText(dataObj.TagString() + "\t" + dataObj.ValueString() + Environment.NewLine);
                    }
                }
            }
        }
        private void BuildTlvTree(string stringIn, ref TreeNode parentNode)
        {
            List <TLVDataObject> tlvlist = TLVDataObject.ConvertToTLVList(stringIn);

            foreach (TLVDataObject tlv in tlvlist)
            {
                TreeNode tn = new TreeNode(tlv.TagString() + "   " + tlv.ValueString());
                parentNode.Nodes.Add(tn);
                if (tlv.IsConstructed)
                {
                    BuildTlvTree(tlv.ValueString(), ref tn);
                }
            }
            return;
        }
        public static List <TLVDataObject> ConvertToTLVList(string tlvString)
        {
            byte[] TLVData = DataHandler.HexStringToByteArray(tlvString);
            if (TLVData == null)
            {
                return(null);
            }

            List <TLVDataObject> TLVList = new List <TLVDataObject>();

            int offset = 0;

            while (offset < TLVData.Length - 1)
            {
                TLVDataObject dataObject = new TLVDataObject();
                dataObject.Parse(ref TLVData, ref offset);
                TLVList.Add(dataObject);
            }
            return(TLVList);
        }