コード例 #1
0
 private static StationDto CreateStationDto(Station station)
 {
     
     DvseMeter meter = null;
     ProductionOrder order = null;
     
     if (!string.IsNullOrEmpty(station.MeterNo))
     {
         meter = MeterRepository.GetOne(station.MeterNo);
     }
     
     if (!string.IsNullOrEmpty(station.OrderUniqueId))
     {
         order  = OrderRepository.GetOneByUniqueId(station.OrderUniqueId, true);
     }
     
     var dto = StationDto.Create(station, order, meter);
     return dto;
 }
コード例 #2
0
        public static void ReadData(Station station, CancellationToken token)
        {
            var meter = GetMeter(station.MeterNo);

            try
            {
                StationRepository.SetPortComParamStatus(station.ComPort, PortComParamStatus.Reading);
                var isFakeCom = AppConfigRepository.Get().IsFakeCom;
                if (!isFakeCom)
                {
                    SetManufacturerMode(station.ComPort, true);
                }

                // clear real values
                meter.Parameters.ForEach(p => p.RealValue = string.Empty);
                MeterRepository.Update(meter);

                foreach (var p in
                   from p in meter.Parameters
                   where p.IsActive              // < only take activated parameters for reading 
                   where !p.IsWriteOnly          // < only take readable parameters for reading
                   where !p.IsNameplateOnly      // < only take com parameters for reading
                   select p)
                {
                    if (token.IsCancellationRequested)
                    {
                        // break if user cancelled task
                        StationRepository.SetPortComParamStatus(station.ComPort, PortComParamStatus.NotRead);
                        return;
                    }

                    if (isFakeCom)
                    {
                        //Thread.Sleep(150);
                        p.RealValue = p.TargetValue;
                        if (p.TagId == ParameterTagId.SignatureCheck)
                        {
                            p.RealValue = "SUCCESS: ...";
                        }
                    }
                    else
                    {
                        switch (p.TagId)
                        {
                            case ParameterTagId.ClientId:
                                p.RealValue = ReadClientId(station.ComPort);
                                break;
                            case ParameterTagId.ManufacturerSerialNumber:
                                p.RealValue = ReadManufacturerSerialNumber(station.ComPort);
                                break;
                            case ParameterTagId.ProductionId:
                                p.RealValue = ReadProductionId(station.ComPort);
                                break;
                            case ParameterTagId.ServerId:
                                p.RealValue = ReadServerId(station.ComPort);
                                break;
                            case ParameterTagId.MeasurementMode:
                                p.RealValue = ReadMeasurementMode(station.ComPort);
                                break;
                            case ParameterTagId.TariffCount:
                                p.RealValue = ReadNumberOfTariffs(station.ComPort).ToString();
                                break;
                            case ParameterTagId.InverseTariffControl:
                                p.RealValue = ReadTerminalControlReverse(station.ComPort);
                                break;
                            case ParameterTagId.PublicKey:
                                p.RealValue = ReadPublicKey(station.ComPort);
                                break;
                            case ParameterTagId.InfoInterfaceActivated:
                                p.RealValue = ReadInfoInterfaceStatus(station.ComPort);
                                break;
                            case ParameterTagId.HistoricValuesEnabled:
                                p.RealValue = ReadHistoricEnergyEnabled(station.ComPort);
                                break;
                            case ParameterTagId.PinProtectionEnabled:
                                p.RealValue = ReadPinProtectionEnabled(station.ComPort);
                                break;
                            case ParameterTagId.PowerOnLcdEnabled:
                                p.RealValue = ReadPowerOnLcdEnabled(station.ComPort);
                                break;
                            case ParameterTagId.AutomaticPinFallback:
                                p.RealValue = ReadAutoPinFallback(station.ComPort);
                                break;
                            case ParameterTagId.SignatureCheck:
                                ReadSignature(station.ComPort, p);
                                break;
                        }
                    }
                }

                meter.IsCommunciationCompleted = meter.Parameters.All(p => p.IsValid);
                MeterRepository.Update(meter);

                StationRepository.SetPortComParamStatus(station.ComPort,
                    meter.IsCommunciationCompleted ? PortComParamStatus.ReadBackOk : PortComParamStatus.ParamFailed);
            }
            catch (Exception ex)
            {
                Log.ErrorException("SmlCom read failed", ex);
                StationRepository.SetPortComParamStatus(station.ComPort, PortComParamStatus.ReadFailed);
            }
        }
