Exemple #1
0
        void ReadMeasurement(PolledMeasurement measurement)
        {
            OpcMetric metric = new OpcMetric();

            metric.Measurement = (MeasurementDto)measurement;

            if (!l_session.Connected)
            {
                l_logger.ErrorFormat(string.Format("Server not connected. Cannot read path {0}.", measurement.Name));
                throw new Exception(string.Format("Server not connected. Cannot read path {0}.", measurement.Name));
            }
            var nodesToRead = OpcUaHelper.GetReadValueIdCollection(measurement.Path, l_session);
            DataValueCollection      results;
            DiagnosticInfoCollection diag;

            l_session.Read(
                requestHeader: null,
                maxAge: 0,
                timestampsToReturn: TimestampsToReturn.Neither,
                nodesToRead: nodesToRead,
                results: out results,
                diagnosticInfos: out diag);
            var val = results[0];

            metric.OpcValue = val.Value;

            metric.Opcstatus = val.StatusCode.ToString();
            if (OpcHelper.QualifyMetric(ref metric, l_cache))
            {
                l_cache[metric.Measurement.Name] = metric.OpcValue;
                l_metricCollection.Add(metric);
            }
        }
Exemple #2
0
 /// <summary>
 /// 主入口
 /// </summary>
 /// <returns></returns>
 public bool Request()
 {
     try
     {
         OpcHelper.OpcConnect();//opc连接
     }
     catch (Exception ex)
     {
         Log.WriteLog(E_ProcessLogType.Error, "opc连接失败。" + ex.Message, "OpcService.OpcConnect()");
         return(false);
     }
     if (!OpcHelper.IsConnected)
     {
         Log.WriteLog(E_ProcessLogType.Error, "opc连接失败。", "Request()");
         return(false);
     }
     try
     {
         LoadConfig();//加载配置
     }
     catch (Exception ex)
     {
         Log.WriteLog(E_ProcessLogType.Error, "加载配置失败。" + ex.Message, "LoadConfig()");
         return(false);
     }
     return(true);
 }
Exemple #3
0
        private bool LoadValues(Dictionary <ApiOpcParameter, string> parameters)
        {
            if (parameters.Any())
            {
                return(OpcHelper.WriteTags(NewOpcServer.OpcList.Rbu, parameters));
            }

            return(false);
        }
 public KepController(EQItem item, ArrayList valList)
 {
     _item         = item;
     subScribeList = valList;
     KepHelper     = new OpcHelper();
     KepHelper.ServerShutdownEvent += new OpcHelper.ServerShutdown(KepHelper_ServerShutdownEvent);
     _kepThread = new Thread(ConnectKep);
     _kepThread.Start();
 }
Exemple #5
0
 /// <summary>
 /// 断开连接
 /// </summary>
 public void Disconnect()
 {
     try
     {
         OpcHelper.OpcDisconnect();
     }
     catch (Exception)
     {
     }
 }
Exemple #6
0
 /// <summary>
 /// 加载配置
 /// </summary>
 public void LoadConfig()
 {
     foreach (var device in BaseData.Devices)
     {
         List <DC_DATA_CONFIG> lstConfig = BaseData.Configs.Where(s => s.DEVICE_ID == device.ID).ToList();
         if (lstConfig != null && lstConfig.Count > 0)
         {
             OpcHelper.OpcRegister(device, lstConfig);
         }
     }
 }
Exemple #7
0
        private void RefreshOpcServers()
        {
            BackgroundWorker bgWorker = new BackgroundWorker();

            bgWorker.DoWork += (s, e) =>
            {
                e.Result = OpcHelper.GetOpcServers(Address);
            };
            bgWorker.RunWorkerCompleted += (s, e) =>
            {
                AvailableOpcServers = (List <String>)e.Result;
            };
            bgWorker.RunWorkerAsync();
        }
Exemple #8
0
 public Task CheckAndLoad()
 {
     return(Task.Run(async() =>
     {
         CurrentTaskIdParameter = GetCommonParameter(OpcHelper.TagNames.CurrentTaskId);
         if (CurrentTaskIdParameter != null)
         {
             var tagValue = OpcHelper.ReadTag(_opcName, CurrentTaskIdParameter.Tag);
             await DoWork(tagValue);
         }
         else
         {
             Logger.Error("Отсутствует параметр CurrentTaskId.");
         }
     }));
 }
Exemple #9
0
        /// <summary>
        /// opc初始化
        /// </summary>
        private void IniOpc()
        {
            //Kepware.KEPServerEX.V5
            //KingView.View.1

            opcHelper = new OpcHelper();
            if (this.opcHelper.CreateServer(ServerIP))
            {
                SimpleLogHelper.Instance.WriteLog(LogType.Info, "创建opc服务成功");
                if (this.opcHelper.OPCServerNames != null)
                {
                    this.cmbOPCNames.ItemsSource   = this.opcHelper.OPCServerNames;
                    this.cmbOPCNames.SelectedIndex = 0;
                }
            }
        }
