// 获取轴信息的变量类型  布尔型
        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 void GetAlarmInfo()
        {
            Int32  index  = 0;
            string errTxt = string.Empty;
            Int32  ret    = 0;

            ret = HncApi.HNC_AlarmGetNum((Int32)AlarmType.ALARM_TYPE_ALL, (Int32)AlarmLevel.ALARM_LEVEL_ALL, ref alarmNum, ActiveClientNo);
            if (ret != 0)
            {
                Console.WriteLine("获取警报失败");
            }
            else
            {
                Console.WriteLine($"当前警报数量为{alarmNum}");
            }

            for (int i = 0; i < alarmNum; i++)
            {
                ret = HncApi.HNC_AlarmGetData((int)AlarmType.ALARM_TYPE_ALL, (int)AlarmLevel.ALARM_ERR, index, ref alarmNo, ref errTxt, ActiveClientNo);
                if (ret == 0)
                {
                    alarmInfo = index.ToString() + alarmNo.ToString() + errTxt + "\n";
                    Console.WriteLine(alarmInfo);
                }

                else
                {
                    Console.WriteLine(" 无法读取警报信息!");
                }
            }
        }
Beispiel #3
0
 public void CancelToolBroken(bool bIsTrueBroken)
 {
     try
     {
         if (this._info != null)
         {
             String Redisip   = System.Configuration.ConfigurationManager.AppSettings["RedisUri"];
             Int32  Redisport = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["RedisPort_RealTime"]);
             ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient(Redisip, Redisport);
             client.Db = this._CloudDB;
             HncMessage <ToolBrokenInfo> toolinfo = new HncMessage <ToolBrokenInfo>();
             toolinfo.Header = "ToolBrokenFeedBack";
             _info.IsBroken  = bIsTrueBroken;
             toolinfo.Body   = _info;
             String msg = Newtonsoft.Json.JsonConvert.SerializeObject(toolinfo);
             client.Set <String>("ToolBrokenFeedBack", msg);
             _info = null;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("CancelToolBroken:" + ex.Message);
     }
     HncApi.HNC_RegClrBit((int)HncRegType.REG_TYPE_G, 2626, 0, _ClientNo);
     HncApi.HNC_RegClrBit((int)HncRegType.REG_TYPE_G, 3013, 15, _ClientNo);
 }
        // 初始化
        private void Form1_Load(object sender, EventArgs e)
        {
            ShowMsgBox(HncApi.HNC_NetInit(GetLocalIpAddr(), localPort) == 0 ? true : false, "Initializing ");
            AddCombox();

            abbScanner();  //  ABB 扫描
        }
Beispiel #5
0
        //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";
                }
            }
        }
Beispiel #6
0
        public void getclientnum(int num) //num 表示华中的第几台设备
        {
            UInt16 ret = HncApi.HNC_NetIsConnect(CGlbFunc.clientNo[num + 1]);

            if (ret == 0)
            {
                clientno = CGlbFunc.clientNo[num + 1];
            }
        }
        //历史报警数目
        public void GetHisAlarmNum()
        {
            Int32 ret = HncApi.HNC_AlarmGetHistoryNum(ref hisAlarmNum, HNCCollector.ActiveClientNo);

            if (ret != 0)
            {
                MessageBox.Show("failing to get the history alarmNum!");
            }
        }
Beispiel #8
0
        public Int32 HNC_NetGetSDKVer(ref String dllPlusVer)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HNCNET.VERSION_LEN);

            ret        = HncApi.HNC_NetGetSDKVer(ptr);
            dllPlusVer = Marshal.PtrToStringAnsi(ptr);
            Marshal.FreeHGlobal(ptr);
            return(ret);
        }
Beispiel #9
0
        public Int32 HNC_ChannelGetValue(Int32 type, Int32 ch, Int32 index, ref Double value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.doubleSize);

            ret   = HncApi.HNC_ChannelGetValue(type, ch, index, ptr, _ClientNo);
            value = (Double)Marshal.PtrToStructure(ptr, typeof(Double));
            Marshal.FreeHGlobal(ptr);
            return(ret);
        }
Beispiel #10
0
        public Int32 HNC_SystemSetValue(Int32 type, String value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HNCSYS.MAX_SYS_STR_LEN);

            ptr = Marshal.StringToCoTaskMemAnsi(value);
            ret = HncApi.HNC_SystemSetValue(type, ptr, _ClientNo);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #11
0
        public Int32 HNC_SystemGetValue(Int32 type, ref String value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HNCSYS.MAX_SYS_STR_LEN);

            ret   = HncApi.HNC_SystemGetValue(type, ptr, _ClientNo);
            value = Marshal.PtrToStringAnsi(ptr);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #12
0
        public Int32 HNC_VarSetValue(Int32 type, Int32 no, Int32 index, Double value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.doubleSize);

            Marshal.StructureToPtr(value, ptr, true);
            ret = HncApi.HNC_VarSetValue(type, no, index, ptr, _ClientNo);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #13
0
        public Int32 HNC_ParamanSetItem(Int32 fileNo, Int32 subNo, Int32 index, Double value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SParamValue)));

            Marshal.StructureToPtr(value, ptr, true);
            ret = HncApi.HNC_ParamanSetItem(fileNo, subNo, index, ptr, _ClientNo);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #14
