Example #1
0
        /// <summary>
        /// 循环获取所需HNC状态信息
        /// </summary>
        public static void hnc_con()
        {
            if (!iscon)
            {
                return;
            }

            // 循环获取HNC状态信息
            Api.HNC_ChannelGetValue(5, 0, 0, ref gsymbol);         // G代码代号
            Api.HNC_FprogGetFullName(0, ref progNp);               // G代码名称
            if (progNp == null)
            //if ((progNp == null)&&(start_transfer))
            {
                //MessageBox.Show("提示:请加载G代码");
                return;
            }

            if (progNp[0] == '/')
            {
                progN = progNp.Remove(0, 13);
            }
            else
            {
                progN = progNp.Remove(0, 8);
            }
            if (progN1 != progN)
            {
                progN1       = progN;
                progch_event = true;
                //String temp_r = "mnt/hgfs/hnc/share/HNC8_V1.26.04" + progN;
                String temp_r = "/h/lnc8/prog/" + progN;
                String temp_l = gcode_path + progN;
                int    retr   = getfile(temp_r, temp_l);
                if (retr != 0)
                {
                    MessageBox.Show("G代码下载失败,错误码:" + retr.ToString());
                }
                else
                {
                    load_event = true;
                }
            }
            Api.HNC_AxisGetValue(6, 0, ref pos_X);                 // X位置
            Api.HNC_AxisGetValue(6, 1, ref pos_Y);                 // Y位置
            Api.HNC_AxisGetValue(6, 2, ref pos_Z);                 // Z位置
            Api.HNC_ChannelGetValue(18, 0, 0, ref cyc);            // 循环启动
            Api.HNC_ChannelGetValue(32, 0, 0, ref gline);          // G代码行号
            Api.HNC_ChannelGetValue(47, 0, 0, ref speed_S);        // 主轴转速
            Api.HNC_ChannelGetValue(6, 0, 0, ref speed_F);         // 进给速度

            // 循环启动变化触发事件
            if (cyc_ch != cyc)
            {
                cyc_ch    = cyc;
                cyc_event = true;
            }
        }
Example #2
0
        public Int32 HNC_FprogGetFullName(Int32 ch, ref String progName)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HNCFPROGMAN.PROG_PATH_SIZE);

            ret      = HncApi.HNC_FprogGetFullName(ch, ptr, _ClientNo);
            progName = Marshal.PtrToStringAnsi(ptr);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Example #3