Exemple #10
0
 /// <summary>
 /// Connects to the OPC server.
 /// </summary>
 private void ConnectToOpcServer()
 {
     try
     {
         OpcHelper helper = new OpcHelper(AppDirs, Log, DeviceNum, true);
         connected                = helper.ConnectAsync(opcDeviceConfig.ConnectionOptions, PollingOptions.Timeout).Result;
         opcSession               = helper.OpcSession;
         opcSession.KeepAlive    += OpcSession_KeepAlive;
         opcSession.Notification += OpcSession_Notification;
     }
     catch (Exception ex)
     {
         connected = false;
         Log.WriteError(ex, Locale.IsRussian ?
                        "Ошибка при соединении с OPC-сервером" :
                        "Error connecting OPC server");
     }
 }
Exemple #11
0
        private decimal GetMixerVolume()
        {
            var mixerVolumeParam = CommonOpcParametersReader.GetCommonOpcParameterByName(OpcHelper.GetTagName(OpcHelper.TagNames.MixerVolume));

            if (mixerVolumeParam != null)
            {
                var mixerVolumeValue = OpcHelper.ReadTag(NewOpcServer.OpcList.Rbu, mixerVolumeParam.Tag);
                var mixerVolume      = Convert.ToDecimal(OpcHelper.GetParameterValue(mixerVolumeValue, mixerVolumeParam));
                if (mixerVolume != 0)
                {
                    return(mixerVolume);
                }

                Logger.Error("Объем миксера не может быть равен 0.");
                MessageBox.Show("Объем миксера не может быть равен 0.");
                return((decimal)0.2);
            }

            Logger.Error("Остутствует название тега - MixerVolume.");
            MessageBox.Show("Остутствует название тега - MixerVolume.");
            return((decimal)0.2);
        }
Exemple #12
0
        void ReadMeasurement(PolledMeasurement measurement)
        {
            var item = new OpcDa.Item {
                ItemName = measurement.Path
            };

            if (l_server == null || l_server.GetStatus().ServerState != OpcDa.serverState.running)
            {
                l_logger.ErrorFormat(string.Format("Server not connected. Cannot read path {0}.", measurement.Name));
                throw new Exception(string.Format("Server not connected. Cannot read path {0}.", measurement.Name));
            }
            var result = l_server.Read(new[] { item })[0];

            if (result == null)
            {
                l_logger.Error("the server replied with an empty response!!!");
                throw new Exception("the server replied with an empty response");//if any item cannot read, throw exeption
            }
            if (result.ResultID.ToString() != "S_OK")
            {
                l_logger.ErrorFormat(string.Format("Invalid response from the server. (Response Status: {0}, Opc Tag: {1})", result.ResultID, measurement.Path));
                throw new Exception(string.Format("Invalid response from the server. (Response Status: {0}, Opc Tag: {1})", result.ResultID, measurement.Path));
            }

            OpcMetric metric = new OpcMetric()
            {
                Measurement = measurement,
                Opcstatus   = result.ResultID.ToString(),
                OpcValue    = result.Value,
                Timestamp   = result.Timestamp
            };

            if (OpcHelper.QualifyMetric(ref metric, l_cache))
            {
                l_cache[metric.Measurement.Name] = metric.OpcValue;
                l_metricCollection.Add(metric);
            }
        }
Exemple #13
0
        void opcManager_OnReadCompleted(object sender, OpcDaCustomAsyncEventArgs e)
        {
            //Invoke((ThreadStart)(() =>
            //{

            //    if (OpcHelper.ShowValue(e, 3) != null)
            //    {
            //        textBox1.Text = OpcHelper.ShowValue(e, 3).ToString();
            //    }
            //}));



            Invoke((ThreadStart)(() =>
            {
                this.textBox1.Clear();
                if (OpcHelper.ShowValue(e, 1) != null)
                {
                    short[] b = (short[])OpcHelper.ShowValue(e, 1);
                    foreach (var item in b)
                    {
                        this.textBox1.AppendText(item.ToString() + ",");
                    }
                }
            }));


            barcode = this.textBox1.Text;


            //string sql = $"INSERT into barcode(barcode,Var01,Var02,Var03,Var04,Var05,Var06,Var07,Var08,CreateTime,IsPrinted) values('{barcode}','{Var01}','{Var02}','{Var03}','{Var04}','{Var05}','{Var06}','{Var07}','{Var08}',0,0)";


            string sql = $"INSERT into barcode(barcode) values('{barcode}')";

            succeed = SqlSugarHelper.DB.Ado.ExecuteCommand(sql);
        }
