Пример #1
0
        //UI6下降沿
        private void BtnPauseStart_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                FmsAssetTagSetting tag = DeviceMonitor.GetTagSettings("TAG_CODE = 'UI6'").FirstOrDefault();

                if (tag == null)
                {
                    return;
                }

                Cursor = Cursors.Wait;
                int    ret    = 0;
                string error  = "";
                int    iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "1", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                if (ret != 0)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }

                Thread.Sleep(500);

                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                Cursor = Cursors.Arrow;
                if (ret == 0)
                {
                    WPFMessageBox.ShowInfo("机器人的暂停后启动信息已经成功给出!", "启动机器人");
                }
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Arrow;
            }
        }
Пример #2
0
        /// <summary>
        /// 读取设备线程
        /// </summary>
        private void TheadCheckData()
        {
            while (!CBaseData.AppClosing)
            {
                Thread.Sleep(200); //暂停
                try
                {
                    for (int i = 1; i <= 5; i++)
                    {
                        string basicAddress     = "[fuzhou]MES.JG.SB_" + i.ToString(); //基本地址
                        string qingqiuAddress   = ".Qing_qiu";                         //请求
                        string gongyiIDAddress  = ".Gongyi_ID";                        //工艺ID
                        string chanpinIDAddress = ".chanpin_ID";                       //产品ID
                        string querenAddress    = ".que_ren";                          //确认地址
                        querenAddress.Substring(0, 1);
                        FmsAssetTagSetting tag_qingqiu =
                            DeviceMonitor.GetTagSettings($"TAG_ADDRESS = '{basicAddress}{qingqiuAddress}'")
                            .FirstOrDefault();

                        if ((tag_qingqiu == null) || (tag_qingqiu.CUR_VALUE != "1"))
                        {
                            continue;
                        }

                        #region 触发请求

                        FmsAssetTagSetting tag_gongyi =
                            DeviceMonitor.GetTagSettings($"TAG_ADDRESS = '{basicAddress}{gongyiIDAddress}'")
                            .FirstOrDefault();     //工艺ID
                        if (tag_gongyi == null)
                        {
                            continue;
                        }

                        FmsAssetTagSetting tag_chanpin =
                            DeviceMonitor.GetTagSettings($"TAG_ADDRESS = '{basicAddress}{chanpinIDAddress}'")
                            .FirstOrDefault();     //产品ID
                        if (tag_chanpin == null)
                        {
                            continue;
                        }

                        FmsAssetTagSetting tag_queren =
                            DeviceMonitor.GetTagSettings($"TAG_ADDRESS = '{basicAddress}{querenAddress}'")
                            .FirstOrDefault();     //确认
                        if (tag_queren == null)
                        {
                            continue;
                        }

                        EmCheckResult checkResult = EmCheckResult.NoCheck; //无校验

                        #region 1.校验程序号

                        AmAssetMasterN checkDevice =
                            wsEAM.UseService(s => s.GetAmAssetMasterNs($"USE_FLAG = 1 AND ASSET_TYPE = '机床' AND ASSET_LABEL = '{i.ToString()}'"))
                            .FirstOrDefault();

                        if (checkDevice == null)
                        {
                            Console.WriteLine("...error:没有相应的机床设备.");
                            continue;
                        }

                        FmsAssetTagSetting tag_focas =
                            DeviceMonitor.GetTagSettings(
                                $"ASSET_CODE = '{checkDevice.ASSET_CODE}' AND TAG_ADDRESS = '程序号'")
                            .FirstOrDefault();     //获取程序号

                        if ((tag_focas != null) &&
                            (tag_focas.CUR_VALUE == tag_gongyi.CUR_VALUE)) //程序号相同
                        {
                            checkResult = EmCheckResult.Success;
                        }
                        else
                        {
                            checkResult = EmCheckResult.ProgramError;
                        }

                        #endregion

                        #region 2.校验产品

                        MesJobOrder curJob =
                            wsPlm.UseService(s => s.GetMesJobOrders($"RUN_STATE = 3 AND LINE_PKNO = '{CBaseData.CurLinePKNO}'")).FirstOrDefault(); //开工确认完成的

                        if (curJob != null)
                        {
                            RsItemMaster itemMaster =
                                wsRSM.UseService(s => s.GetRsItemMasterById(curJob.ITEM_PKNO));

                            if ((itemMaster != null) && (itemMaster.ITEM_ABV == tag_chanpin.CUR_VALUE))
                            {
                                if (checkResult == EmCheckResult.Success)  //程序校验成功
                                {
                                    checkResult = EmCheckResult.Success;
                                }
                            }
                            else
                            {
                                checkResult = EmCheckResult.ProductError;
                            }
                        }
                        else
                        {
                            checkResult = EmCheckResult.ProductError;
                        }

                        #endregion

                        #region 向PLC反馈

                        FmsAssetCommParam deviceComm =
                            ws.UseService(
                                s => s.GetFmsAssetCommParams(
                                    $"ASSET_CODE = '{tag_qingqiu.ASSET_CODE}' AND USE_FLAG = 1")).FirstOrDefault();  //反馈设备

                        string        error = "";
                        OperateResult ret   = DeviceHelper.WriteDataByAddress(deviceComm.ASSET_CODE,
                                                                              deviceComm.INTERFACE_TYPE, deviceComm.COMM_ADDRESS,
                                                                              tag_queren.PKNO, tag_queren.TAG_ADDRESS,
                                                                              ((int)checkResult).ToString()); //反馈

                        #endregion

                        if (!ret.IsSuccess)
                        {
                            Console.WriteLine("...error:向设备" + tag_queren.ASSET_CODE + "反馈确认结果失败。");
                        }

                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("...error:生产过程校验错误,错误为:" + ex.Message);
                }
            }
        }
Пример #3
0
        private void btnRestDevice1_Click(object sender, RoutedEventArgs e)
        {
            //创胜特尔
            try
            {
                Cursor = Cursors.Wait;
                string assetCode = "SH00003";

                int                ret        = 0;
                string             error      = "";
                int                iWrite     = 0;
                string             tagAddress = "";
                FmsAssetTagSetting tag        = null;

                tagAddress = "#120";
                #region 清空换刀刀号

                tag = DeviceMonitor.GetTagSettings($"ASSET_CODE = '{assetCode}' AND TAG_ADDRESS = '{tagAddress}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                tagAddress = "#121";
                #region 清空下次换刀刀号

                tag = DeviceMonitor.GetTagSettings($"ASSET_CODE = '{assetCode}' AND TAG_ADDRESS = '{tagAddress}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                tagAddress = "E520.0";
                #region 清空启动程序

                tag = DeviceMonitor.GetTagSettings($"ASSET_CODE = '{assetCode}' AND TAG_ADDRESS = '{tagAddress}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                tagAddress = "E521.0";
                #region 清空 机床加工下发/完成

                tag = DeviceMonitor.GetTagSettings($"ASSET_CODE = '{assetCode}' AND TAG_ADDRESS = '{tagAddress}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                tagAddress = "E521.1";
                #region 清空 机床换刀中

                tag = DeviceMonitor.GetTagSettings($"ASSET_CODE = '{assetCode}' AND TAG_ADDRESS = '{tagAddress}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                tagAddress = "E530";
                #region 清空 机床加工程序号

                tag = DeviceMonitor.GetTagSettings($"ASSET_CODE = '{assetCode}' AND TAG_ADDRESS = '{tagAddress}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                tagAddress = "E531.0";
                #region 清空 机床松开刀

                tag = DeviceMonitor.GetTagSettings($"ASSET_CODE = '{assetCode}' AND TAG_ADDRESS = '{tagAddress}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                tagAddress = "E532.0";
                #region 清空 机床拉紧刀

                tag = DeviceMonitor.GetTagSettings($"ASSET_CODE = '{assetCode}' AND TAG_ADDRESS = '{tagAddress}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                tagAddress = "E533.0";
                #region 清空 机器人离开机床

                tag = DeviceMonitor.GetTagSettings($"ASSET_CODE = '{assetCode}' AND TAG_ADDRESS = '{tagAddress}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                Cursor = Cursors.Arrow;

                if (ret == 0)
                {
                    WPFMessageBox.ShowInfo("1#机床(创胜特尔)的FCS状态已复位.", "复位机床状态");
                }
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Arrow;
            }
        }
Пример #4
0
        //UI18下降沿
        private void BtnStart_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Cursor = Cursors.Wait;

                int                ret     = 0;
                string             error   = "";
                int                iWrite  = 0;
                string             tagCode = "";
                FmsAssetTagSetting tag     = null;
                #region 清空相关DI
                #region 清空DI271
                tagCode = "DI271";
                tag     = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                #region 清空DI272
                tagCode = "DI272";
                tag     = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion
                #region 清空DI275
                tagCode = "DI275";
                tag     = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion
                #region 清空DI276
                tagCode = "DI276";
                tag     = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                #region 清空DI277
                tagCode = "DI277";
                tag     = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                #region AGV寄存器清空
                tagCode = "1005";
                tag     = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "1", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion
                #endregion
                tagCode = "清空机器人GI";
                #region 清空GI

                tag = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion


                tagCode = "UI5";
                #region 给出UI5

                tag = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "1", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                tagCode = "UI17";
                #region 给出UI17

                tag = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "1", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                Thread.Sleep(300);

                tagCode = "UI18";
                #region UI18 下降沿

                tag = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "1", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                if (ret != 0)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }

                Thread.Sleep(300);

                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                Thread.Sleep(1000);

                tagCode = "UI17";
                #region 清空 UI17

                tag = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                tagCode = "UI5";
                #region 清空 UI5

                tag = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "0", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                Cursor = Cursors.Arrow;

                if (ret == 0)
                {
                    WPFMessageBox.ShowInfo("机器人启动信号已经成功给出.", "启动机器人");
                }
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Arrow;
            }
        }
Пример #5
0
        //机器人使能
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //机器人使能UI1=1 UI2=1 UI3=1 UI8=1 UI9=1
            FmsAssetTagSetting tag = null;
            int    ret             = 0;
            string error           = "";
            int    iWrite          = 0;
            string tagCode         = "UI1";



            tagCode = "UI1";
            #region 给出使能

            tag = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

            if (tag == null)
            {
                return;
            }
            iWrite = 0;
            while (iWrite < ReWriteCount)
            {
                ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "1", out error);
                if (ret == 0)
                {
                    break;
                }
                iWrite++;
                Thread.Sleep(100);
            }

            #endregion

            tagCode = "UI2";
            #region 给出使能

            tag = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

            if (tag == null)
            {
                return;
            }
            iWrite = 0;
            while (iWrite < ReWriteCount)
            {
                ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "1", out error);
                if (ret == 0)
                {
                    break;
                }
                iWrite++;
                Thread.Sleep(100);
            }

            #endregion

            tagCode = "UI3";
            #region 给出使能

            tag = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

            if (tag == null)
            {
                return;
            }
            iWrite = 0;
            while (iWrite < ReWriteCount)
            {
                ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "1", out error);
                if (ret == 0)
                {
                    break;
                }
                iWrite++;
                Thread.Sleep(100);
            }

            #endregion

            tagCode = "UI8";
            #region 给出使能

            tag = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

            if (tag == null)
            {
                return;
            }
            iWrite = 0;
            while (iWrite < ReWriteCount)
            {
                ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "1", out error);
                if (ret == 0)
                {
                    break;
                }
                iWrite++;
                Thread.Sleep(100);
            }

            #endregion

            tagCode = "UI9";
            #region 给出使能

            tag = DeviceMonitor.GetTagSettings($"TAG_CODE = '{tagCode}'").FirstOrDefault();

            if (tag == null)
            {
                return;
            }
            iWrite = 0;
            while (iWrite < ReWriteCount)
            {
                ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "1", out error);
                if (ret == 0)
                {
                    break;
                }
                iWrite++;
                Thread.Sleep(100);
            }

            #endregion

            if (ret == 0)
            {
                WPFMessageBox.ShowInfo("机器人使能已经给出.", "启动机器人");
            }
        }
Пример #6
0
        private Action <DragThumb, FmsAssetTagSetting> _showInfo; //显示界面信息

        private void ThreadShowWorkState(object obj)
        {
            //状态颜色 0:其他状态=脱机的颜色;1:工作状态颜色;2:故障状态颜色;3:待机状态颜色;4:急停状态颜色
            Brush[] StateColors = new Brush[5]
            {
                Brushes.Gray, Brushes.Green, Brushes.OrangeRed, Brushes.DarkGoldenrod, Brushes.DarkRed
            };

            #region 创建显示信息的函数,提高效率

            _showInfo = (thumb, tag) =>
            {
                if ((thumb == null) || (tag == null))
                {
                    return;
                }

                if (tag.STATE_MARK_TYPE == 0) //普通内容
                {
                    thumb.Text = tag.TAG_VALUE_NAME + " " + tag.CUR_VALUE + " " + tag.VALUE_UNIT;
                }
                else if (tag.STATE_MARK_TYPE == 1) //联机状态
                {
                    int state = SafeConverter.SafeToInt(tag.CUR_VALUE, 0);
                    if (state <= 4) //状态
                    {
                        thumb.Background  = StateColors[state];
                        thumb.BorderBrush = StateColors[state];
                    }
                }
                else if (tag.STATE_MARK_TYPE == 2) //待机状态
                {
                    int state = SafeConverter.SafeToInt(tag.CUR_VALUE, 0);
                    if (state == 2)
                    {
                        state = 3;
                    }

                    if (state <= 4) //状态
                    {
                        thumb.Background  = StateColors[state];
                        thumb.BorderBrush = StateColors[state];
                    }
                }
                else if (tag.STATE_MARK_TYPE == 4) //故障状态
                {
                    int state = SafeConverter.SafeToInt(tag.CUR_VALUE, -1);
                    if (state == 1) //故障,整个产线报警
                    {
                        thumb.Background  = StateColors[2];
                        thumb.BorderBrush = StateColors[2];
                    }
                    else if (state == 0) //正常
                    {
                        thumb.Background  = StateColors[1];
                        thumb.BorderBrush = StateColors[1];
                    }
                    else //离线状态
                    {
                        thumb.Background  = StateColors[0];
                        thumb.BorderBrush = StateColors[0];
                    }
                }
                else if (tag.STATE_MARK_TYPE == 10) //状态
                {
                    int state = SafeConverter.SafeToInt(tag.CUR_VALUE, 0);
                    if ((state < 0) || (state >= StateColors.Length))
                    {
                        state = 0;
                    }

                    thumb.Background  = StateColors[state];
                    thumb.BorderBrush = StateColors[state];
                }
            };

            #endregion

            #region 后台执行

            while (!CBaseData.AppClosing)
            {
                if (!bShowInfo)
                {
                    Thread.Sleep(500);
                    continue;
                }

                //显示状态
                try
                {
                    foreach (DragThumb thumb in cvMain.DragThumbs)
                    {
                        if (!bShowInfo)
                        {
                            break;
                        }

                        FmsAssetTagSetting tag = DeviceMonitor.GetTagSettingById(thumb.CtrlName); //查找TagSetting
                        if (tag == null)
                        {
                            continue;
                        }

                        Dispatcher.BeginInvoke(_showInfo, thumb, tag);
                    }
                }
                catch (Exception ex)
                {
                    EventLogger.Log($"!!!!!!实时监控错误,原因:{ex.Message}!!!!!!");
                }

                Thread.Sleep(500);
            }

            #endregion
        }
Пример #7
0
        private void btnRestDevice2_Click(object sender, RoutedEventArgs e)
        {
            //英伟达
            try
            {
                Cursor = Cursors.Wait;
                string assetCode = "SH00002";

                int                ret        = 0;
                string             error      = "";
                int                iWrite     = 0;
                string             tagAddress = "";
                FmsAssetTagSetting tag        = null;
                tagAddress = "E530";
                #region 初始化101程序

                tag = DeviceMonitor.GetTagSettings($"ASSET_CODE = '{assetCode}' AND TAG_ADDRESS = '{tagAddress}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "101", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion


                tagAddress = "E520.0";
                #region 初始化开始状态

                tag = DeviceMonitor.GetTagSettings($"ASSET_CODE = '{assetCode}' AND TAG_ADDRESS = '{tagAddress}'").FirstOrDefault();

                if (tag == null)
                {
                    Cursor = Cursors.Arrow;
                    return;
                }
                iWrite = 0;
                while (iWrite < ReWriteCount)
                {
                    ret = DeviceMonitor.WriteTagToDevice(tag.PKNO, "1", out error);
                    if (ret == 0)
                    {
                        break;
                    }

                    iWrite++;
                    Thread.Sleep(100);
                }

                #endregion

                Cursor = Cursors.Arrow;

                if (ret == 0)
                {
                    WPFMessageBox.ShowInfo("2#机床(英伟达)的FCS状态已复位.", "复位机床状态");
                }
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Arrow;
            }
        }