/// <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; } }
// 获取轴信息的变量类型 布尔型 public bool AxisInfoGotItems(UInt32 AxisMask, ref string[] AxisName, ref Int32[] AxisId, ref Int32[] axisValue, ref Double[] loadValue, ref Double[] cmdVel, ref Double[] actVel, Int16 clientNo) { bool flag = true; Int32 index = 0; Int32 ret = 0; // 引用变量 if (AxisMask == 0) { flag = false; return(flag); } for (Int32 i = 0; i < AxisTypesCount; i++) { if ((AxisMask >> i & 1) == 1) // 位与运算 i 与 1 都是 1 时 返回1 >> 右移 符号(转换为2进制向右移动第二个操作数的位数) { ret += HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_NAME, i, ref AxisName[index], clientNo); // 类型 轴号 轴值 网络号 // 轴名 AxisId[index] = i; ret += HncApi.HNC_AxisGetValue((Int32)HncAxis.HNC_AXIS_ACT_POS, AxisId[index], ref axisValue[index], ActiveClientNo); // 位置信息 是米度单位 ret += HncApi.HNC_AxisGetValue((Int32)HncAxis.HNC_AXIS_LOAD_CUR, AxisId[index], ref loadValue[index], ActiveClientNo); // 负载电流 ret += HncApi.HNC_AxisGetValue((Int32)HncAxis.HNC_AXIS_CMD_VEL, AxisId[index], ref cmdVel[index], ActiveClientNo); // 指令速度 是米度单位 ret += HncApi.HNC_AxisGetValue((Int32)HncAxis.HNC_AXIS_ACT_VEL, AxisId[index], ref actVel[index], ActiveClientNo); // 实际速度 是毫米每分钟 不用换算 index++; if (ret != 0) { flag = false; break; } } } return(flag); }
//public Int32 index = 0; //// 获取报警信息 //private void GetAlarmInfo(ref Int32 AlarmNum, ref Int32 AlarmNo, ref string[] errText, Int16 clientNo) //{ // Int32 alarmNum = 0; //报警数目 // Int32 alarmNo = 0; // 报警号 // Int32 ret = 0; // // 获取报警数目 // ret = HncApi.HNC_AlarmGetNum((Int32)AlarmType.ALARM_TYPE_ALL, (Int32)AlarmLevel.ALARM_ERR, ref alarmNum, ActiveClientNo); // if (ret != 0) // { // for (int i = 0; i < alarmCount; i++) // { // string[] items = new string[4]; // items[0] = "No index"; // items[1] = "No AlarmNo"; // items[2] = "No ErrorText"; // items[3] = DateTime.Now.ToString(); // ListViewItem item = new ListViewItem(items); // this.AlarmlistView.Items.Add(item); // } // return; // } // // 获取报警类型 注意每一个报警对应的数据不同 // int index = 0; // for (int i = 0; i < alarmNum; i++) // { // ret = HncApi.HNC_AlarmGetData((Int32)AlarmType.ALARM_TYPE_ALL, (Int32)AlarmLevel.ALARM_ERR, i, ref alarmNo, ref errText, ActiveClientNo); // if (ret != 0) // { // // // } // index++; // } //} // 位移单位转换 private void GetAxisStrInfo(int count, Int32[] AxisId, Int32[] axisValue, ref string[] AxisValueInfo) { Int32 ret = 0; Int32 lax = 0; Int32 axistype = 0; Int32 metric = 0; Int32 unit = 100000; Int32 diameter = 0; for (int i = 0; i < count; i++) { ret = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_LAX, mch, AxisId[i], ref lax, ActiveClientNo); // 直半径处理 ret = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_DIAMETER, mch, 0, ref diameter, ActiveClientNo); if (0 == lax && 1 == diameter) { axisValue[i] *= 2; } ret = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_TYPE, lax, ref axistype, ActiveClientNo); if (axistype == 1)//直线轴 { ret = HncApi.HNC_SystemGetValue((int)HncSystem.HNC_SYS_MOVE_UNIT, ref unit, ActiveClientNo); ret = HncApi.HNC_SystemGetValue((int)HncSystem.HNC_SYS_METRIC_DISP, ref metric, ActiveClientNo); if (0 == metric) // 英制 { unit = (Int32)(unit * 25.4); } } else { ret = HncApi.HNC_SystemGetValue((int)HncSystem.HNC_SYS_TURN_UNIT, ref unit, ActiveClientNo); } if (Math.Abs(unit) - 0.00001 <= 0.0) //除零保护 { AxisValueInfo[i] = "0"; } else { AxisValueInfo[i] = ((double)axisValue[i] / unit).ToString("F4"); // 实际输出的轴的位置 单位换算 } if (axistype == 1) { if (0 == metric) // 英制 { AxisValueInfo[i] += " inch"; } else { AxisValueInfo[i] += " mm"; } } else { AxisValueInfo[i] += " D"; } } }
public Int32 HNC_AxisGetValue(Int32 type, Int32 ax, ref Double value) { Int32 ret = -1; IntPtr ptr = Marshal.AllocHGlobal(HncApi.doubleSize); ret = HncApi.HNC_AxisGetValue(type, ax, ptr, _ClientNo); value = (Double)Marshal.PtrToStructure(ptr, typeof(Double)); Marshal.FreeHGlobal(ptr); return(ret); }
public Int32 HNC_AxisGetValue(Int32 type, Int32 ax, ref Int32 value) { Int32 ret = -1; IntPtr ptr = Marshal.AllocHGlobal(HncApi.intSize); ret = HncApi.HNC_AxisGetValue(type, ax, ptr, _ClientNo); value = Marshal.ReadInt32(ptr); Marshal.FreeHGlobal(ptr); return(ret); }
public Int32 HNC_AxisGetValue(Int32 type, Int32 ax, ref String value) { Int32 ret = -1; IntPtr ptr = Marshal.AllocHGlobal(HNCAXIS.MOTOR_TYPE_LEN); ret = HncApi.HNC_AxisGetValue(type, ax, ptr, _ClientNo); value = Marshal.PtrToStringAnsi(ptr); Marshal.FreeHGlobal(ptr); return(ret); }
/// <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()); } }
private void NC_Status_Update() { double value64 = 0; int Move_unit = 0; int Turn_unit = 0; int ret32 = 0; int value = 0; UInt16 ret = HncApi.HNC_NetIsConnect(CGlbFunc.clientNo[clientnum]); if (ret == 0) { //ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_TYPE, Constants.AXIS_LOGIC_NUM_X, ref axisType, clientnum); //switch (axisType) //{ // case 1: // 直线轴 HncApi.HNC_SystemGetValue((int)HncSystem.HNC_SYS_MOVE_UNIT, ref Move_unit, CGlbFunc.clientNo[clientnum]); // break; //default: // 旋转轴 HncApi.HNC_SystemGetValue((int)HncSystem.HNC_SYS_TURN_UNIT, ref Turn_unit, CGlbFunc.clientNo[clientnum]); // break; //} ///* 电机转速 */ //ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_MOTOR_REV, Constants.AXIS_LOGIC_NUM_X, ref value64, clientnum); //if (ret32 == 0) //{ // Rev_X.Text = value64.ToString(); //} //ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_MOTOR_REV, Constants.AXIS_LOGIC_NUM_Y, ref value64, clientnum); //if (ret32 == 0) //{ // Rev_Y.Text = value64.ToString(); //} //ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_MOTOR_REV, Constants.AXIS_LOGIC_NUM_Z, ref value64, clientnum); //if (ret32 == 0) //{ // Rev_Z.Text = value64.ToString(); //} /* 电机跟踪误差 */ ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_FOLLOW_ERR, Constants.AXIS_LOGIC_NUM_X, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { value = value / Move_unit; Rev_X_err.Text = value.ToString("0.0000"); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_FOLLOW_ERR, Constants.AXIS_LOGIC_NUM_Y, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { value = value / Move_unit; Rev_Y_err.Text = value.ToString("0.0000"); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_FOLLOW_ERR, Constants.AXIS_LOGIC_NUM_Z, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { value = value / Move_unit; Rev_Z_err.Text = value.ToString("0.0000"); } //ret2 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_CMD_POS_RCS, int.Parse(axisnum.Text), ref value, clientnum); //if (ret2 == 0) //{ // pos = (double)value / unit; // Axis_position.Text += ("cmd_pos_rcs:" + pos.ToString() + System.Environment.NewLine); //} //ret2 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_CMD_POS_WCS, int.Parse(axisnum.Text), ref value, clientnum); //if (ret2 == 0) //{ // pos = (double)value / unit; // Axis_position.Text += ("cmd_pos_wcs:" + pos.ToString() + System.Environment.NewLine); //} //ret2 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_CMD_POS, int.Parse(axisnum.Text), ref value, clientnum); //if (ret2 == 0) //{ // pos = (double)value / unit; // Axis_type.Text = axisType.ToString(); // Axis_position.Text += ("pos:" + pos.ToString() + System.Environment.NewLine); //} /* ACT_POS相对实际位置 */ ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_ACT_POS_RCS, Constants.AXIS_LOGIC_NUM_X, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { value = value / Move_unit; Pos_Act_X.Text = value.ToString(); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_ACT_POS_RCS, Constants.AXIS_LOGIC_NUM_Y, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { value = value / Move_unit; Pos_Act_Y.Text = value.ToString(); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_ACT_POS_RCS, Constants.AXIS_LOGIC_NUM_Z, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { value = value / Move_unit; Pos_Act_Z.Text = value.ToString(); } /* CMD_POS相对指令位置 */ ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_CMD_POS_RCS, Constants.AXIS_LOGIC_NUM_X, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { value = value / Move_unit; Pos_Com_X.Text = value.ToString(); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_CMD_POS_RCS, Constants.AXIS_LOGIC_NUM_Y, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { value = value / Move_unit; Pos_Com_Y.Text = value.ToString(); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_CMD_POS_RCS, Constants.AXIS_LOGIC_NUM_Z, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { value = value / Move_unit; Pos_Com_Z.Text = value.ToString(); } /* Cur_Load负载电流 */ ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_LOAD_CUR, Constants.AXIS_LOGIC_NUM_X, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { Cur_Load_X.Text = value64.ToString(); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_LOAD_CUR, Constants.AXIS_LOGIC_NUM_Y, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { Cur_Load_Y.Text = value64.ToString(); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_LOAD_CUR, Constants.AXIS_LOGIC_NUM_Z, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { Cur_Load_Z.Text = value64.ToString(); } /* Cur_Rated额定负载电流 */ ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_RATED_CUR, Constants.AXIS_LOGIC_NUM_X, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { Cur_Rated_X.Text = value64.ToString(); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_RATED_CUR, Constants.AXIS_LOGIC_NUM_Y, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { Cur_Rated_Y.Text = value64.ToString(); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_RATED_CUR, Constants.AXIS_LOGIC_NUM_Z, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { Cur_Rated_Z.Text = value64.ToString(); } /* Speed_Act实际进给速度 */ ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_ACT_VEL, Constants.AXIS_LOGIC_NUM_X, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value64 = value64 / Move_unit * 1000 * 60; Speed_Act_X.Text = value64.ToString("0.00"); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_ACT_VEL, Constants.AXIS_LOGIC_NUM_Y, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value64 = value64 / Move_unit * 1000 * 60; Speed_Act_Y.Text = value64.ToString("0.00"); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_ACT_VEL, Constants.AXIS_LOGIC_NUM_Z, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value64 = value64 / Move_unit * 1000 * 60; Speed_Act_Z.Text = value64.ToString("0.00"); } /* Speed_Com指令进给速度 */ ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_CMD_VEL, Constants.AXIS_LOGIC_NUM_X, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { // value = value / Move_unit * 1000 * 60; Speed_Com_X.Text = value.ToString("0.00"); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_CMD_VEL, Constants.AXIS_LOGIC_NUM_Y, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value = value / Move_unit * 1000 * 60; Speed_Com_Y.Text = value.ToString("0.00"); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_CMD_VEL, Constants.AXIS_LOGIC_NUM_Z, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value = value / Move_unit * 1000 * 60; Speed_Com_Z.Text = value.ToString("0.00"); } else { MessageBox.Show("IP" + CGlbFunc.ip_info[0] + "读取失败"); } /* 主轴指令进给速度 */ ret32 = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_CMD_FEEDRATE, 0, 0, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value64 = value64 / Turn_unit * 1000 * 60; Chan_Cmd_Feedrate.Text = value64.ToString("0.00"); } /* 主轴实际进给速度 */ ret32 = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_ACT_FEEDRATE, 0, 0, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { // value64 = value64 / Turn_unit * 1000 * 60; Chan_Act_Feedrate.Text = value64.ToString("0.00"); } /* 主轴指令速度 */ ret32 = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_CMD_SPDL_SPEED, 0, 0, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value64 = value64 / Turn_unit * 1000 * 60; Chan_Cmd_Speed.Text = value64.ToString("0.00"); } /* 主轴实际速度 */ ret32 = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_ACT_SPDL_SPEED, 0, 0, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value64 = value64 / Turn_unit * 1000 * 60; Chan_Act_Speed.Text = value64.ToString("0.00"); } /*增加主轴负载电流及三种倍率信息*/ /* 主轴负载电流 */ //ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_RATED_CUR, Constants.AXIS_LOGIC_NUM_X, ref value64, clientnum); Double cur1 = 0; //值 ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_RATED_CUR, 5, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value64 = value64 / Turn_unit * 1000 * 60; cur1 = value64; Current_Spindle_Rated.Text = value64.ToString("0.000"); } ret32 = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_LOAD_CUR, 5, ref value64, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value64 = value64 / Turn_unit * 1000 * 60; value64 = value64 / 100 * cur1; Current_Spindle_Load.Text = value64.ToString("0.000"); } /* 进给修调 */ ret32 = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_FEED_OVERRIDE, 0, 0, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value64 = value64 / Turn_unit * 1000 * 60; Feed_override.Text = (value / 100.0).ToString("0.00" + "%"); } /* 快移修调 */ ret32 = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_RAPID_OVERRIDE, 0, 0, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value64 = value64 / Turn_unit * 1000 * 60; Rapid_override.Text = (value / 100.0).ToString("0.00" + "%"); } /* 主轴转速修调 */ ret32 = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_SPDL_OVERRIDE, 0, 0, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { //value64 = value64 / Turn_unit * 1000 * 60; Spdl_override.Text = (value / 100.0).ToString("0.00" + "%"); } /* 主轴逻辑轴号 */ ret32 = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_SPDL_LAX, 0, 0, ref value, CGlbFunc.clientNo[clientnum]); if (ret == 0) { Chan_Logic_Num.Text = value.ToString(); } /* 运行程序编号 */ ret32 = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_RUN_PROG, 0, 0, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { Chan_Run_Prog.Text = value.ToString(); } /* 刀具编号 */ ret32 = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_TOOL_USE, 0, 0, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { Cur_Tool.Text = value.ToString(); } /* 运行程序行 */ ret32 = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_RUN_ROW, 0, 0, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { Chan_Run_Row.Text = value.ToString(); } /* 编码程序行 */ ret32 = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_DCD_ROW, 0, 0, ref value, CGlbFunc.clientNo[clientnum]); if (ret32 == 0) { Chan_Dcd_Row.Text = value.ToString(); } NC_num.Text = clientnum.ToString(); Chan_num.Text = "0"; //else //{ // MessageBox.Show("IP" + CGlbFunc.ip_info[0] + "读取失败"); //} } //else //{ // MessageBox.Show("IP" + CGlbFunc.ip_info[0] + "通信失败"); //} }
private void add2list(PointPairList list, string param, ZedGraphControl zed) { double x = (double)new XDate(DateTime.Now);; double y = 0.0; zed.GraphPane.XAxis.Scale.MaxAuto = true; //如果要在折线图内显示指定数量的点,只需要在添加坐标之前把第一个坐标点去掉: if (list.Count >= 100) { list.RemoveAt(0); } switch (param) { case "主轴负载": //值 ret = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_RATED_CUR, 5, ref cur, clientno); if (ret == 0) { cur1 = cur; //Current_Spindle_Rated.Text = value64.ToString("0.000"); } ret = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_LOAD_CUR, 5, ref curate, clientno); if (ret == 0) { //value64 = value64 / Turn_unit * 1000 * 60; y = curate / 100 * cur1; //Current_Spindle_Load.Text = value64.ToString("0.000"); } list.Add(x, y); break; case "X轴负载": ret = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_LOAD_CUR, Constants.AXIS_LOGIC_NUM_X, ref cur_x, clientno); if (ret == 0) { y = cur_x; //负载电流单位为A,机床空负载时有静态误差,会出现负电流 } list.Add(x, y); break; case "Y轴负载": ret = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_LOAD_CUR, Constants.AXIS_LOGIC_NUM_Y, ref cur_y, clientno); if (ret == 0) { y = cur_y; //负载电流单位为A,机床空负载时有静态误差,会出现负电流 } list.Add(x, y); break; case "Z轴负载": ret = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_LOAD_CUR, Constants.AXIS_LOGIC_NUM_Z, ref cur_z, clientno); if (ret == 0) { y = cur_z; //负载电流单位为A,机床空负载时有静态误差,会出现负电流 } list.Add(x, y); break; case "供电电流": //double y1= 0.0; break; case "供电电压": break; default: break; } }
// 位置单位转换 private void GetAxisStrInfo(int count, Int32[] AxisId, Int32[] axisValue, Double[] cmdVel, ref string[] AxisValueInfo, ref string[] AxiscmdVelInfo) // 前三个是输入量,由方法 AxisInfoGotItems()获取的变量作为输入;ref后面的变量 是引用的传递变量 { Int32 ret = 0; Int32 lax = 0; Int32 axistype = 0; Int32 metric = 0; Int32 unit = 100000; Int32 diameter = 0; for (int i = 0; i < count; i++) { ret = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_LAX, mch, AxisId[i], ref lax, ActiveClientNo); // 直半径处理 ret = HncApi.HNC_ChannelGetValue((int)HncChannel.HNC_CHAN_DIAMETER, mch, 0, ref diameter, ActiveClientNo); if (0 == lax && 1 == diameter) { axisValue[i] *= 2; } ret = HncApi.HNC_AxisGetValue((int)HncAxis.HNC_AXIS_TYPE, lax, ref axistype, ActiveClientNo); // 判断轴的类型 获取响应的单位换算参数 if (axistype == 1) { ret = HncApi.HNC_SystemGetValue((int)HncSystem.HNC_SYS_MOVE_UNIT, ref unit, ActiveClientNo); // 直线轴 长度分辨率 ret = HncApi.HNC_SystemGetValue((int)HncSystem.HNC_SYS_METRIC_DISP, ref metric, ActiveClientNo); // 公英制 if (0 == metric) // 英制 { unit = (Int32)(unit * 25.4); } } else { ret = HncApi.HNC_SystemGetValue((int)HncSystem.HNC_SYS_TURN_UNIT, ref unit, ActiveClientNo); // 旋转轴 角度分辨率 } if (Math.Abs(unit) - 0.00001 <= 0.0) //除零保护 { AxisValueInfo[i] = "0"; AxiscmdVelInfo[i] = "0"; // 米度单位换算为 毫米每分钟 } else { AxisValueInfo[i] = ((double)axisValue[i] / unit).ToString("F4"); // 实际输出的轴的位置 单位换算 AxiscmdVelInfo[i] = (cmdVel[i] / unit).ToString("F4"); } if (axistype == 1) { if (0 == metric) // 英制 { AxisValueInfo[i] += " inch"; } else { AxisValueInfo[i] += " mm"; } } else { AxisValueInfo[i] += " D"; } } }