Exemple #14
0
        public async Task ReportHandler()
        {
            await Task.Run(() =>
            {
                if (_opc != null && _reportAttributesDict != null)
                {
                    for (var i = 1; i <= 10; i++)
                    {
                        var taskIdTag = _reportAttributesDict[ReportAttributes.ReportName] + $"[{i}]." +
                                        _reportAttributesDict[ReportAttributes.TaskId];
                        var finishDateTag = _reportAttributesDict[ReportAttributes.ReportName] + $"[{i}]." +
                                            _reportAttributesDict[ReportAttributes.FinishDate];
                        var finishTimeTag = _reportAttributesDict[ReportAttributes.ReportName] + $"[{i}]." +
                                            _reportAttributesDict[ReportAttributes.FinishTime];
                        var taskId     = _opc.ReadNode(taskIdTag.ToNode(), OpcAttribute.Value)?.ToString();
                        var finishDate = _opc.ReadNode(finishDateTag.ToNode(), OpcAttribute.Value)?.ToString();
                        var finishTime = _opc.ReadNode(finishTimeTag.ToNode(), OpcAttribute.Value)?.ToString();
                        if (!string.IsNullOrEmpty(taskId) && finishDate != "1990-01-01")
                        {
                            long.TryParse(taskId, out var id);
                            if (SearchReport(id))
                            {
                                var finishDt = OpcHelper.StringDateParsing(finishDate, finishTime);
                                _reports.Add(ReadReport(i, id, finishDt));
                            }
                        }
                    }

                    if (_reports.Any())
                    {
                        WriteReportList(_reports);
                        _reports.Clear();
                    }
                }
            });
        }
Exemple #15
0
        private Report ReadReport(int i, long taskId, DateTime finishDt)
        {
            var report = new Report
            {
                Task = new AsuBetonLibrary.Classes.DbContext.Task {
                    Id = taskId
                },
                FinishDt = finishDt
            };

            if (_reportAttributesDict.ContainsKey(ReportAttributes.StartDate) && _reportAttributesDict.ContainsKey(ReportAttributes.StartTime))
            {
                var startDateTag = _reportAttributesDict[ReportAttributes.ReportName] + $"[{i}]." + _reportAttributesDict[ReportAttributes.StartDate];
                var starTimeTag  = _reportAttributesDict[ReportAttributes.ReportName] + $"[{i}]." + _reportAttributesDict[ReportAttributes.StartTime];
                var startDate    = _opc.ReadNode(startDateTag.ToNode(), OpcAttribute.Value)?.ToString();
                var startTime    = _opc.ReadNode(starTimeTag.ToNode(), OpcAttribute.Value)?.ToString();
                report.StartDt = OpcHelper.StringDateParsing(startDate, startTime);
            }

            var reportString = _reportAttributesDict[ReportAttributes.ReportName] + $"[{i}].";

            report.Batches = GetBatches(reportString);
            return(report);
        }