コード例 #3
0
        public static void WriteData(Station station, CancellationToken token, bool isReadBackEnabled = false)
        {
            var meter = GetMeter(station.MeterNo);

            try
            {
                StationRepository.SetPortComParamStatus(station.ComPort, PortComParamStatus.Writing);

                if (!AppConfigRepository.Get().IsFakeCom)
                {
                    SetManufacturerMode(station.ComPort, true);
                }

                // clear real values
                meter.Parameters.ForEach(p => p.RealValue = string.Empty);

                // clear written status
                meter.Parameters.ForEach(p => p.IsWritten = false);

                MeterRepository.Update(meter);

                var isFakeCom = AppConfigRepository.Get().IsFakeCom;
                foreach (var p in meter.Parameters)
                {
                    if (token.IsCancellationRequested)
                    {
                        // break if user cancelled task
                        StationRepository.SetPortComParamStatus(station.ComPort, PortComParamStatus.NotWritten);
                        return;
                    }

                    if (p.IsActive == false || p.IsNameplateOnly || p.IsReadOnly)
                    {
                        if (p.TagId != ParameterTagId.SignatureCheck)
                        {
                            // Signaturecheck should be always performed, even when it was declared as readonly or inactive...
                            continue;
                        }
                    }

                    if (isFakeCom)
                    {
                        p.RealValue = p.TargetValue;
                        if (!p.IsReadOnly && !p.IsNameplateOnly)
                        {
                            p.IsWritten = true;
                        }

                        if (p.TagId == ParameterTagId.SignatureCheck)
                        {
                            p.IsWritten = true;
                        }

                        Thread.Sleep(200);
                        continue;
                    }

                    switch (p.TagId)
                    {
                        case ParameterTagId.ClientId:
                            WriteClientId(station.ComPort, p.TargetValue);
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.ManufacturerSerialNumber:
                            WriteManufacturerSerialNumber(station.ComPort, p.TargetValue);
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.ProductionId:
                            WriteProductionId(station.ComPort, p.TargetValue);
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.ServerId:
                            WriteServerId(station.ComPort, p.TargetValue);
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.MeasurementMode:
                            WriteMeasurementMode(station.ComPort, p.TargetValue);
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.TariffCount:
                            WriteNumberOfTariffs(station.ComPort, int.Parse(p.TargetValue));
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.InverseTariffControl:
                            WriteTerminalControlReverse(station.ComPort, p.TargetValue);
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.GenerateKeys:
                            if (GetTextAsValue(p.TargetValue))
                            {
                                WriteCreateEccKeys(station.ComPort);
                            }
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.ClearManipulation:
                            if (GetTextAsValue(p.TargetValue))
                            {
                                WriteClearManipulation(station.ComPort);
                            }
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.ClearHistoricEnergy:
                            if (GetTextAsValue(p.TargetValue))
                            {
                                WriteEraseHistoricEnergy(station.ComPort);
                            }
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.ClearEvents:
                            if (GetTextAsValue(p.TargetValue))
                            {
                                WriteClearEvent(station.ComPort);
                            }
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.ClearError:
                            if (GetTextAsValue(p.TargetValue))
                            {
                                WriteClearError(station.ComPort);
                            }
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.PinCode:
                            WritePinCode(station.ComPort, p.TargetValue);
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.InfoInterfaceActivated:
                            WriteInfoInterfaceStatus(station.ComPort, p.TargetValue);
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.HistoricValuesEnabled:
                            WriteHistoricEnergyEnabled(station.ComPort, p.TargetValue);
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.PinProtectionEnabled:
                            WritePinProtectionEnabled(station.ComPort, p.TargetValue);
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.PowerOnLcdEnabled:
                            WritePowerOnLcdEnabled(station.ComPort, p.TargetValue);
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.AutomaticPinFallback:
                            WriteAutoPinFallback(station.ComPort, p.TargetValue);
                            p.IsWritten = true;
                            break;
                        case ParameterTagId.SignatureCheck:
                            WriteEnableEdl40(station.ComPort);
                            p.IsWritten = true;
                            break;
                    }
                }

                MeterRepository.Update(meter);
                StationRepository.SetPortComParamStatus(station.ComPort, PortComParamStatus.WriteOk);
            }
            catch (Exception ex)
            {
                StationRepository.SetPortComParamStatus(station.ComPort, PortComParamStatus.WriteFailed);
                Log.ErrorException("Sml Com write failed", ex);
            }

            if (isReadBackEnabled)
            {
                ReadData(station, token);
            }
        }
コード例 #4
0
 public void Update(Station station)
 {
     Clients.All.Update(station);
 }