Example #1
0
 public DAMachineRealTimeInfo GetDAMachineRealTimeInfoById(string Id)
 {
     using (IDAMachineRealTimeInfoBLL DAMachineRealTimeInfoBLL = BLLContainer.Resolve <IDAMachineRealTimeInfoBLL>())
     {
         DAMachineRealTimeInfo model = DAMachineRealTimeInfoBLL.GetFirstOrDefault(Id);
         return(model);
     }
 }
Example #2
0
 public bool AddDAMachineRealTimeInfo(DAMachineRealTimeInfo mDAMachineRealTimeInfo)
 {
     if (mDAMachineRealTimeInfo == null)
     {
         return(false);
     }
     using (IDAMachineRealTimeInfoBLL DAMachineRealTimeInfoBLL = BLLContainer.Resolve <IDAMachineRealTimeInfoBLL>())
     {
         return(DAMachineRealTimeInfoBLL.Add(mDAMachineRealTimeInfo));
     }
 }
Example #3
0
 public bool DelDAMachineRealTimeInfo(string Id)
 {
     using (IDAMachineRealTimeInfoBLL DAMachineRealTimeInfoBLL = BLLContainer.Resolve <IDAMachineRealTimeInfoBLL>())
     {
         try
         {
             DAMachineRealTimeInfo item = DAMachineRealTimeInfoBLL.GetFirstOrDefault(Id);
             return(DAMachineRealTimeInfoBLL.Delete(item));
         }
         catch { return(false); }
     }
 }
Example #4
0
 public bool DelDAMachineRealTimeInfos(string[] Ids)
 {
     using (IDAMachineRealTimeInfoBLL DAMachineRealTimeInfoBLL = BLLContainer.Resolve <IDAMachineRealTimeInfoBLL>())
     {
         try
         {
             List <DAMachineRealTimeInfo> entitys = new List <DAMachineRealTimeInfo>();
             foreach (string id in Ids)
             {
                 DAMachineRealTimeInfo item = DAMachineRealTimeInfoBLL.GetFirstOrDefault(id);
                 entitys.Add(item);
             }
             return(DAMachineRealTimeInfoBLL.Delete(entitys));
         }
         catch { return(false); }
     }
 }