Exemple #16
0
        private Dictionary <ApiOpcParameter, string> GetValues(ApiTask task, ApiRecipe recipe, Dictionary <long, ApiRecipeMaterial> containers)
        {
            var result   = new Dictionary <ApiOpcParameter, string>();
            var isOk     = true;
            var batchers = BatchersReader.ListBatchers();

            foreach (var batcher in batchers)
            {
                foreach (var dosingSource in batcher.DosingSources)
                {
                    containers.TryGetValue(dosingSource.Container.Id, out var recipeMaterial);
                    if (recipeMaterial != null)
                    {
                        var materialSetParameter = dosingSource.DosingSourceOpcParameters.FirstOrDefault(x =>
                                                                                                         x.Name == OpcHelper.GetTagName(OpcHelper.TagNames.MaterialSet));
                        if (materialSetParameter != null)
                        {
                            var volume = Math.Round(recipeMaterial.Volume * task.BatchVolume, 1);
                            result.Add(materialSetParameter, volume.ToString(CultureInfo.InvariantCulture));
                        }
                        else
                        {
                            isOk = false;
                            Logger.Error($"У дозатора {batcher.Name} - источник дозирования {dosingSource.Name} отсутствует параметр - MaterialSet.");
                        }
                        var materialIdParameter = dosingSource.DosingSourceOpcParameters.FirstOrDefault(x =>
                                                                                                        x.Name == OpcHelper.GetTagName(OpcHelper.TagNames.MaterialId));
                        if (materialIdParameter != null)
                        {
                            result.Add(materialIdParameter, recipeMaterial.Material.Id.ToString(CultureInfo.InvariantCulture));
                        }
                        else
                        {
                            isOk = false;
                            Logger.Error($"У дозатора {batcher.Name} - источник дозирования {dosingSource.Name} отсутствует параметр - MaterialId.");
                        }
                        var containerIdParameter = dosingSource.DosingSourceOpcParameters.FirstOrDefault(x =>
                                                                                                         x.Name == OpcHelper.GetTagName(OpcHelper.TagNames.ContainerId));
                        if (containerIdParameter != null)
                        {
                            result.Add(containerIdParameter, dosingSource.Container.Id.ToString(CultureInfo.InvariantCulture));
                        }
                        else
                        {
                            isOk = false;
                            Logger.Error($"У дозатора {batcher.Name} - источник дозирования {dosingSource.Name} отсутствует параметр - ContainerId.");
                        }
                    }
                }
            }
            var batchesAmount = GetCommonParameter(OpcHelper.TagNames.BatchesAmount);

            if (batchesAmount != null)
            {
                result.Add(batchesAmount, task.BatchesAmount.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                isOk = false;
                Logger.Error("Отсутствует параметр - BatchesAmount.");
            }
            var mixingTime = GetCommonParameter(OpcHelper.TagNames.MixingTime);

            if (mixingTime != null)
            {
                result.Add(mixingTime, recipe.MixingTime.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                isOk = false;
                Logger.Error("Отсутствует параметр - MixingTime.");
            }
            var percentOpenGate = GetCommonParameter(OpcHelper.TagNames.PercentOpenGate);

            if (percentOpenGate != null)
            {
                result.Add(percentOpenGate, recipe.PercentOpenGate.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                isOk = false;
                Logger.Error("Отсутствует параметр - PercentOpenGate.");
            }
            var timeFullUnload = GetCommonParameter(OpcHelper.TagNames.TimeFullUnload);

            if (timeFullUnload != null)
            {
                result.Add(timeFullUnload, recipe.TimeFullUnload.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                isOk = false;
                Logger.Error("Отсутствует параметр - TimeFullUnload.");
            }
            var timePartialUnload = GetCommonParameter(OpcHelper.TagNames.TimePartialUnload);

            if (timePartialUnload != null)
            {
                result.Add(timePartialUnload, recipe.TimePartialUnload.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                isOk = false;
                Logger.Error("Отсутствует параметр - TimePartialUnload.");
            }
            return(isOk ? result : null);
        }
Exemple #17
0
        private List <DosingSourceMaterial> GetDosingSourceMaterials(string batcher)
        {
            var dosingSourceMaterials = new List <DosingSourceMaterial>();
            var dosingSourceNames     = DosingSourcesReader.GetDosingSourceNames();

            if (_reportAttributesDict.ContainsKey(ReportAttributes.SetVolume))
            {
                foreach (var dosingSourceName in dosingSourceNames)
                {
                    var setVolumeTag = batcher + $"{dosingSourceName}." +
                                       _reportAttributesDict[ReportAttributes.SetVolume];
                    var setVolumeString = _opc.ReadNode(setVolumeTag.ToNode(), OpcAttribute.Value)?.ToString();
                    decimal.TryParse(setVolumeString, out var setVolume);

                    if (setVolume != 0)
                    {
                        var dosingSourceMaterial = new DosingSourceMaterial {
                            SetVolume = setVolume
                        };
                        if (_reportAttributesDict.ContainsKey(ReportAttributes.StartDosageDate) && _reportAttributesDict.ContainsKey(ReportAttributes.StartDosageTime))
                        {
                            var startDosageDateTag = batcher + $"{dosingSourceName}." +
                                                     _reportAttributesDict[ReportAttributes.StartDosageDate];
                            var startDosageTimeTag = batcher + $"{dosingSourceName}." +
                                                     _reportAttributesDict[ReportAttributes.StartDosageTime];
                            var startDosageDate = _opc.ReadNode(startDosageDateTag.ToNode(), OpcAttribute.Value)?.ToString();
                            var startDosageTime = _opc.ReadNode(startDosageTimeTag.ToNode(), OpcAttribute.Value)?.ToString();
                            dosingSourceMaterial.StartDosage = OpcHelper.StringDateParsing(startDosageDate, startDosageTime);
                        }

                        if (_reportAttributesDict.ContainsKey(ReportAttributes.FinishDosageDate) && _reportAttributesDict.ContainsKey(ReportAttributes.FinishDosageTime))
                        {
                            var finishDosageDateTag = batcher + $"{dosingSourceName}." +
                                                      _reportAttributesDict[ReportAttributes.FinishDosageDate];
                            var finishDosageTimeTag = batcher + $"{dosingSourceName}." +
                                                      _reportAttributesDict[ReportAttributes.FinishDosageTime];
                            var finishDosageDate =
                                _opc.ReadNode(finishDosageDateTag.ToNode(), OpcAttribute.Value)?.ToString();
                            var finishDosageTime =
                                _opc.ReadNode(finishDosageTimeTag.ToNode(), OpcAttribute.Value)?.ToString();
                            dosingSourceMaterial.FinishDosage = OpcHelper.StringDateParsing(finishDosageDate, finishDosageTime);
                        }

                        if (_reportAttributesDict.ContainsKey(ReportAttributes.StartWeightDosage))
                        {
                            var startWeightTag = batcher + $"{dosingSourceName}." +
                                                 _reportAttributesDict[ReportAttributes.StartWeightDosage];
                            var startWeightString =
                                _opc.ReadNode(startWeightTag.ToNode(), OpcAttribute.Value)?.ToString();
                            decimal.TryParse(startWeightString, out var startWeight);
                            dosingSourceMaterial.StartWeightDosage = startWeight;
                        }

                        if (_reportAttributesDict.ContainsKey(ReportAttributes.FinishWeightDosage))
                        {
                            var finishWeightTag = batcher + $"{dosingSourceName}." +
                                                  _reportAttributesDict[ReportAttributes.FinishWeightDosage];
                            var finishWeightString =
                                _opc.ReadNode(finishWeightTag.ToNode(), OpcAttribute.Value)?.ToString();
                            decimal.TryParse(finishWeightString, out var finishWeight);
                            dosingSourceMaterial.FinishWeightDosage = finishWeight;
                        }

                        if (_reportAttributesDict.ContainsKey(ReportAttributes.MaterialId))
                        {
                            var materialIdTag = batcher + $"{dosingSourceName}." +
                                                _reportAttributesDict[ReportAttributes.MaterialId];
                            var materialIdString =
                                _opc.ReadNode(materialIdTag.ToNode(), OpcAttribute.Value)?.ToString();
                            long.TryParse(materialIdString, out var materialId);
                            dosingSourceMaterial.MaterialId = materialId;
                        }

                        if (_reportAttributesDict.ContainsKey(ReportAttributes.ContainerId))
                        {
                            var containerIdTag = batcher + $"{dosingSourceName}." +
                                                 _reportAttributesDict[ReportAttributes.ContainerId];
                            var containerIdString =
                                _opc.ReadNode(containerIdTag.ToNode(), OpcAttribute.Value)?.ToString();
                            long.TryParse(containerIdString, out var containerId);
                            dosingSourceMaterial.ContainerId = containerId;
                        }

                        dosingSourceMaterials.Add(dosingSourceMaterial);
                    }
                }
            }

            return(dosingSourceMaterials);
        }
Exemple #18
0
        private List <BatcherMaterial> GetBatcherMaterials(string batch)
        {
            var batcherMaterials = new List <BatcherMaterial>();
            var batcherNames     = BatchersReader.GetBatcherNames();

            if (_reportAttributesDict.ContainsKey(ReportAttributes.FinishLoadingDate) && _reportAttributesDict.ContainsKey(ReportAttributes.FinishLoadingTime))
            {
                foreach (var batcherName in batcherNames)
                {
                    var finishDateLoadingTag = batch + $"{batcherName}." +
                                               _reportAttributesDict[ReportAttributes.FinishLoadingDate];
                    var finishTimeLoadingTag = batch + $"{batcherName}." +
                                               _reportAttributesDict[ReportAttributes.FinishLoadingTime];
                    var finishLoadingDate = _opc.ReadNode(finishDateLoadingTag.ToNode(), OpcAttribute.Value)
                                            ?.ToString();
                    var finishLoadingTime = _opc.ReadNode(finishTimeLoadingTag.ToNode(), OpcAttribute.Value)
                                            ?.ToString();
                    if (finishLoadingDate != "1990-01-01" && finishLoadingDate != "null")
                    {
                        var batcherMaterial = new BatcherMaterial {
                            FinishLoading = OpcHelper.StringDateParsing(finishLoadingDate, finishLoadingTime)
                        };
                        if (_reportAttributesDict.ContainsKey(ReportAttributes.StartLoadingDate) && _reportAttributesDict.ContainsKey(ReportAttributes.StartLoadingTime))
                        {
                            var startDateLoadingTag = batch + $"{batcherName}." +
                                                      _reportAttributesDict[ReportAttributes.StartLoadingDate];
                            var startTimeLoadingTag = batch + $"{batcherName}." +
                                                      _reportAttributesDict[ReportAttributes.StartLoadingTime];
                            var startLoadingDate =
                                _opc.ReadNode(startDateLoadingTag.ToNode(), OpcAttribute.Value)?.ToString();
                            var startLoadingTime =
                                _opc.ReadNode(startTimeLoadingTag.ToNode(), OpcAttribute.Value)?.ToString();
                            batcherMaterial.StartLoading = OpcHelper.StringDateParsing(startLoadingDate, startLoadingTime);
                        }

                        if (_reportAttributesDict.ContainsKey(ReportAttributes.StartWeight))
                        {
                            var startWeightTag = batch + $"{batcherName}." +
                                                 _reportAttributesDict[ReportAttributes.StartWeight];
                            var startWeightString =
                                _opc.ReadNode(startWeightTag.ToNode(), OpcAttribute.Value)?.ToString();
                            decimal.TryParse(startWeightString, out var startWeight);
                            batcherMaterial.StartWeight = startWeight;
                        }

                        if (_reportAttributesDict.ContainsKey(ReportAttributes.FinishWeight))
                        {
                            var finishWeightTag = batch + $"{batcherName}." +
                                                  _reportAttributesDict[ReportAttributes.FinishWeight];
                            var finishWeightString =
                                _opc.ReadNode(finishWeightTag.ToNode(), OpcAttribute.Value)?.ToString();
                            decimal.TryParse(finishWeightString, out var finishWeight);
                            batcherMaterial.FinishWeight = finishWeight;
                        }

                        var batcherString = batch + $"{batcherName}.";
                        batcherMaterial.DosingSourceMaterials = GetDosingSourceMaterials(batcherString);
                        batcherMaterials.Add(batcherMaterial);
                    }
                }
            }

            return(batcherMaterials);
        }
Exemple #19
0
        private List <Batch> GetBatches(string report)
        {
            var batches = new List <Batch>();

            for (int j = 1; j <= 10; j++)
            {
                if (_reportAttributesDict.ContainsKey(ReportAttributes.BatchFinishDate) && _reportAttributesDict.ContainsKey(ReportAttributes.BatchFinishTime))
                {
                    var batchFinishDateTag = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}]." + _reportAttributesDict[ReportAttributes.BatchFinishDate];
                    var batchFinishTimeTag = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}]." + _reportAttributesDict[ReportAttributes.BatchFinishTime];
                    var finishDate         = _opc.ReadNode(batchFinishDateTag.ToNode(), OpcAttribute.Value)?.ToString();
                    var finishTime         = _opc.ReadNode(batchFinishTimeTag.ToNode(), OpcAttribute.Value)?.ToString();
                    if (finishDate != "1990-01-01" && finishDate != "null")
                    {
                        var batch = new Batch {
                            FinishDt = OpcHelper.StringDateParsing(finishDate, finishTime)
                        };

                        if (_reportAttributesDict.ContainsKey(ReportAttributes.BatchStartDate) && _reportAttributesDict.ContainsKey(ReportAttributes.BatchStartTime))
                        {
                            var batchStartDateTag = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}]." + _reportAttributesDict[ReportAttributes.BatchStartDate];
                            var batchStartTimeTag = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}]." + _reportAttributesDict[ReportAttributes.BatchStartTime];
                            var startDate         = _opc.ReadNode(batchStartDateTag.ToNode(), OpcAttribute.Value)?.ToString();
                            var startTime         = _opc.ReadNode(batchStartTimeTag.ToNode(), OpcAttribute.Value)?.ToString();
                            batch.StartDt = OpcHelper.StringDateParsing(startDate, startTime);
                        }
                        if (_reportAttributesDict.ContainsKey(ReportAttributes.StartMixingDate) && _reportAttributesDict.ContainsKey(ReportAttributes.StartMixingTime))
                        {
                            var startMixingDateTag = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}]." + _reportAttributesDict[ReportAttributes.StartMixingDate];
                            var startMixingTimeTag = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}]." + _reportAttributesDict[ReportAttributes.StartMixingTime];
                            var startMixingDate    = _opc.ReadNode(startMixingDateTag.ToNode(), OpcAttribute.Value)?.ToString();
                            var startMixingTime    = _opc.ReadNode(startMixingTimeTag.ToNode(), OpcAttribute.Value)?.ToString();
                            batch.StartMixing = OpcHelper.StringDateParsing(startMixingDate, startMixingTime);
                        }
                        if (_reportAttributesDict.ContainsKey(ReportAttributes.FinishMixingDate) && _reportAttributesDict.ContainsKey(ReportAttributes.FinishMixingTime))
                        {
                            var finishMixingDateTag = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}]." + _reportAttributesDict[ReportAttributes.FinishMixingDate];
                            var finishMixingTimeTag = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}]." + _reportAttributesDict[ReportAttributes.FinishMixingTime];
                            var finishMixingDate    = _opc.ReadNode(finishMixingDateTag.ToNode(), OpcAttribute.Value)?.ToString();
                            var finishMixingTime    = _opc.ReadNode(finishMixingTimeTag.ToNode(), OpcAttribute.Value)?.ToString();
                            batch.FinishMixing = OpcHelper.StringDateParsing(finishMixingDate, finishMixingTime);
                        }
                        if (_reportAttributesDict.ContainsKey(ReportAttributes.StartUnloadingDate) && _reportAttributesDict.ContainsKey(ReportAttributes.StartUnloadingTime))
                        {
                            var startUnloadingDateTag = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}]." + _reportAttributesDict[ReportAttributes.StartUnloadingDate];
                            var startUnloadingTimeTag = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}]." + _reportAttributesDict[ReportAttributes.StartUnloadingTime];
                            var startUnloadingDate    = _opc.ReadNode(startUnloadingDateTag.ToNode(), OpcAttribute.Value)?.ToString();
                            var startUnloadingTime    = _opc.ReadNode(startUnloadingTimeTag.ToNode(), OpcAttribute.Value)?.ToString();
                            batch.StartUnloading = OpcHelper.StringDateParsing(startUnloadingDate, startUnloadingTime);
                        }
                        if (_reportAttributesDict.ContainsKey(ReportAttributes.FinishUnloadingDate) && _reportAttributesDict.ContainsKey(ReportAttributes.FinishUnloadingTime))
                        {
                            var startUnloadingDateTag = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}]." + _reportAttributesDict[ReportAttributes.FinishUnloadingDate];
                            var startUnloadingTimeTag = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}]." + _reportAttributesDict[ReportAttributes.FinishUnloadingTime];
                            var finishUnloadingDate   = _opc.ReadNode(startUnloadingDateTag.ToNode(), OpcAttribute.Value)?.ToString();
                            var finishUnloadingTime   = _opc.ReadNode(startUnloadingTimeTag.ToNode(), OpcAttribute.Value)?.ToString();
                            batch.FinishUnloading = OpcHelper.StringDateParsing(finishUnloadingDate, finishUnloadingTime);
                        }

                        var batchString = report + _reportAttributesDict[ReportAttributes.BatchName] + $"[{j}].";
                        batch.BatcherMaterials = GetBatcherMaterials(batchString);
                        batches.Add(batch);
                    }
                }
            }
            return(batches);
        }
