Ejemplo n.º 1
0
        public void rd_para()                           //duqu 参数号内的值,已测试
        {
            short number = Convert.ToInt16(txt_para.Text);
            short ret    = Fanuc.cnc_rdparam(Fanuc.h, number, Fanuc.ALL_AXES, 4 + 4 * Fanuc.MAX_AXIS, psd_1);

            if (ret == Fanuc.EW_OK)
            {
                listBox1.Items.Add(psd_1.cdata.ToString());
                listBox1.Items.Add(psd_1.type.ToString());
                listBox1.Items.Add(psd_1.datano.ToString());
                MessageBox.Show("读取参数成功");
            }
            else
            {
                if (ret == 3)
                {
                    MessageBox.Show("机器中的参数可能未设置或没有,请从填");
                }
                else
                {
                    MessageBox.Show(ret + "  ");
                }
            }
        }
Ejemplo n.º 2
0
        public void cnc_wrpm_item() //写入维修的状态项目
        {
            short b    = 1;         //数量
            short type = 1;

            if (a > 10)
            {
                MessageBox.Show("存储已满,你所输入的值将会代替第一个");
                a = 1;
            }
            else
            {
                if (textBox3.Text == null)
                {
                    MessageBox.Show("没有输入项目");
                }
                else
                {
                    string      na   = textBox3.Text;
                    string      str1 = "data" + a.ToString();
                    var         p    = inte.GetType();
                    object      obj  = p.GetField(str1).GetValue(inte);
                    System.Type ob   = obj.GetType();

                    var data = ob.GetRuntimeField("name");//读取类中的类里面的字段
                    data.SetValue(obj, na);
                    //MessageBox.Show(inte.data1.name);
                    short ret = Fanuc.cnc_wrpm_item(Fanuc.h, a, type, b, inte);
                    if (ret == 0)
                    {
                        MessageBox.Show("输入成功");
                        a++;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void get_mente_special()//读取维修的机床项目
        {
            listBox5.Items.Clear();
            short  a    = 1;                                              //说明开始读取的序列号
            short  b    = 11;                                             //表示读取的维修项目的数量
            short  ret  = Fanuc.cnc_rdpm_mcnitem(Fanuc.h, a, ref b, tem); //ref b,返回的是机器里实际读取的数量
            string str2 = "name";

            System.Type type = tem.GetType();


            if (ret == 0)
            {
                for (int i = 1; i < b; i++)
                {
                    str2 = "name" + i;
                    listBox5.Items.Add(i + "    :" + type.GetField(str2).GetValue(tem).ToString());
                }
            }
            else
            {
                MessageBox.Show(ret + " ");
            }
        }
Ejemplo n.º 4
0
        Fanuc.ODBDY2_1 c = new Focas1.ODBDY2_1(); //动态信息显示
        public void dynatic()                     //读取动态的数据的函数
        {
            short ret = Fanuc.cnc_rddynamic2(Fanuc.h, 2, 28 + 4 * 4 * 1, c);

            if (ret == 0)
            {
                listBox4.Items.Add("进给速率" + c.actf);
                listBox4.Items.Add("主轴速率" + c.acts);
                listBox4.Items.Add("警报" + c.alarm);
                listBox4.Items.Add("轴的数量" + c.axis);
                listBox4.Items.Add("可能用" + c.dummy);
                listBox4.Items.Add("绝对 位置:" + c.pos.absolute[0] + c.pos.absolute[1]);
                listBox4.Items.Add("相对 位置:" + c.pos.relative[0] + c.pos.relative[1]);
                listBox4.Items.Add("机器 位置:" + c.pos.machine[0] + c.pos.machine[1]);
                listBox4.Items.Add("剩余 位置:" + c.pos.distance[0] + c.pos.distance[1]);
                listBox4.Items.Add("当前的程序" + c.prgmnum);
                listBox4.Items.Add("主要的程序:" + c.prgmnum);
                listBox4.Items.Add("顺序号:" + c.seqnum);
            }
            else
            {
                MessageBox.Show(ret + " ");
            }
        }//动态数据
Ejemplo n.º 5
0
        //读注册程序
        private void button8_Click(object sender, EventArgs e)
        {
            Fanuc.PRGDIR3 prgdir3 = new Focas1.PRGDIR3();
            short         a = 2, c = 100;//a:输出type b:指针开始位置 c:程序的总数量
            int           b   = Convert.ToInt16(textBox1.Text);
            short         ret = Fanuc.cnc_rdprogdir3(Fanuc.h, a, ref b, ref c, prgdir3);

            //dir1包含的数据number编号 length程序大小 comment注释
            if (ret == Fanuc.EW_OK)
            {
                string sprgdir3       = "dir";
                string sprgdir3_data  = "number";
                string sprgdir3_data2 = "length";
                string sprgdir3_data3 = "comment";
                string sprgdir3_data4 = "mdate";
                string sprgdir3_data5 = "year";
                string sprgdir3_data6 = "month";
                string sprgdir3_data7 = "day";
                string sprgdir3_data8 = "hour";
                string sprgdir3_data9 = "minute";

                if (ret == Fanuc.EW_OK)
                {
                    //处理显示的数据
                    listcnc_rdprogdir2.Items.Clear();
                    listcnc_rdprogdir2.Items.Add("合计:" + c);
                    listcnc_rdprogdir2.Items.Add("程序号(个)|大小(Kbyte)|时间            |注释()");
                    System.Type type = prgdir3.GetType();                 //|2016/5/25 24:24
                    for (int j = 1; j < c + 1; j++)
                    {
                        sprgdir3 = "dir" + j;
                        FieldInfo   fieidinfo = type.GetField(sprgdir3);
                        object      ob        = fieidinfo.GetValue(prgdir3);
                        System.Type typeob    = ob.GetType();

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

                        double temp = Convert.ToDouble(typeob.GetField(sprgdir3_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, ' ');

                        object      ob1    = typeob.GetField(sprgdir3_data4).GetValue(ob);
                        System.Type tyob1  = ob1.GetType();
                        string      year   = tyob1.GetField(sprgdir3_data5).GetValue(ob1).ToString().PadLeft(4, '0');
                        string      month  = tyob1.GetField(sprgdir3_data6).GetValue(ob1).ToString().PadLeft(2, '0');
                        string      day    = tyob1.GetField(sprgdir3_data7).GetValue(ob1).ToString().PadLeft(2, '0');
                        string      hour   = tyob1.GetField(sprgdir3_data8).GetValue(ob1).ToString().PadLeft(2, '0');
                        string      minute = tyob1.GetField(sprgdir3_data9).GetValue(ob1).ToString().PadLeft(2, '0');
                        string      nctime = year + "/" + month + "/" + day + " " + hour + ":" + minute;

                        string ncComment = typeob.GetField(sprgdir3_data3).GetValue(ob).ToString();

                        string all = ncNumber + "|" + ncLength + "|" + nctime + "|" + ncComment;
                        listcnc_rdprogdir2.Items.Add(all);
                    }
                }
            }
        }
Ejemplo n.º 6
0
 //獲取詳細的錯誤信息
 private static short getdtailerr(ushort handle, Fanuc.ODBERR odberr)
 {
     return(Fanuc.cnc_getdtailerr(handle, odberr));
 }
Ejemplo n.º 7
0
 //下載
 private static short dwnload(ushort handle, ref int datalength, string data)
 {
     //開始下載程序  datalength將會被返回,實際的輸出的字符數量
     return(Fanuc.cnc_download3(handle, ref datalength, data));
 }
Ejemplo n.º 8
0
 //結束
 private static short dwnend(ushort handle)
 {
     return(Fanuc.cnc_dwnend3(handle));
 }
Ejemplo n.º 9
0
 //下載程序  5-27
 //開始
 private static short dwnstart(ushort handle, short type)
 {
     return(Fanuc.cnc_dwnstart3(handle, type));
 }
Ejemplo n.º 10
0
 public void set_timer()//设置时间
 {
     Fanuc.cnc_settimer(Fanuc.h, timer);
 }
Ejemplo n.º 11
0
 public void rd_sys_info()//读取cnc系统内的信息,比如轴数dengdeng
 {
     Fanuc.cnc_sysinfo(Fanuc.h, sys);
     toolStripStatusLabel1.Text = "主轴数:  " + sys.axes[0].ToString();
     toolStripStatusLabel2.Text = "被控制的伺服轴数;    " + sys.axes[1].ToString();
 }
Ejemplo n.º 12
0
 //下载
 private static short dwnload(ushort handle, ref int datalength, string data)
 {
     //开始下载程序  datalength将会被返回,实际的输出的字符数量
     return(Fanuc.cnc_download3(handle, ref datalength, data));
 }
Ejemplo n.º 13
0
 private void menu_FormClosing(object sender, FormClosingEventArgs e)
 {
     int ret = Fanuc.cnc_freelibhndl(Fanuc.h);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// 读取指定pmc地址的内容
        /// </summary>
        /// <param name="address"></param>
        public void ReadPmc(string address)
        {
            try
            {
                string addressKindStr = address.Substring(0, 1);
                int    addressKindInt = 0;
                int    addressNo      = int.Parse(address.Substring(1, 4).TrimStart('0') == "" ? "0" : address.Substring(1, 4).TrimStart('0'));
                for (int i = 0; i < pmcAddress.Keys.Count; i++)
                {
                    if (pmcAddress[i].ToString() == addressKindStr)
                    {
                        addressKindInt = i;
                        break;
                    }
                }
                short  a     = Convert.ToInt16(addressKindInt);
                short  b     = 0;
                ushort start = Convert.ToUInt16(addressNo);
                ushort end   = Convert.ToUInt16(addressNo + 1);
                ushort f     = 0;
                ushort N     = (ushort)(end - start + 1);
                switch (b)
                {
                case 0:
                    f = (ushort)(8 + N);
                    break;

                case 1:
                    f = (ushort)(8 + N * 2);
                    break;

                case 2:
                    f = (ushort)(8 + N * 4);
                    break;
                }
                Fanuc.IODBPMC0 iodbpmc0 = new Focas1.IODBPMC0();
                int            ret      = Fanuc.pmc_rdpmcrng(Fanuc.h, a, b, start, end, f, iodbpmc0);
                if (ret == Fanuc.EW_OK)
                {
                    byte[] data = iodbpmc0.cdata;
                    int    j    = 0;
                    for (ushort i = start; i < end; i++, j++)
                    {
                        string add   = Fanuc.getpmcadd(iodbpmc0.type_a, i);
                        int    value = Convert.ToInt32(Convert.ToString(data[j], 16).ToString());
                        string temp  = Convert.ToString(value, 2).PadLeft(8, '0');
                        char[] chars = temp.ToCharArray();

                        textBox9.Text = chars[7].ToString();
                        textBox8.Text = chars[6].ToString();
                        textBox7.Text = chars[5].ToString();
                        textBox6.Text = chars[4].ToString();
                        textBox5.Text = chars[3].ToString();
                        textBox4.Text = chars[2].ToString();
                        textBox3.Text = chars[1].ToString();
                        textBox2.Text = chars[0].ToString();
                    }
                }
                else
                {
                    MessageBox.Show(ret + "");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("输入的地址错误,详细:" + e.ToString());
            }
        }