Example #5
0
        /// <summary>
        /// 读取DA数据
        /// </summary>
        /// <param name="device"></param>
        private void ThreadGetDaMonitor(FmsAssetCommParam device)
        {
            if ((!bMonitor) || (device == null))
            {
                return;        //未开启监控
            }
            int readSpan = 0;  //设定采样周期的变量

            #region 获取基础参数

            string deviceCode = device.ASSET_CODE;
            DeviceCommInterface interfaceType = EnumHelper.ParserEnumByValue(device.INTERFACE_TYPE, DeviceCommInterface.CNC_Fanuc);
            string commAddress = device.COMM_ADDRESS;
            int    period      = Convert.ToInt32(device.SAMPLING_PERIOD); //采样周期

            List <FmsAssetTagSetting> tagSettings =
                _tagSettings.Where(c => c.ASSET_CODE == deviceCode && c.SAMPLING_MODE == 3).ToList();  //DA采集模式

            if (tagSettings.Count <= 0)
            {
                return;
            }

            #endregion

            DeviceManager deviceCommunication = new DeviceManager(CBaseData.NewGuid(),
                                                                  interfaceType, commAddress, period * 1000);

            List <DeviceTagParam> deviceTags = new List <DeviceTagParam>();

            foreach (var tagSetting in tagSettings)
            {
                DeviceTagParam deviceTag = new DeviceTagParam(tagSetting.PKNO, tagSetting.TAG_CODE,
                                                              tagSetting.TAG_NAME, tagSetting.TAG_ADDRESS,
                                                              EnumHelper.ParserEnumByValue(tagSetting.VALUE_TYPE, TagDataType.Default),
                                                              EnumHelper.ParserEnumByValue(tagSetting.SAMPLING_MODE, DataSimplingMode.ReadAndWrite),
                                                              deviceCommunication); //通讯参数

                deviceTags.Add(deviceTag);                                          //添加
            }

            deviceCommunication.InitialDevice(deviceTags, SaveData);

            while (!CBaseData.AppClosing)
            {
                #region 暂停

                if (bPause)
                {
                    System.Threading.Thread.Sleep(200);
                    continue;
                }

                #endregion

                try
                {
                    readSpan++;

                    if ((period > 0) && (readSpan % (period * 10) == 0)) //读取数据
                    {
                        string error = "";

                        lock (locakDA)
                        {
                            List <FmsAssetTagSetting> daTags =
                                tagSettings.Where(c => c.SAMPLING_MODE == 3).ToList(); //这些为Focas的

                            if (daTags.Any())
                            {
                                #region 采集实时信息

                                DAMachineRealTimeInfo realTimeInfo =
                                    ws_DA.UseService(
                                        s => s.GetDAMachineRealTimeInfos("ASSET_CODE = " + device.ASSET_CODE + ""))
                                    .FirstOrDefault();

                                if (realTimeInfo != null)
                                {
                                    //实况信息采集和录入
                                    realTimeInfo.STATUS           = int.Parse(deviceCommunication.SyncReadData("状态", out error));
                                    realTimeInfo.MAIN_PROG        = deviceCommunication.SyncReadData("程序号", out error);
                                    realTimeInfo.SPINDLE_OVERRIDE = deviceCommunication.SyncReadData("主轴负载", out error);
                                    realTimeInfo.SPINDLE_SPPED    = deviceCommunication.SyncReadData("主轴转速", out error);
                                    realTimeInfo.FEED_SPEED       = deviceCommunication.SyncReadData("进给速度", out error);
                                    realTimeInfo.FEED_RATE        = deviceCommunication.SyncReadData("进给倍率", out error);
                                    realTimeInfo.DA_TIME          = DateTime.Now;
                                    ws_DA.UseService(s => s.UpdateDAMachineRealTimeInfo(realTimeInfo)); //实时更新
                                }

                                #endregion

                                #region 采集产量信息

                                //设备产量记录采集
                                DAProductRecord productRecord =
                                    ws_DA.UseService(s => s.GetDAProductRecords($"ASSET_CODE = '{device.ASSET_CODE}'"))
                                    .OrderByDescending(c => c.END_TIME)
                                    .FirstOrDefault();     //获取生产记录

                                if (productRecord != null)
                                {
                                    int part_num = 0;
                                    int.TryParse(deviceCommunication.SyncReadData("工件数", out error), out part_num);
                                    int total_num = 0;
                                    int.TryParse(deviceCommunication.SyncReadData("工件总数", out error), out total_num);

                                    if (part_num == productRecord.PART_NUM)
                                    {
                                        if (productRecord.END_TIME <= DateTime.Now.AddMinutes(-5)) //每5分钟,更新数据库
                                        {
                                            productRecord.END_TIME = DateTime.Now;
                                            ws_DA.UseService(s => s.UpdateDAProductRecord(productRecord));
                                        }
                                    }
                                    else //不一致
                                    {
                                        productRecord.END_TIME = DateTime.Now;
                                        ws_DA.UseService(s => s.UpdateDAProductRecord(productRecord));

                                        //插入新的纪录
                                        DAProductRecord newProductRecord = new DAProductRecord();
                                        newProductRecord.ASSET_CODE = deviceCode;
                                        newProductRecord.PKNO       = Guid.NewGuid().ToString("N");
                                        newProductRecord.START_TIME = DateTime.Now;
                                        newProductRecord.END_TIME   = DateTime.Now.AddMilliseconds(100);
                                        newProductRecord.PART_NUM   = part_num;

                                        newProductRecord.TOTAL_PART_NUM = total_num;
                                        ws_DA.UseService(s => s.AddDAProductRecord(newProductRecord)); //新增当前值到数据库
                                    }
                                }

                                #endregion

                                #region 采集报警信息

                                string a = deviceCommunication.SyncReadData("报警信息", out error);

                                #endregion
                            }
                        }
                    }

                    readSpan = 0;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ThreadGetDAMonitor, 错误为:" + ex.Message);
                }

                System.Threading.Thread.Sleep(100);
            }
        }