Exemple #20
0
 /// <summary>
 /// 读
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 public object Read(DC_DATA_CONFIG config)
 {
     return(OpcHelper.Read(config));
 }
Exemple #21
0
 /// <summary>
 /// 写
 /// </summary>
 /// <param name="config"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public bool Write(DC_DATA_CONFIG config, object value)
 {
     return(OpcHelper.Write(config, value));
 }
Exemple #22
0
        public void ClientDataChanged(List <object> clientHandleList, List <DataValue> valueList, StationModel stnmodel, BaseProtocol protocol)
        {
            OpcHelper opchelper = new OpcHelper(protocol, stnmodel, stnmodel.ServerIndex);

            try
            {
                OpcBll bll = new OpcBll();
                bll.myopcHelper = opchelper;
                bll.StnModel    = stnmodel;
                for (int i = 0; i < clientHandleList.Count; i++)
                {
                    int       clientHandle = Convert.ToInt32(clientHandleList[i]);
                    DataValue datavalue    = valueList[i];
                    bool      value        = Convert.ToBoolean(datavalue.Value);
                    switch (clientHandle)
                    {
                    case 0:    //心跳
                        // opchelper.SendHeartBit(!value);
                        break;

                    case 1:    //电芯NG剔料,记录过点,然后电芯补一个订单
                        if (value)
                        {
                            messagaBLL.WriteMessage("收到电芯NG剔料请求", stnmodel.StationCode, 0);
                            byte[]         array = opchelper.ReadPlcData();
                            AnalDataHelper a     = new AnalDataHelper(stnmodel);
                            int            res   = a.DianXinNg(array);
                            if (res == 0)
                            {
                                messagaBLL.WriteMessage("发送电芯NG剔料完成", stnmodel.StationCode, res);
                                opchelper.SendDianXinNgOk();
                            }
                            else
                            {
                                messagaBLL.WriteMessage("发送电芯NG剔料失败,发送错误代码" + res, stnmodel.StationCode, res);
                                opchelper.SendErrorsCode((byte)res);
                            }
                        }
                        break;

                    case 2:    //上线请求
                        if (value)
                        {
                            messagaBLL.WriteMessage("收到上线请求", stnmodel.StationCode, 0);
                            bll.InitData();
                        }
                        break;

                    case 3:    //下线请求
                        if (value)
                        {
                            messagaBLL.WriteMessage("收到下线请求", stnmodel.StationCode, 0);
                            byte[]         array = opchelper.ReadPlcData();
                            AnalDataHelper a     = new AnalDataHelper(stnmodel);
                            int            res   = a.AnalData(array);
                            if (res == 0)
                            {
                                if (stnmodel.StationCode == "OP240A")
                                {
                                    byte[] tagValues;
                                    tagValues = opchelper.ReadRepairPlcData();
                                    int temp = a.SaveOP240TagValue(tagValues);
                                    if (temp != 0)
                                    {
                                        opchelper.SendErrorsCode(50);
                                        messagaBLL.WriteMessage("保存TAG数据失败发送错误代码:" + 50, stnmodel.StationCode, 50);
                                        return;
                                    }
                                }
                                opchelper.SendReaddowngDownCmd();
                                opchelper.SendErrorsCode(0);
                                messagaBLL.WriteMessage("发送下线完成", stnmodel.StationCode, 0);
                            }
                            else
                            {
                                opchelper.SendErrorsCode((byte)res);
                                messagaBLL.WriteMessage("发送错误代码" + res, stnmodel.StationCode, res);
                            }
                        }
                        break;

                    case 4:    //读bom
                        if (value)
                        {
                            messagaBLL.WriteMessage("收到BOM比对请求", stnmodel.StationCode, 0);
                            bll.CheckBom();
                        }
                        break;

                    case 5:    //返修上线
                        if (value)
                        {
                            messagaBLL.WriteMessage("收到返修上线请求", stnmodel.StationCode, 0);
                            int res = bll.InitRepairData();
                            if (res == 0)
                            {
                                opchelper.SendRepairWriteDown();
                                opchelper.SendErrorsCode(0);
                                messagaBLL.WriteMessage("发送返修上线完成", stnmodel.StationCode, 0);
                            }
                            else
                            {
                                opchelper.SendErrorsCode((byte)res);
                                messagaBLL.WriteMessage("返修上线失败,发送错误代码" + res, stnmodel.StationCode, res);
                            }
                        }
                        break;

                    case 6:    //返修下线
                        if (value)
                        {
                            messagaBLL.WriteMessage("收到返修下线请求", stnmodel.StationCode, 0);
                            byte[]         array = opchelper.ReadRepairPlcData();
                            AnalDataHelper a     = new AnalDataHelper(stnmodel);
                            int            r     = a.SaveTagValue(array);
                            if (r == 0)
                            {
                                opchelper.SendRepairReadDown();
                                opchelper.SendErrorsCode(0);
                                messagaBLL.WriteMessage("发送返修下线完成", stnmodel.StationCode, 0);
                            }
                            else
                            {
                                opchelper.SendErrorsCode((byte)r);
                                messagaBLL.WriteMessage("返修下线失败,发送错误代码" + r, stnmodel.StationCode, 0);
                            }
                        }
                        break;

                    case 7:    //andon物料拉动
                        if (value)
                        {
                            messagaBLL.WriteMessage("收到物料拉动请求", stnmodel.StationCode, 0);
                            string materialNum = opchelper.ReadMaterialNum();
                            string operatornum = opchelper.ReadOperatorNum();
                            int    res         = AndonHelper.SendMaterialPull(materialNum, operatornum, stnmodel.StationCode);
                            if (res == 0)
                            {
                                opchelper.SendMaterialPullOk();
                                opchelper.SendErrorsCode(0);
                                messagaBLL.WriteMessage("发送物料拉动完成", stnmodel.StationCode, 0);
                            }
                            else
                            {
                                opchelper.SendMaterialPullNG();
                                //opchelper.SendErrorsCode((byte)res);//PLC那边不要这个错误代码
                                messagaBLL.WriteMessage("发送物料拉动失败,发送错误代码:" + res, stnmodel.StationCode, res);
                            }
                        }
                        break;

                    case 8:    //OCV 检测
                        if (value)
                        {
                            messagaBLL.WriteMessage("收到OCV测试请求", stnmodel.StationCode);
                            byte[] array = opchelper.ReadPlcData();
                            bll.CheckOCVTest(array);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Write(ex, "BingEvent");
                opchelper.SendErrorsCode(100);
            }
        }
Exemple #23
0
        private ApiOpcParameter GetCommonParameter(OpcHelper.TagNames tagName)
        {
            var currentTaskIdParameter = CommonOpcParametersReader.GetCommonOpcParameterByName(OpcHelper.GetTagName(tagName));

            return(currentTaskIdParameter);
        }