コード例 #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);
        }
コード例 #2
0
        public void Test_DatReader()
        {
            int       tag_count = 0;
            int       val_count = 0;
            DatReader dr        = new DatReader("../../InputData");

            foreach (string floatfile_name in dr.GetFloatfiles())
            {
                Console.Write($"{floatfile_name}\n");
                foreach (DatTagRecord tag in dr.ReadTagFile(floatfile_name))
                {
                    tag_count++;
                }
                foreach (DatFloatRecord val in dr.ReadFloatFile(floatfile_name))
                {
                    val_count++;
                }
            }
            Assert.AreEqual(tag_count, 32);
            Assert.AreEqual(val_count, 128);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            if (args.Length < 4)
            {
                Console.WriteLine("Error: argument not found");
                Console.WriteLine("Usage: dat2sql ServerName CatalogName User Password [TablePrefix]");
                return;
            }

            string FloatTable  = "FloatTable";
            string TagTable    = "TagTable";
            string StringTable = "StringTable";

            if (args.Length >= 5)
            {
                FloatTable  = $"{args[4]}_FloatTable";
                TagTable    = $"{args[4]}_TagTable";
                StringTable = $"{args[4]}_StringTable";
            }

            string connString = $"Data Source={args[0]};Initial Catalog={args[1]};Persist Security Info=True;User ID={args[2]};Password={args[3]}";

            SqlConnection conn = new SqlConnection(connString);

            conn.Open();
            CreateTables(conn, TagTable, FloatTable);

            DatReader dr        = new DatReader(".");
            uint      converted = 0;

            foreach (string infilename in dr.GetFloatfiles())
            {
                Console.WriteLine("converting {0}", infilename);
                MakeSQL(dr, infilename, conn, TagTable, FloatTable);
                converted++;
            }

            conn.Close();
            Console.WriteLine("converted {0} files", converted);
        }
コード例 #4
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);
                }
            }
        }