Esempio n. 1
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Error: argument not found");
                Console.WriteLine("Usage: dat2fth PointPrefix [path]");
                return;
            }
            PIAPI.POINT_PREFIX = args[0];

            string path = ".";

            if (args.Length >= 2)
            {
                path = args[1];
            }

            DatReader dr        = new DatReader(path);
            uint      converted = 0;

            List <string> tagnames = new List <string>();

            using (StreamWriter val_writer = new StreamWriter(File.Open("values.csv", FileMode.Create)))
            {
                val_writer.Write("@mode edit, t\n");
                val_writer.Write("@table pisnap\n");
                val_writer.Write("@istr tag, time, value\n");

                foreach (string infilename in dr.GetFloatfiles())
                {
                    Console.WriteLine("converting {0}", Path.GetFileName(infilename));
                    MakeFTH(dr, infilename, val_writer, tagnames);
                    converted++;
                }
            }
            Console.WriteLine("converted {0} files", converted);

            using (StreamWriter pts_writer = new StreamWriter(File.Open("del_points.csv", FileMode.Create)))
            {
                pts_writer.Write("@tabl pipoint,classic\n");
                pts_writer.Write("@mode delete\n");
                pts_writer.Write("@istr tag\n");
                foreach (var tagname in tagnames)
                {
                    pts_writer.Write($"{PIAPI.TagToPoint(tagname)}\n");
                }
            }
            using (StreamWriter pts_writer = new StreamWriter(File.Open("add_points.csv", FileMode.Create)))
            {
                pts_writer.Write("@tabl pipoint,classic\n");
                pts_writer.Write("@mode create\n");
                pts_writer.Write("@istr tag,pointsource,location1,location3,location4,zero,span,instrumenttag,compdev\n");
                foreach (var tagname in tagnames)
                {
                    pts_writer.Write($"{PIAPI.TagToPoint(tagname)},FTLD,1,1,1,0.,100.,{tagname},0.2\n");
                }
            }
            Console.WriteLine("created {0} point definitions", tagnames.Count);
        }
Esempio n. 2
0
        public static void MakeFTH(DatReader dr, string floatfile_name, StreamWriter outwriter, List <string> all_tagnames)
        {
            Dictionary <int, string> pointnames = new Dictionary <int, string>();

            foreach (DatTagRecord tag in dr.ReadTagFile(floatfile_name))
            {
                pointnames[tag.id] = PIAPI.TagToPoint(tag.name);
                if (!all_tagnames.Contains(tag.name))
                {
                    all_tagnames.Add(tag.name);
                }
            }

            int         batch_count = 0;
            string      batch       = "";
            CultureInfo culture     = new CultureInfo("en-US");

            foreach (DatFloatRecord val in dr.ReadFloatFile(floatfile_name))
            {
                if (val.status != 'U')
                {
                    batch += $"{pointnames[val.tagid]},{val.datetime.ToString("dd-MMM-yy HH:mm:ss.fff", culture)},{val.val}\n";
                    batch_count++;
                }
                if (batch_count == Globals.BATCH_SIZE)
                {
                    outwriter.Write(batch); // async?
                    batch_count = 0;
                    batch       = "";
                }
            }
            if (batch_count > 0)
            {
                outwriter.Write(batch);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Error: argument not found");
                Console.WriteLine("Usage: dat2fth ServerName PointPrefix [Path]");
                return;
            }
            PIAPI.Connect(args[0]);
            PIAPI.POINT_PREFIX = args[1];

            string path = ".";

            if (args.Length >= 3)
            {
                path = args[2];
            }

            // TODO: expose this for easy filtering
            List <string> allowed_tagnames = new List <string>();
            //allowed_tagnames.Add("AI\\FY59_1");

            DatReader dr = new DatReader(path);

            foreach (string floatfile_name in dr.GetFloatfiles())
            {
                Console.WriteLine("converting {0}", Path.GetFileName(floatfile_name));
                Dictionary <int, int> pointids = new Dictionary <int, int>();
                foreach (DatTagRecord tag in dr.ReadTagFile(floatfile_name))
                {
                    if (allowed_tagnames.Count > 0 && !allowed_tagnames.Contains(tag.name))
                    {
                        continue;
                    }

                    string pointname = PIAPI.TagToPoint(tag.name);
                    pointids[tag.id] = PIAPI.GetPointNumber(pointname);
                }

                int           batch_count = 0;
                Int32[]       ptids       = new Int32[Globals.BATCH_SIZE];
                double[]      vs          = new double[Globals.BATCH_SIZE];
                PITIMESTAMP[] ts          = new PITIMESTAMP[Globals.BATCH_SIZE];

                // can use intermediate storage, more readable but less speed
                // List<FloatSnapshot> snaps = new List<FloatSnapshot>();

                foreach (DatFloatRecord val in dr.ReadFloatFile(floatfile_name))
                {
                    if (!pointids.ContainsKey(val.tagid))
                    {
                        continue;
                    }
                    Int32 ptid = pointids[val.tagid];
                    ptids[batch_count] = ptid;
                    vs[batch_count]    = val.val;
                    ts[batch_count]    = new PITIMESTAMP(val.datetime);
                    batch_count++;

                    if (batch_count == Globals.BATCH_SIZE)
                    {
                        PIAPI.PutSnapshots(batch_count, ptids, vs, ts);
                        batch_count = 0;
                    }
                }
                if (batch_count > 0)
                {
                    PIAPI.PutSnapshots(batch_count, ptids, vs, ts);
                }
            }
        }