0
        /// <summary>
        /// 循环获取所需HNC状态信息
        /// </summary>
        public static void hnc_con()
        {
            List <List <Int32> > m_listData = new List <List <int> >();
            //List<Int32>[] tmp = new List<Int32>[32];
            long freq = 0;

            if (QueryPerformanceFrequency(ref freq) == false)
            {
                throw new Exception("不支持高精度计时.");
            }
            double count_per_millsec = freq / 1000.0;
            long   start_time = 0, stop_time = 0;
            long   now_time = 0;

            QueryPerformanceCounter(ref start_time);
            while (true)
            {
                QueryPerformanceCounter(ref now_time);
                while (now_time - start_time < 200 * count_per_millsec)
                {
                    QueryPerformanceCounter(ref now_time);
                }
                Console.WriteLine("等待时间" + ((now_time - start_time) / count_per_millsec).ToString());
                start_time = now_time;

                List <List <Int32> > m_datatemp = new List <List <int> >();

                if (issmpl)
                {
                    //List<List<Int32>> m_datatemp = new List<List<int>>();

                    // 获取数据
                    int ret = Api.HNC_SamplGetData(m_datatemp);
                }

                //getdata.WaitOne();

                if (!iscon)
                {
                    //getdata.ReleaseMutex();
                    QueryPerformanceCounter(ref stop_time);
                    continue;
                }

                //List<List<Int32>> m_datatemp = new List<List<int>>();

                //// 获取数据
                //int ret = Api.HNC_SamplGetData(m_datatemp);

                // 循环获取HNC状态信息
                Api.HNC_FprogGetFullName(0, ref progNp);               // G代码名称
                if (progNp == null)
                {
                    QueryPerformanceCounter(ref stop_time);
                    continue;
                }
                //Console.WriteLine("运行测试2");
                if (progNp[0] == '/')
                {
                    progN = progNp.Remove(0, 13);
                }
                else
                {
                    progN = progNp.Remove(0, 8);
                }
                if (progN1 != progN)
                {
                    progN1 = progN;
                    //progch_event = true;
                    //String temp_r = "mnt/hgfs/hnc/share/HNC8_V1.26.04" + progN;
                    String temp_r = "/h/lnc8/prog/" + progN;
                    temp_l = gcode_path + progN;
                    int retr = getfile(temp_r, temp_l);
                    //int retr = 0;
                    if (retr != 0)
                    {
                        MessageBox.Show("G代码下载失败,错误码:" + retr.ToString());
                    }
                    else
                    {
                        load_event = true;
                    }
                    progch_event = true;
                    gcodeupload();
                }

                //Api.HNC_ChannelGetValue(18, 6, 0, ref cyc);            // 循环启动
                //Api.HNC_ChannelGetValue(32, 7, 0, ref gline);          // G代码行号
                //Api.HNC_ChannelGetValue(47, 8, 0, ref speed_S);        // 主轴转速
                //Api.HNC_ChannelGetValue(6, 9, 0, ref speed_F);         // 进给速度
                //Api.HNC_ChannelGetValue(9, 10, 0, ref F_OVERRIDE);      // 进给修调
                //Api.HNC_ChannelGetValue(49, 11, 0, ref S_OVERRIDE);     // 主轴修调

                Api.HNC_AxisGetValue((Int32)HncAxis.HNC_AXIS_DRIVE_CUR, 0, ref drive_cur);

                Api.HNC_ChannelGetValue(18, 0, 0, ref cyc);            // 循环启动
                Api.HNC_ChannelGetValue(32, 0, 0, ref gline);          // G代码行号
                Api.HNC_ChannelGetValue(47, 0, 0, ref speed_S);        // 主轴转速
                Api.HNC_ChannelGetValue(6, 0, 0, ref speed_F);         // 进给速度
                Api.HNC_ChannelGetValue(9, 0, 0, ref F_OVERRIDE);      // 进给修调
                Api.HNC_ChannelGetValue(49, 0, 0, ref S_OVERRIDE);     // 主轴修调
                Api.HNC_ChannelGetValue(50, 0, 0, ref R_OVERRIDE);     // 快移调修
                Api.HNC_ChannelGetValue(25, 0, 0, ref estop);          // 急停
                //Api.HNC_AxisGetValue((Int32)HncAxis.HNC_AXIS_DRIVE_CUR, 5, ref drive_cur);

                #region 接口数据转换

                List <byte> lsdata = new List <byte>();

                byte[] cyc1 = BitConverter.GetBytes(cyc);
                lsdata.AddRange(cyc1);

                byte[] gline1 = BitConverter.GetBytes(gline);
                lsdata.AddRange(gline1);

                byte[] speed_S1 = BitConverter.GetBytes(speed_S);
                lsdata.AddRange(speed_S1);

                byte[] speed_F1 = BitConverter.GetBytes(speed_F);
                lsdata.AddRange(speed_F1);

                byte[] F_OVERRIDE1 = BitConverter.GetBytes(S_OVERRIDE);
                lsdata.AddRange(F_OVERRIDE1);

                byte[] S_OVERRIDE1 = BitConverter.GetBytes(F_OVERRIDE);
                lsdata.AddRange(S_OVERRIDE1);

                byte[] R_OVERRIDE1 = BitConverter.GetBytes(R_OVERRIDE);
                lsdata.AddRange(R_OVERRIDE1);

                byte[] E_STOP = BitConverter.GetBytes(estop);
                lsdata.AddRange(E_STOP);

                byte[] DRIVE_CUR = BitConverter.GetBytes(drive_cur);
                lsdata.AddRange(DRIVE_CUR);

                #endregion

                // 循环启动变化触发事件
                if (cyc_ch != cyc)
                {
                    cyc_ch    = cyc;
                    cyc_event = true;
                }

                getdata.WaitOne();

                // 采样是否打开
                if (!issmpl)
                {
                    getdata.ReleaseMutex();
                    QueryPerformanceCounter(ref stop_time);
                    continue;
                }


                try
                {
                    m_listData.Clear();
                }
                catch (Exception ex)
                {
                    //Ignore
                }

                //List<List<Int32>> m_datatemp = new List<List<int>>();

                //// 获取数据
                //int ret = Api.HNC_SamplGetData(m_datatemp);
                //Console.WriteLine("运行测试2:");
                if ((m_datatemp == null) || (m_datatemp.Count == 0))
                {
                    //Console.WriteLine("运行测试3:未得到数据");
                    QueryPerformanceCounter(ref stop_time);
                    getdata.ReleaseMutex();
                    continue;
                }
                //Console.WriteLine("运行测试3:已得到数据");
                m_listData = m_datatemp;

                int chnum = m_datatemp.Count;


                List <Int32>[] tmp = m_listData.ToArray();

                int[] series_X = tmp[0].ToArray();
                int[] series_Y = tmp[1].ToArray();
                int[] series_Z = tmp[2].ToArray();
                int[] series_C = tmp[3].ToArray();
                int[] series_I = tmp[4].ToArray();

                int dag1 = series_X.Length / 4;

                //for()
                temp2[0] = new List <byte>();
                temp2[1] = new List <byte>();
                temp2[2] = new List <byte>();
                temp2[3] = new List <byte>();

                for (int m1 = 0; m1 < 4; m1++)
                {
                    object obj_X = (object)series_X[(m1 + 1) * dag1 - 1];
                    object obj_Y = (object)series_Y[(m1 + 1) * dag1 - 1];
                    object obj_Z = (object)series_Z[(m1 + 1) * dag1 - 1];
                    object obj_C = (object)series_C[(m1 + 1) * dag1 - 1];

                    pos_X = x[m1] = Convert.ToSingle(obj_X) / 100000;
                    pos_Y = y[m1] = Convert.ToSingle(obj_Y) / 100000;
                    pos_Z = z[m1] = Convert.ToSingle(obj_Z) / 100000;
                    pos_C = c[m1] = Convert.ToSingle(obj_C) / 100000;

                    //temp2[m1].AddRange(lsdata);
                    byte[] a = BitConverter.GetBytes(x[m1]);
                    temp2[m1].AddRange(a);
                    a = BitConverter.GetBytes(y[m1]);
                    temp2[m1].AddRange(a);
                    a = BitConverter.GetBytes(z[m1]);
                    temp2[m1].AddRange(a);
                    a = BitConverter.GetBytes(c[m1]);
                    temp2[m1].AddRange(a);
                    temp2[m1].AddRange(lsdata);
                }

                axisi = series_I;

                int dataplist = tmp[0].Count;

                int listc = series_X.Length;

                #region i,v,s等数据转换

                int comp = listc / 4;

                //List<byte>[] i_byte = new List<byte>[4];
                //Queue<Int32> i_que = new Queue<Int32>();

                if (i_que.Count > 1000)
                {
                    i_que.Clear();
                }
                if (v_que.Count > 10000)
                {
                    v_que.Clear();
                }
                if (s_que.Count > 10000)
                {
                    s_que.Clear();
                }

                for (int l = 0; l < series_I.Length; l++)
                {
                    i_que.Enqueue(series_I[l]);
                }

                //for (int l = 0; l < series_I.Length; l++)
                //{
                //    if (l > comp * 3)
                //    {
                //        byte[] a = BitConverter.GetBytes(series_I[l]);
                //        //i_byte[3].Enqueue()
                //        i_byte[3].AddRange(a);
                //    }
                //    else if (l > comp * 2)
                //    {
                //        byte[] a = BitConverter.GetBytes(series_I[l]);
                //        i_byte[2].AddRange(a);
                //    }
                //    else if (l > comp)
                //    {
                //        byte[] a = BitConverter.GetBytes(series_I[l]);
                //        i_byte[1].AddRange(a);
                //    }
                //    else
                //    {
                //        byte[] a = BitConverter.GetBytes(series_I[l]);
                //        i_byte[0].AddRange(a);
                //    }
                //}

                //int comp = listc / 4;

                //List<byte>[] v_byte = new List<byte>[4];

                //Queue<Int16> v_que = new Queue<Int16>();

                for (int m = 0; m < v_len / 4; m++)
                {
                    tmp[m + 5].Reverse();
                }

                for (int j = 0; j < listc; j++)
                {
                    for (int m = 0; m < v_len / 4; m++)
                    {
                        int temp   = tmp[m + 5].Last <Int32>();
                        int temp_2 = tmp[m + 5].Last <Int32>();
                        tmp[m + 5].RemoveAt(tmp[m + 5].Count - 1);

                        Int16 hdata = (Int16)(temp >> 16);
                        Int16 ldata = (Int16)((temp_2 << 16) >> 16);

                        //v_que.Enqueue(ldata);
                        //v_que.Enqueue(hdata);
                        v_que.Enqueue(hdata);
                        v_que.Enqueue(ldata);
                    }
                }

                //for (int j = 0; j < listc; j++)
                //{
                //    for (int m = 0; m < v_len / 4; m++)
                //    {
                //        int temp = tmp[m + 5].Last<Int32>();
                //        tmp[m + 5].RemoveAt(tmp[m + 5].Count-1);

                //        Int16 hdata = (Int16)(temp >> 16);
                //        Int16 ldata = (Int16)((temp << 16) >> 16);

                //        value_v1.Add(hdata);
                //        value_v1.Add(ldata);

                //        if (j > comp*3)
                //        {
                //            byte[] a = BitConverter.GetBytes(hdata);
                //            v_byte[3].AddRange(a);
                //            byte[] b = BitConverter.GetBytes(ldata);
                //            v_byte[3].AddRange(b);
                //        }
                //        else if(j>comp*2)
                //        {
                //            byte[] a = BitConverter.GetBytes(hdata);
                //            v_byte[2].AddRange(a);
                //            byte[] b = BitConverter.GetBytes(ldata);
                //            v_byte[2].AddRange(b);
                //        }
                //        else if(j>comp)
                //        {
                //            byte[] a = BitConverter.GetBytes(hdata);
                //            v_byte[1].AddRange(a);
                //            byte[] b = BitConverter.GetBytes(ldata);
                //            v_byte[1].AddRange(b);
                //        }
                //        else
                //        {
                //            byte[] a = BitConverter.GetBytes(hdata);
                //            v_byte[0].AddRange(a);
                //            byte[] b = BitConverter.GetBytes(ldata);
                //            v_byte[0].AddRange(b);
                //        }
                //    }
                //}

                //List<byte>[] s_byte = new List<byte>[4];

                //Queue<Int16> s_que = new Queue<short>();

                for (int m = 0; m < v_len / 4; m++)
                {
                    tmp[m + 15].Reverse();
                }

                for (int j = 0; j < listc; j++)
                {
                    for (int m = 0; m < s_len / 4; m++)
                    {
                        int temp = tmp[m + 15].Last <Int32>();
                        tmp[m + 15].RemoveAt(tmp[m + 15].Count - 1);

                        Int16 hdata = (Int16)(temp >> 16);
                        Int16 ldata = (Int16)((temp << 16) >> 16);

                        s_que.Enqueue(hdata);
                        s_que.Enqueue(ldata);
                    }
                }

                //int a2 = v_que.Count;

                //if (i_que.Count > 1000)
                //    i_que.Clear();
                //if (v_que.Count > 10000)
                //    v_que.Clear();
                //if (s_que.Count > 10000)
                //    s_que.Clear();
                //for (int j = 0; j < listc; j++)
                //{
                //    for (int m = 0; m < s_len / 4; m++)
                //    {
                //        int temp = tmp[m + 15].Last<Int32>();
                //        tmp[m + 15].RemoveAt(tmp[m + 15].Count-1);

                //        Int16 hdata = (Int16)(temp >> 16);
                //        Int16 ldata = (Int16)((temp << 16) >> 16);

                //        value_s1.Add(hdata);
                //        value_s1.Add(ldata);

                //        if (j > comp * 3)
                //        {
                //            byte[] a = BitConverter.GetBytes(hdata);
                //            s_byte[3].AddRange(a);
                //            byte[] b = BitConverter.GetBytes(ldata);
                //            s_byte[3].AddRange(b);
                //        }
                //        else if (j > comp * 2)
                //        {
                //            byte[] a = BitConverter.GetBytes(hdata);
                //            s_byte[2].AddRange(a);
                //            byte[] b = BitConverter.GetBytes(ldata);
                //            s_byte[2].AddRange(b);
                //        }
                //        else if (j > comp)
                //        {
                //            byte[] a = BitConverter.GetBytes(hdata);
                //            s_byte[1].AddRange(a);
                //            byte[] b = BitConverter.GetBytes(ldata);
                //            s_byte[1].AddRange(b);
                //        }
                //        else
                //        {
                //            byte[] a = BitConverter.GetBytes(hdata);
                //            s_byte[0].AddRange(a);
                //            byte[] b = BitConverter.GetBytes(ldata);
                //            s_byte[0].AddRange(b);
                //        }
                //    }
                //}

                //value_v = value_v1.ToArray();
                //value_s = value_s1.ToArray();

                #endregion

                //byte[] div = { 0x01, 0x02, 0x03, 0x04 };


                //for(int ki=0;ki<4;ki++)
                //{
                //    datatemp[ki].AddRange(temp2[ki]);
                //    datatemp[ki].AddRange(lsdata);
                //    datatemp[ki].AddRange(div);
                //    datatemp[ki].AddRange(i_byte[ki]);
                //    datatemp[ki].AddRange(v_byte[ki]);
                //    datatemp[ki].AddRange(s_byte[ki]);
                //}
                //datatemp.AddRange(lsdata);
                //datatemp.AddRange(x_byte);
                //datatemp.AddRange(y_byte);
                //datatemp.AddRange(z_byte);
                //datatemp.AddRange(c_byte);
                //datatemp.AddRange(i_byte);
                //datatemp.AddRange(v_byte);
                //datatemp.AddRange(s_byte);

                //byte[] datasend = datatemp.ToArray();

                //Upload.socketsend(datasend);

                lsdata.Clear();
                //x_byte.Clear();
                //y_byte.Clear();
                //z_byte.Clear();
                //c_byte.Clear();
                //i_byte.Clear();
                //v_byte.Clear();
                //s_byte.Clear();
                //datatemp.Clear();

                //value_v = value_v1.ToArray();
                //value_s = value_s1.ToArray();

                //if (!(value_v.Length < 10))
                //{
                dataready = true;
                //}

                getdata.ReleaseMutex();

                QueryPerformanceCounter(ref stop_time);

                //Console.WriteLine("通道数目" + chnum.ToString());
                //Console.WriteLine("数据长度" + dataplist.ToString());
                //Console.WriteLine("使用时间 " + ((stop_time - start_time) / count_per_millsec).ToString());
            }
        }