Exemple #1
0
        public TheData readDAT(string tagsFileName, string floatsFileName)
        {
            TheData result = new TheData();

            using (BinaryReader b = new BinaryReader(File.Open(tagsFileName, FileMode.Open)))
            {
                int pos = 0xA1;
                b.BaseStream.Seek(pos, SeekOrigin.Begin);
                int length = (int)b.BaseStream.Length - 1; //tagfile has a 0x1A end marker

                while (pos < length)
                {
                    TheData.TagRow t = new TheData.TagRow();
                    b.ReadByte(); // 0x20
                    char[] c = b.ReadChars(255);
                    t.tn = new string(c);
                    c    = b.ReadChars(5);
                    t.ti = int.Parse(new string(c));
                    t.tt = int.Parse(new string(b.ReadChars(1)));
                    t.td = int.Parse(new string(b.ReadChars(2)));
                    result.tags.Add(t);
                    pos += 264;
                }
            }
            using (BinaryReader b = new BinaryReader(File.Open(floatsFileName, FileMode.Open)))
            {
                int pos = 0x121;
                b.BaseStream.Seek(pos, SeekOrigin.Begin);
                int length = (int)b.BaseStream.Length;

                while (pos < length)
                {
                    TheData.FloatRow f = new TheData.FloatRow();
                    b.ReadByte(); // 0x20
                    f.date     = new string(b.ReadChars(8));
                    f.time     = new string(b.ReadChars(8));
                    f.millitm  = int.Parse(new string(b.ReadChars(3)));
                    f.tagindex = int.Parse(new string(b.ReadChars(5)));
                    f.value    = b.ReadDouble();
                    f.status   = b.ReadChar().ToString();
                    f.marker   = b.ReadChar().ToString();
                    f.intern   = b.ReadInt32();
                    result.floats.Add(f);
                    pos += 39;
                }
            }
            return(result);
        }
Exemple #2
0
        public TheData readCSV(string inputData)
        {
            TheData data = new TheData();

            using (var stream = StringStream(inputData))
                using (TextFieldParser csvParser = new TextFieldParser(stream))
                {
                    csvParser.CommentTokens = new string[] { ";" };
                    csvParser.SetDelimiters(new string[] { "," });

                    while (!csvParser.EndOfData)
                    {
                        string[] fields = csvParser.ReadFields();
                        if (fields.Length == 5)
                        {
                            TheData.TagRow t = new TheData.TagRow();
                            t.tn = fields[0];
                            t.ti = int.Parse(fields[1]);
                            t.tt = int.Parse(fields[2]);
                            t.td = int.Parse(fields[3]);
                            data.tags.Add(t);
                        }
                        else
                        {
                            TheData.FloatRow f = new TheData.FloatRow();
                            f.date     = fields[0];
                            f.time     = fields[1];
                            f.millitm  = int.Parse(fields[2]);
                            f.tagindex = int.Parse(fields[3]);
                            f.value    = double.Parse(fields[4]);
                            f.status   = fields[5];
                            if (String.IsNullOrEmpty(f.status))
                            {
                                f.status = " ";
                            }
                            f.marker = fields[6];
                            if (String.IsNullOrEmpty(f.marker))
                            {
                                f.marker = " ";
                            }
                            f.intern = int.Parse(fields[7]);
                            data.floats.Add(f);
                        }
                    }
                }
            return(data);
        }