0
        public Int32 HNC_ParamanGetFileName(Int32 fileNo, ref String buf)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HNCDATADEF.PARAMAN_LIB_TITLE_SIZE);

            ret = HncApi.HNC_ParamanGetFileName(fileNo, ptr, _ClientNo);
            buf = Marshal.PtrToStringAnsi(ptr);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #15
0
        public Int32 HNC_ParamanGetParaProp(Int32 filetype, Int32 subid, Int32 index, Byte prop_type, ref String prop_value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.PAR_PROP_DATA_LEN);

            ret        = HncApi.HNC_ParamanGetParaProp(filetype, subid, index, prop_type, ptr, _ClientNo);
            prop_value = Marshal.PtrToStringAnsi((IntPtr)(ptr.ToInt32() + HncApi.intSize));
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #16
0
        public Int32 HNC_CrdsSetValue(Int32 type, Int32 ax, Int32 value, Int32 ch, Int32 crds)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.intSize);

            Marshal.WriteInt32(ptr, value);
            ret = HncApi.HNC_CrdsSetValue(type, ax, ptr, ch, crds, _ClientNo);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #17
0
        public Int32 HNC_CrdsSetValue(Int32 type, Int32 ax, Double value, Int32 ch, Int32 crds)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.doubleSize);

            Marshal.StructureToPtr(value, ptr, true);
            ret = HncApi.HNC_CrdsSetValue(type, ax, ptr, ch, crds, _ClientNo);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #18
0
        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);
        }
Beispiel #19
0
        public Int32 HNC_RegSetValue(Int32 type, Int32 index, Byte value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.byteSize);

            Marshal.WriteByte(ptr, value);
            ret = HncApi.HNC_RegSetValue(type, index, ptr, _ClientNo);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #20
0
        public Int32 HNC_RegGetValue(Int32 type, Int32 index, ref Int16 value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.shortSize);

            ret   = HncApi.HNC_RegGetValue(type, index, ptr, _ClientNo);
            value = Marshal.ReadInt16(ptr);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #21
0
        public Int32 HNC_SystemSetValue(Int32 type, Int32 value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.intSize);

            Marshal.WriteInt32(ptr, value);
            ret = HncApi.HNC_SystemSetValue(type, ptr, _ClientNo);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #22
0
        public Int32 HNC_EventPut(SEventElement ev)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SEventElement)));

            Marshal.StructureToPtr(ev, ptr, true);
            ret = HncApi.HNC_EventPut(ptr, _ClientNo);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #23
0
        public Int32 HNC_ParamanGetParaPropEx(Int32 parmId, Byte propType, ref String propValue)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.PAR_PROP_DATA_LEN);

            ret       = HncApi.HNC_ParamanGetParaPropEx(parmId, propType, ptr, _ClientNo);
            propValue = Marshal.PtrToStringAnsi((IntPtr)(ptr.ToInt32() + HncApi.intSize));
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #24
0
        public Int32 HNC_ToolSetToolPara(Int32 toolNo, Int32 index, Int32 value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.intSize);

            Marshal.WriteInt32(ptr, value);
            ret = HncApi.HNC_ToolSetToolPara(toolNo, index, ptr, _ClientNo);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #25
0
        public Int32 HNC_AlarmGetData(Int32 type, Int32 level, Int32 index, ref Int32 alarmNo, ref String alarmText)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HNCALARM.ALARM_TXT_LEN);

            ret       = HncApi.HNC_AlarmGetData(type, level, index, ref alarmNo, ptr, _ClientNo);
            alarmText = Marshal.PtrToStringAnsi(ptr);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #26
0
        public Int32 HNC_ToolSetToolPara(Int32 toolNo, Int32 index, Double value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.doubleSize);

            Marshal.StructureToPtr(value, ptr, true);
            ret = HncApi.HNC_ToolSetToolPara(toolNo, index, ptr, _ClientNo);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #27
0
        public Int32 HNC_ParamanGetStr(Int32 fileNo, Int32 subNo, Int32 index, ref String value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.PAR_PROP_DATA_LEN);

            ret   = HncApi.HNC_ParamanGetStr(fileNo, subNo, index, ptr, _ClientNo);
            value = Marshal.PtrToStringAnsi(ptr);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #28
0
        public Int32 HNC_VarGetValue(Int32 type, Int32 no, Int32 index, ref Int32 value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.intSize);

            ret   = HncApi.HNC_VarGetValue(type, no, index, ptr, _ClientNo);
            value = Marshal.ReadInt32(ptr);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #29
0
        public Int32 HNC_ToolGetToolPara(Int32 toolNo, Int32 index, ref Double value)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HncApi.doubleSize);

            ret   = HncApi.HNC_ToolGetToolPara(toolNo, index, ptr, _ClientNo);
            value = (Double)Marshal.PtrToStructure(ptr, typeof(Double));
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }
Beispiel #30
0
        public Int32 HNC_FprogGetProgPathByIdx(Int32 pindex, ref String progName)
        {
            Int32  ret = -1;
            IntPtr ptr = Marshal.AllocHGlobal(HNCFPROGMAN.PROG_PATH_SIZE);

            ret      = HncApi.HNC_FprogGetProgPathByIdx(pindex, ptr, _ClientNo);
            progName = Marshal.PtrToStringAnsi(ptr);
            Marshal.FreeHGlobal(ptr);

            return(ret);
        }