Beispiel #1
0
        /// <summary>
        /// 读取NC目录
        /// </summary>
        public Focas1.PRGDIR2 getNCDir(string _top_prog, string _num_prog, ushort Flibhndl)
        {
            short type     = 2;
            short top_prog = short.Parse(_top_prog);
            short num_prog = short.Parse(_num_prog);

            Focas1.PRGDIR2 buf = new Focas1.PRGDIR2();
            Focas1.cnc_rdprogdir2(Flibhndl, type, ref top_prog, ref num_prog, buf);
            return(buf);
        }
Beispiel #2
0
        //TODO 读取注册程序目录
        public void rdProDir()
        {
            Fanuc.PRGDIR2 prgdir2 = new Focas1.PRGDIR2();
            //a:输出type     Specify the type of the program directory to read.
            //0  :  "Program number" only
            //1  :  "Program number" and "Comment"
            //2  :  "Program number", "Comment" and "Program size"
            short a = 2, b = Convert.ToInt16(textBox1.Text), c = 10;// b:指针开始位置 c:程序的总数量
            short ret = Fanuc.cnc_rdprogdir2(Fanuc.h, a, ref b, ref c, prgdir2);

            //dir1包含的数据number编号 length程序大小 comment注释
            if (ret == Fanuc.EW_OK)
            {
                string sprgdir2       = "dir";
                string sprgdir2_data  = "number";
                string sprgdir2_data2 = "length";
                string sprgdir2_data3 = "comment";
                if (ret == Fanuc.EW_OK)
                {
                    //处理显示的数据
                    listcnc_rdprogdir2.Items.Clear();
                    listcnc_rdprogdir2.Items.Add("合计:" + c);
                    listcnc_rdprogdir2.Items.Add("程序号(个)|大小(Kbyte)|注释()");
                    System.Type type = prgdir2.GetType();
                    for (int j = 1; j < c + 1; j++)
                    {
                        sprgdir2 = "dir" + j;
                        FieldInfo   fieidinfo = type.GetField(sprgdir2);
                        object      ob        = fieidinfo.GetValue(prgdir2);
                        System.Type typeob    = ob.GetType();

                        string ncNumber = typeob.GetField(sprgdir2_data).GetValue(ob).ToString().PadLeft(4, '0');
                        ncNumber = ncNumber.PadRight(12, ' ');

                        double temp = Convert.ToDouble(typeob.GetField(sprgdir2_data2).GetValue(ob).ToString());
                        temp = temp / 1024.0 + 0.5;
                        if (temp < 1)
                        {
                            temp += 0.5;
                        }

                        string ncLength = ((int)temp).ToString();
                        ncLength = ncLength.PadRight(13, ' ');
                        string ncComment = typeob.GetField(sprgdir2_data3).GetValue(ob).ToString();
                        string all       = ncNumber + "|" + ncLength + "|" + ncComment;
                        listcnc_rdprogdir2.Items.Add(all);
                    }
                }
            }
        }