示例#1
0
        private void SubsystemServiceListUpdate(string alias, SubsystemUpdateEnum?update, string filenameWithPath)
        {
            try
            {
                if (update == SubsystemUpdateEnum.SubsystemConnect)
                {
                    string assemblyFile = Path.Combine(Path.GetDirectoryName(filenameWithPath),
                                                       Path.GetFileNameWithoutExtension(filenameWithPath));

                    if (!Directory.Exists(assemblyFile))
                    {
                        Directory.CreateDirectory(assemblyFile);

                        using (ZipFile zip = ZipFile.Read(filenameWithPath))
                        {
                            zip.ExtractAll(assemblyFile);
                        }
                    }

                    LoadAssembly(assemblyFile);
                }
                else
                {
                    UnloadAssembly(alias);
                }
            }
            catch (Exception ex)
            {
                _Logger.LogError(ex);
            }
        }
示例#2
0
        private void ConnectionAgent()
        {
            while (!_connectionEnd.WaitOne(0) && !Connected)
            {
                try
                {
                    URL url = new URL(_OpcSection.Server.Name);
                    _Server = new Opc.Da.Server(new OpcCom.Factory(), null);
                    _Server.Connect(url, new ConnectData(new NetworkCredential()));

                    _groupRead  = (Subscription)_Server.CreateSubscription(_GroupReadState);
                    _groupWrite = (Subscription)_Server.CreateSubscription(_GroupWriteState);

                    for (int i = 0; i < _OpcSection.Server.TagGroup.GetElement(_TagGroup).Tags.Count; i++)
                    {
                        _Items[i] = new Opc.Da.Item();
                        //_Items[i].ItemName = String.Format("{0}{1}", _OpcSection.Server.Channel, _OpcSection.Server.TagGroup.GetElement(_TagGroup).Tags[i].Name);
                        _Items[i].ItemName = _OpcSection.Server.Channel + "." + _OpcSection.Server.Device + "." + _OpcSection.Server.TagGroup.GetElement(_TagGroup).Tags[i].Name;
                        //string itmNam = String.Format("{0}]{1}", _OpcSection.Server.Channel, _OpcSection.Server.TagGroup.GetElement(_TagGroup).Tags[i].Name);
                        _logger.LogInfo(/*Mtd*/ ": recognized element " + _Items[i].ItemName);
                    }
                    _Items = _groupRead.AddItems(_Items);
                    _groupRead.DataChanged += new DataChangedEventHandler(Group_DataChanged);
                }
                catch (Exception ex) { _logger.LogError(ex); }
            }
        }
示例#3
0
        private void SearchAgent()
        {
            _ObjectLines = new List <DataInfo>();
            int airLines       = 0;
            int emptyScanLines = 0;

            while (!_searchEnd.WaitOne(0))
            {
                try
                {
                    DataInfo dataInfo = _inComingDataColl.Take(_searchCancel.Token);
                    if (_ObjectLines.Count == AppConfiguration.NumberOfLinesForStartOfObject)
                    {
                        _dataAccess.StartCaseManagerScan();
                        _ObjectLines.Add(dataInfo);

                        _log.LogInfo("Found Start of Object");
                        _foundObject   = true;
                        emptyScanLines = 0;
                    }
                    else if (IsObjectLine(dataInfo))
                    {
                        _ObjectLines.Add(dataInfo);
                    }
                    else if (_ObjectLines.Count < AppConfiguration.NumberOfLinesForStartOfObject)
                    {
                        _ObjectLines.Clear();

                        if (++emptyScanLines > AppConfiguration.XrayOffLineThreshold && _foundObject)
                        {
                            _log.LogInfo("No object found for " + emptyScanLines + " lines, forcing STOP");
                            emptyScanLines = 0;
                            _dataAccess.StopScan();
                        }
                    }
                    else if (++airLines > AppConfiguration.NumberofLinesForEndOfObject)
                    {
                        DataComplete(true);
                        _log.LogInfo("Found End of Object");
                        airLines = 0;
                    }
                    else
                    {
                        _ObjectLines.Add(dataInfo);
                    }
                    _dataAccess.RealTimeViewer.AddDataLine(ref dataInfo);
                }
                catch (Exception ex)
                {
                    // this will re initialize the CORBA connection
                    _dataAccess.CargoHostEndPoint.RebindToNameService();
                    if (!_searchEnd.WaitOne(0))
                    {
                        _log.LogError(ex);
                    }
                }
            }
        }
示例#4
0
        protected void SendStatusUpdate()
        {
            try
            {
                List <string> errorMessages   = new List <string>();
                List <string> warningMessages = new List <string>();
                string        color           = IndicatorColors.Clear;

                lock (_StatusLock)
                {
                    foreach (StatusElement statusElement in _Statuses)
                    {
                        try
                        {
                            if (statusElement.Type.Contains(TagTypes.Status))
                            {
                                if (String.Compare(statusElement.StatusType, TagValueTypes.Error, true) == 0)
                                {
                                    errorMessages.Add(statusElement.Message);
                                    if (string.Compare(color, IndicatorColors.Unknown, true) != 0)
                                    {
                                        color = IndicatorColors.Error;
                                    }
                                }
                                else if (String.Compare(statusElement.StatusType, TagValueTypes.Warning, true) == 0)
                                {
                                    warningMessages.Add(statusElement.Message);
                                    if (string.Compare(color, IndicatorColors.Clear, true) == 0)
                                    {
                                        color = IndicatorColors.Warning;
                                    }
                                }
                                else if (String.Compare(statusElement.StatusType, TagValueTypes.Unknown, true) == 0)
                                {
                                    errorMessages.Clear();
                                    warningMessages.Clear();
                                    color = IndicatorColors.Unknown;
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.LogError(ex);
                        }
                    }
                }

                DataAccess.UpdateStatusErrorMessages(errorMessages.ToArray());
                DataAccess.UpdateStatusWarningMessages(warningMessages.ToArray());
                DataAccess.UpdateStatusIndicator(color);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
        }
示例#5
0
 public void StartUp()
 {
     try
     {
         _SubsystemServices.StartUp();
     }
     catch (Exception ex)
     {
         _Logger.LogError(ex);
     }
 }
示例#6
0
        public int GetTagValue(string name)
        {
            int value = -1;

            try
            {
                value = _OpcClient.ReadValue(name);
            }
            catch (Exception exp)
            {
                _logger.LogError(exp);
            }

            return(value);
        }
示例#7
0
        private void SendAgent()
        {
            while (!_sendEnd.WaitOne(0))
            {
                try
                {
                    DataInfo dataInfo = _inComingDataColl.Take(_sendCancel.Token);
                    if ((IsDualEnergy && dataInfo.XRayInfo.Energy == XRayEnergyEnum.HighEnergy) || !IsDualEnergy)
                    {
                        byte[] scaledData = new byte[dataInfo.LineData.Length / AppConfiguration.RealTimeViewerPixelInterval];

                        Parallel.For(0, scaledData.Length, i =>
                        {
                            scaledData[i] = (byte)(dataInfo.LineData[i * AppConfiguration.RealTimeViewerPixelInterval].Value >> 8);
                        });

                        _realTimeViewerHost.SendData(scaledData);
                    }
                }
                catch (Exception exp)
                {
                    if (!_sendEnd.WaitOne(0))
                    {
                        _log.LogError(exp);
                    }
                }
            }
        }
示例#8
0
        private void NormalizeAgent()
        {
            double MaxValue = Math.Pow(Byte.MaxValue + 1, AppConfiguration.BytesPerPixel) - 1.0;

            while (!_normalizeEnd.WaitOne(0))
            {
                try
                {
                    DataInfo dataInfo = _rawDataColl.Take(_normalizeCancel.Token);
                    if (AppConfiguration.NormalizeRawData)
                    {
                        Pixel[] airData         = _calibration.GetAirData(dataInfo.XRayInfo);
                        Pixel[] darkData        = _calibration.GetDarkData(dataInfo.XRayInfo);
                        float[] scaleFactorData = _calibration.GetScaleFactor(dataInfo.XRayInfo);

                        double refFactorValue = (AppConfiguration.EnableReferenceCorrection) ? ReferenceFactor(dataInfo.LineData, airData, darkData) : 1.0;
                        _calibration.AddReferenceCorrection(dataInfo.XRayInfo, refFactorValue);
                        int numReferenceDetectors = _dataAccess.Detectors.GetNumberReferencePixels();

                        // Normalize all of the data;
                        Parallel.For(0, dataInfo.LineData.Length, i =>
                        {
                            double tempValue           = (Math.Max((double)dataInfo.LineData[i].Value - (double)darkData[i].Value, 0) * scaleFactorData[i] * refFactorValue);
                            dataInfo.LineData[i].Value = (uint)Math.Min(tempValue, MaxValue);
                        });

                        for (int i = 0; i < 32; i++)
                        {
                            if (i < (AppConfiguration.ReferenceRangeLowerDetectorNum - 1) && i > (AppConfiguration.ReferenceRangeUpperDetectorNum + 1))
                            {
                                dataInfo.LineData[i].Value = (uint)AppConfiguration.NormConstant;
                            }
                        }

                        // Correct for bad detectors
                        if (AppConfiguration.CorrectForBadDetectors)
                        {
                            foreach (int index in _calibration.BadDetectorsList)
                            {
                                int correctedIndex = (index > 0) ? index - 1 : index + 1;
                                dataInfo.LineData[index].Value = dataInfo.LineData[correctedIndex].Value;
                            }
                        }
                    }

                    _objectSearch.AddDataLine(ref dataInfo);
                }
                catch (Exception ex)
                {
                    if (!_normalizeCancel.IsCancellationRequested)
                    {
                        _log.LogError(ex);
                    }
                }
            }
        }
示例#9
0
 protected virtual void ProcessControlUpdateRequest(string name, int value)
 {
     try
     {
         _DataAccess.UpdatePLCTagValue(name, value);
     }
     catch (Exception ex)
     {
         _Logger.LogError(ex);
     }
 }
示例#10
0
 private void ClosingArea_MouseOrTouchDown(object sender, RoutedEventArgs e)
 {
     try
     {
         CollapseNotifications();
     }
     catch (Exception ex)
     {
         _Logger.LogError(ex);
     }
 }
示例#11
0
        private void SendDataThreadMethod(object param)
        {
            //send resoultion information first
            _dataAccess.UpdateWidgets("REALTIME_VIEWER_RESOLUTION", (int)
                                      ((_realTimeViewerPixelsPerColumn << 16) | _realTimeViewerBytesPerPixel));

            int scaleValueBits = (int)((AppConfiguration.BytesPerPixel - _realTimeViewerBytesPerPixel) * 8);

            CancellationToken token = (CancellationToken)param;

            while (!token.IsCancellationRequested)
            {
                try
                {
                    DataInfo dataInfo = _inComingDataColl.Take(token);

                    //if (_dataAccess.Detectors.PixelPerColumn != _realTimeViewerPixelsPerColumn)
                    if (AppConfiguration.BytesPerPixel != _realTimeViewerBytesPerPixel)
                    {
                        //downscale data to reduce bandwidth
                        byte[] downscaledData      = new byte[_realTimeViewerPixelsPerColumn * _realTimeViewerBytesPerPixel];
                        int    downscaledDataIndex = 0;

                        for (int index = 0; index < dataInfo.LineData.Length; index++)
                        {
                            if ((index % _pixelInterval) == 0)
                            {
                                uint[] value = new uint[1];
                                value[0] = dataInfo.LineData[index].Value >> scaleValueBits;
                                Buffer.BlockCopy(value, 0, downscaledData, downscaledDataIndex, (int)_realTimeViewerBytesPerPixel);
                                downscaledDataIndex += (int)_realTimeViewerBytesPerPixel;
                            }
                        }

                        _realTimeViewerHost.SendData(downscaledData);
                    }
                    else
                    {
                        _realTimeViewerHost.SendData(dataInfo.LineData, (uint)AppConfiguration.BytesPerPixel);
                    }
                }
                catch (Exception exp)
                {
                    if (!token.IsCancellationRequested)
                    {
                        _log.LogError(exp);
                    }
                }
            }
        }
示例#12
0
    /// <summary>
    /// CreateCase.  This interface function Creates new Case using container id
    ///
    ///	Arguments:
    ///		containerid: The container id
    ///	Exceptions:
    ///		none
    ///	Return:
    ///		Caseid
    /// </summary>
    public string CreateCase(string containerid)
    {
        string caseid = null;

        try
        {
            //m_XRayHost = GetXrayHost();
            caseid = _cargoHostEndPoint.CreateInitAreaCase();
            //caseid = m_XRayHost.makeCase(containerid);
            XCase currentCase = _cargoHostEndPoint.GetCase(caseid);
            currentCase.setContainerId(containerid);
        }
        catch (Exception e1)
        {
            _logger.LogError("OM - " + e1.Message);
        }

        return(caseid);
    }
示例#13
0
        public string CreatePXEFile(LINAC_ENERGY_TYPE_VALUE energy, PulseWidth pulseWidth, List <DataInfo> ObjectLines)
        {
            lock (_writeLock)
            {
                string pxeFile = Path.Combine(AppConfiguration.HostTempFileLocation, DateTime.Now.ToString(_dateFormat) + _pxeExtension);
                _pxeWriteAccess.CreatePXE(pxeFile);

                try
                {
                    List <Pixel[]>   highEnergyLines = new List <Pixel[]>();
                    List <Pixel[]>   lowEnergyLines  = new List <Pixel[]>();
                    XRayInfoIDStruct highEnergyInfo  = default(XRayInfoIDStruct);
                    XRayInfoIDStruct lowEnergyInfo   = default(XRayInfoIDStruct);

                    if (energy == LINAC_ENERGY_TYPE_VALUE.Dual)
                    {
                        if (ObjectLines[0].XRayInfo.Energy == XRayEnergyEnum.HighEnergy)
                        {
                            ObjectLines.RemoveAt(0);
                        }
                    }

                    //store object line data
                    foreach (DataInfo dataLine in ObjectLines)
                    {
                        if (dataLine.XRayInfo.Energy == XRayEnergyEnum.HighEnergy)
                        {
                            highEnergyLines.Add(dataLine.LineData);
                            highEnergyInfo = dataLine.XRayInfo;
                        }
                        else //low energy
                        {
                            lowEnergyLines.Add(dataLine.LineData);
                            lowEnergyInfo = dataLine.XRayInfo;
                        }
                    }

                    int maxLength = Math.Min(lowEnergyLines.Count, highEnergyLines.Count);

                    if (maxLength == 0)
                    {
                        maxLength = Math.Max(lowEnergyLines.Count, highEnergyLines.Count);
                    }

                    if (maxLength > AppConfiguration.MaxPXEWidth)
                    {
                        maxLength = AppConfiguration.MaxPXEWidth;
                    }

                    if (energy != LINAC_ENERGY_TYPE_VALUE.Low && highEnergyLines.Count > 0)
                    {
                        int bufferSize = maxLength * highEnergyLines[0].Length;

                        if (bufferSize > 0)
                        {
                            float[] buffer = new float[bufferSize];
                            Parallel.For(highEnergyLines.Count - maxLength, maxLength, index =>
                            {
                                float[] pixelArray = PixelConverter.Convert(highEnergyLines[index]);
                                int length         = Buffer.ByteLength(pixelArray);
                                Buffer.BlockCopy(pixelArray, 0, buffer, index * length, length);
                            });


                            if (energy == LINAC_ENERGY_TYPE_VALUE.Dual)
                            {
                                _pxeWriteAccess.CreateHiPXEHeader((uint)maxLength, (uint)highEnergyLines[0].Length);
                                _pxeWriteAccess.WriteHiDataLines(buffer, (uint)maxLength);
                                _pxeWriteAccess.WriteHighEngDarkSample(PixelConverter.Convert(_calibration.GetDarkData(highEnergyInfo)));
                                _pxeWriteAccess.WriteHighEngAirSample(PixelConverter.Convert(_calibration.GetAirData(highEnergyInfo)));

                                if (AppConfiguration.StoreReferenceCorrection)
                                {
                                    _pxeWriteAccess.WriteHiRef(_calibration.GetReferenceCorrections(highEnergyInfo));
                                }

                                if (AppConfiguration.StoreScaleFactor)
                                {
                                    _pxeWriteAccess.WriteHiScaleFactor(_calibration.GetScaleFactor(highEnergyInfo));
                                }

                                if (AppConfiguration.StoreAirDarkSamples)
                                {
                                    _pxeWriteAccess.WriteHiFullAirData(PixelConverter.Convert(_calibration.GetAirDataCollection(highEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                    _pxeWriteAccess.WriteHiFullDarkData(PixelConverter.Convert(_calibration.GetDarkDataCollection(highEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                }
                            }
                            else
                            {
                                _pxeWriteAccess.CreateHiPXEHeader((uint)maxLength, (uint)highEnergyLines[0].Length);
                                _pxeWriteAccess.WriteHiDataLines(buffer, (uint)maxLength);
                                _pxeWriteAccess.WriteHighEngDarkSample(PixelConverter.Convert(_calibration.GetDarkData(highEnergyInfo)));
                                _pxeWriteAccess.WriteHighEngAirSample(PixelConverter.Convert(_calibration.GetAirData(highEnergyInfo)));

                                if (AppConfiguration.StoreReferenceCorrection)
                                {
                                    _pxeWriteAccess.WriteHiRef(_calibration.GetReferenceCorrections(highEnergyInfo));
                                }

                                if (AppConfiguration.StoreScaleFactor)
                                {
                                    _pxeWriteAccess.WriteHiScaleFactor(_calibration.GetScaleFactor(highEnergyInfo));
                                }

                                if (AppConfiguration.StoreAirDarkSamples)
                                {
                                    _pxeWriteAccess.WriteHiFullAirData(PixelConverter.Convert(_calibration.GetAirDataCollection(highEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                    _pxeWriteAccess.WriteHiFullDarkData(PixelConverter.Convert(_calibration.GetDarkDataCollection(highEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                }
                            }
                        }

                        highEnergyLines.Clear();
                    }

                    if (energy != LINAC_ENERGY_TYPE_VALUE.High && lowEnergyLines.Count > 0)
                    {
                        int bufferSize = maxLength * lowEnergyLines[0].Length;

                        if (bufferSize > 0)
                        {
                            float[] buffer = new float[bufferSize];
                            Parallel.For(0, maxLength, index =>
                            {
                                float[] pixelArray = PixelConverter.Convert(lowEnergyLines[index]);
                                int length         = Buffer.ByteLength(pixelArray);
                                Buffer.BlockCopy(pixelArray, 0, buffer, index * length, length);
                            });

                            if (energy == LINAC_ENERGY_TYPE_VALUE.Dual)
                            {
                                _pxeWriteAccess.CreateLoPXEHeader((uint)maxLength, (uint)lowEnergyLines[0].Length);
                                _pxeWriteAccess.WriteLoDataLines(buffer, (uint)maxLength);
                                _pxeWriteAccess.WriteLowEngDarkSample(PixelConverter.Convert(_calibration.GetDarkData(lowEnergyInfo)));
                                _pxeWriteAccess.WriteLowEngAirSample(PixelConverter.Convert(_calibration.GetAirData(lowEnergyInfo)));

                                if (AppConfiguration.StoreReferenceCorrection)
                                {
                                    _pxeWriteAccess.WriteLoRef(_calibration.GetReferenceCorrections(lowEnergyInfo));
                                }

                                if (AppConfiguration.StoreScaleFactor)
                                {
                                    _pxeWriteAccess.WriteLoScaleFactor(_calibration.GetScaleFactor(lowEnergyInfo));
                                }

                                if (AppConfiguration.StoreAirDarkSamples)
                                {
                                    _pxeWriteAccess.WriteLoFullAirData(PixelConverter.Convert(_calibration.GetAirDataCollection(lowEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                    _pxeWriteAccess.WriteLoFullDarkData(PixelConverter.Convert(_calibration.GetDarkDataCollection(lowEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                }
                            }
                            else
                            {
                                _pxeWriteAccess.CreateLoPXEHeader((uint)maxLength, (uint)lowEnergyLines[0].Length);
                                _pxeWriteAccess.WriteLoDataLines(buffer, (uint)maxLength);
                                _pxeWriteAccess.WriteLowEngDarkSample(PixelConverter.Convert(_calibration.GetDarkData(lowEnergyInfo)));
                                _pxeWriteAccess.WriteLowEngAirSample(PixelConverter.Convert(_calibration.GetAirData(lowEnergyInfo)));

                                if (AppConfiguration.StoreReferenceCorrection)
                                {
                                    _pxeWriteAccess.WriteLoRef(_calibration.GetReferenceCorrections(lowEnergyInfo));
                                }

                                if (AppConfiguration.StoreScaleFactor)
                                {
                                    _pxeWriteAccess.WriteLoScaleFactor(_calibration.GetScaleFactor(lowEnergyInfo));
                                }

                                if (AppConfiguration.StoreAirDarkSamples)
                                {
                                    _pxeWriteAccess.WriteLoFullAirData(PixelConverter.Convert(_calibration.GetAirDataCollection(lowEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                    _pxeWriteAccess.WriteLoFullDarkData(PixelConverter.Convert(_calibration.GetDarkDataCollection(lowEnergyInfo)), Convert.ToUInt32(AppConfiguration.CalibrationDataLines));
                                }
                            }
                        }

                        lowEnergyLines.Clear();
                    }
                }
                catch { }

                try
                {
                    _pxeWriteAccess.ClosePXEWrite();
                }
                catch (Exception e)
                {
                    _log.LogError("Exception closing PXEWrite.");
                    _log.LogError(e.GetType().ToString() + ": " + e.Message);
                    _log.LogError(e.StackTrace);
                }
                return(pxeFile);
            }
        }
示例#14
0
 private void InitializeDisplay()
 {
     try
     {
         BackgroundWorker backgroundWorker = new BackgroundWorker();
         backgroundWorker.DoWork             += new DoWorkEventHandler(SetupDisplay);
         backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(SetupDisplayCompleted);
         backgroundWorker.RunWorkerAsync();
     }
     catch (Exception ex)
     {
         _Logger.LogError(ex);
     }
 }
示例#15
0
        private void ReceivedOCR_MASTER(object messageObj, string msgName)
        {
            L3.Cargo.OCR.Messages.ocr_master.message master_msg = (Messages.ocr_master.message)messageObj;

            string[] rootCaseID = new string[10];
            int      itemCount  = 0;

            try
            {
                WriteLogMessage(msgName);

                if (string.IsNullOrEmpty(master_msg.body.payload.CaseNumber))
                {   // Message contains no case ID, create a new case for
                    // the message.

                    int i = 0;

                    for (; i < master_msg.body.payload.Cont.Length; i++)
                    {
                        rootCaseID[i] = m_cargoHostIF.CreateCase(master_msg.body.payload.Cont[i].Code);
                        itemCount++;
                    }

                    if (String.IsNullOrEmpty(rootCaseID[0]))
                    {
                        for (; i < master_msg.body.payload.Trailer.Length; i++)
                        {
                            rootCaseID[i] = m_cargoHostIF.CreateCase(master_msg.body.payload.Trailer[i].Code);
                            itemCount++;
                        }
                    }

                    if (String.IsNullOrEmpty(rootCaseID[0]))
                    {
                        rootCaseID[i] = m_cargoHostIF.CreateCase(master_msg.body.payload.Vehicle.Code);
                        itemCount++;
                    }
                }
                else
                {   // Extract the case ID from the message.
                    m_cargoHostIF.SetContainerNumber(rootCaseID[0], master_msg.body.payload.Cont[0].Code);

                    string [] caseList = m_cargoHostIF.GetScanCaseList();

                    if (caseList != null && caseList.Length > 0)
                    {
                        int j = 1;

                        for (int i = 0; i < caseList.Length; i++)
                        //foreach (string caseid in caseList)
                        {
                            if (caseList[i].CompareTo(rootCaseID) == 0)
                            {
                                if (i <= caseList.Length)
                                {
                                    rootCaseID[j] = caseList[i];
                                    m_cargoHostIF.SetContainerNumber(rootCaseID[j], master_msg.body.payload.Cont[j].Code);
                                    j++;
                                }
                                else
                                {
                                    for (; j < master_msg.body.payload.Cont.Length; j++)
                                    {
                                        rootCaseID[j] = m_cargoHostIF.CreateCase(master_msg.body.payload.Cont[j].Code);
                                    }
                                }
                            }

                            break;
                        }
                    }
                }

                try
                {   // ==> Add Manifest(s) to Case
                    for (int id = 0; id < master_msg.body.payload.Cont.Length; id++)
                    {
                        try
                        {
                            if (!String.IsNullOrEmpty(master_msg.body.payload.Cont[id].Code))
                            {
                                m_cargoHostIF.AddManifest(master_msg.body.payload.Cont[id].Code, rootCaseID[id]);
                            }
                        }
                        catch (System.NullReferenceException)
                        {
                            // Container Object was not created after
                            // deserializing object. Don't worry about
                            // it, press on.
                        }
                        catch (CargoException)
                        {
                            // Error with logger
                        }
                    }
                }   // <== Add Manifest(s) to Case
                catch (System.NullReferenceException)
                {
                    // Container Object was not created after
                    // deserializing object. Don't worry about it,
                    // press on.
                }

                try
                {   // ==> Add per-container OCR file(s) to case
                    for (int id = 0; id < master_msg.body.payload.Cont.Length; id++)
                    {
                        try
                        {
                            if (File.Exists(master_msg.body.payload.Cont[id].FileName))
                            {
                                string basePath = @"C:\Temp\";
                                if (master_msg.body.payload.Cont[id].FileName.EndsWith(".zip", false, null))
                                {
                                    ZipFile zf = new ZipFile(master_msg.body.payload.Cont[id].FileName);

                                    foreach (ZipEntry ze in zf)
                                    {
                                        if (ze.FileName.EndsWith(".jpg", false, null))
                                        {
                                            ze.Extract(basePath);
                                            m_cargoHostIF.AddOCRFile(rootCaseID[id], basePath + ze.FileName);
                                        }
                                    }

                                    zf.Dispose();
                                }
                                else
                                {
                                    m_cargoHostIF.AddOCRFile(rootCaseID[id], master_msg.body.payload.Cont[id].FileName);
                                }
                            }
                        }
                        catch (System.NullReferenceException)
                        {
                            // Container Object was not created after
                            // deserializing object. Don't worry about
                            // it, press on.
                        }
                        catch (CargoException)
                        {
                            // Error with logger
                        }
                    }
                }   // <== Add per-container OCR file(s) to case
                catch (System.NullReferenceException)
                {
                    // Container Object was not created after
                    // deserializing object. Don't worry about it, press
                    // on.
                }

                try
                {   // ==> Add per-trailer OCR file(s) to case
                    for (int id = 0; id < master_msg.body.payload.Trailer.Length; id++)
                    {
                        try
                        {
                            if (File.Exists(master_msg.body.payload.Trailer[id].FileName))
                            {
                                string basePath = @"C:\Temp\";

                                if (master_msg.body.payload.Trailer[id].FileName.EndsWith(".zip", false, null))
                                {
                                    ZipFile zf = new ZipFile(master_msg.body.payload.Trailer[id].FileName);

                                    foreach (ZipEntry ze in zf)
                                    {
                                        if (ze.FileName.EndsWith(".jpg", false, null))
                                        {
                                            ze.Extract(basePath);
                                            m_cargoHostIF.AddOCRFile(rootCaseID[id], basePath + ze.FileName);
                                        }
                                    }

                                    zf.Dispose();
                                }
                                else
                                {
                                    m_cargoHostIF.AddOCRFile(rootCaseID[id], master_msg.body.payload.Trailer[id].FileName);
                                }
                            }
                        }
                        catch (System.NullReferenceException)
                        {
                            // Container Object was not created after
                            // deserializing object. Don't worry about
                            // it, press on.
                        }
                        catch (CargoException)
                        {
                            // Error with logger
                        }
                    }
                }   // <== Add per-trailer OCR file(s) to case
                catch (System.NullReferenceException)
                {
                    // Container Object was not created after
                    // deserializing object. Don't worry about it, press
                    // on.
                }

                try
                {   // ==> Add vehicle OCR file to case
                    if (File.Exists(master_msg.body.payload.Vehicle.FileName))
                    {
                        string basePath = @"C:\Temp\";

                        if (master_msg.body.payload.Vehicle.FileName.EndsWith(".zip", false, null))
                        {
                            ZipFile zf = new ZipFile(master_msg.body.payload.Vehicle.FileName);

                            foreach (ZipEntry ze in zf)
                            {
                                if (ze.FileName.EndsWith(".jpg", false, null))
                                {
                                    ze.Extract(basePath);
                                    m_cargoHostIF.AddOCRFile(rootCaseID[0], basePath + ze.FileName);
                                }
                            }

                            zf.Dispose();
                        }
                        else
                        {
                            m_cargoHostIF.AddOCRFile(rootCaseID[0], master_msg.body.payload.Vehicle.FileName);
                        }
                    }
                }   // <== Add vehicle OCR file to case
                catch (System.NullReferenceException)
                {
                    // Container Object was not created after
                    // deserializing object. Don't worry about it, press
                    // on.
                }
                catch (CargoException)
                {
                    // Error with logger
                }
            }
            catch (Exception ex)
            {
                try
                {
                    _logger.LogError("OCRMonitor ReceivedOCR_MASTER - " + ex.Message);
                }
                catch (CargoException)
                {
                    // Error with logger
                }
            }
        }
示例#16
0
        private void DataAckThreadMethod()
        {
            int length = Marshal.SizeOf(typeof(LinacPacketFormat.CommandPacket));

            byte[] command  = new byte[length];
            int    dataRead = 0;

            while (!_shutdown)
            {
                while (!IsConnected && !_shutdown)
                {
                    try
                    {
                        _tcpClient = new TcpClient(_address, _port);

                        _pingTimer = new Timer(new TimerCallback(CheckConnection), null, _pingDueTimeMsec, _pingDueTimeMsec);

                        _networkStream             = _tcpClient.GetStream();
                        _networkStream.ReadTimeout = -1;
                        IsConnected = true;
                        _logger.LogInfo("Connected to Linac.");
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e);
                        Thread.Sleep(2000);
                    }
                }

                try
                {
                    while (!_shutdown && IsConnected)
                    {
                        try
                        {
                            //read command
                            dataRead = _networkStream.Read(command, 0, command.Length);

                            if (dataRead <= 0)
                            {
                                if (!_shutdown)
                                {
                                    _logger.LogInfo("Disconnected from Linac: Zero bytes read");
                                }
                                IsConnected = false;
                                _networkStream.Close();
                                _logger.LogInfo("Disconnected from Linac");
                                break;
                            }
                            else
                            {
                                ProcessCommand(command, dataRead);
                            }
                        }
                        catch (IOException)
                        {
                            // This even can be used to clear all values on a disconnection
                            if (ProcessCommandEvent != null)
                            {
                                ProcessCommandEvent(null);
                            }
                            if (_flushNetworkStream)
                            {
                                if (_networkStream.DataAvailable)
                                {
                                    StackTrace stackTrace = new StackTrace(true);
                                    _logger.LogError("Flushing network stream",
                                                     stackTrace);
                                }
                                while (_networkStream.DataAvailable)
                                {
                                    byte[] dummyBuffer = new byte[256];
                                    _networkStream.Read(dummyBuffer, 0, dummyBuffer.Length);
                                }
                                _flushNetworkStream = false;
                                _FlushingNetworkDoneEvent.Set();
                            }
                            IsConnected = false;
                            _networkStream.Close();
                            _logger.LogInfo("Disconnected from Linac");
                        }
                        catch (ObjectDisposedException exp)
                        {
                            _logger.LogError(exp);
                            IsConnected = false;
                            _networkStream.Close();
                            _logger.LogInfo("Disconnected from Linac");
                        }
                    }
                }
                catch (Exception exp)
                {
                    //connection error, try to connect again.
                    _logger.LogError(exp);
                    _logger.LogInfo("Exception in LinacAccess: " + exp.StackTrace);
                }
            }
        }
示例#17
0
        private void ProcessDataThreadMethod()
        {
            bool wasRunning         = false;
            bool waitingForXRaysOff = false;
            int  airDataCount       = 0;

            while (!_processEnd.WaitOne(0))
            {
                try
                {
                    DataInfo dataInfo = _dataAccess.Detectors.RawDataCollection.Take(_processCancel.Token);
                    _dataAccess.RawDataAccess.AddDataLine(ref dataInfo);
                    int calibrationLinesNeeded = AppConfiguration.CalibrationDataLines * ((_dataAccess.OpcTags.LINAC_ENERGY_TYPE.Value == LINAC_ENERGY_TYPE_VALUE.Dual) ? 2 : 1);

                    if (AppConfiguration.CalibrationMode == AppConfiguration.CalibrationModeEnum.Inline)
                    {
                        // calibrate at the start of a scan
                        if (_dataAccess.OpcTags.LINAC_STATE.Value == LINAC_STATE_VALUE.XRaysOn && airDataCount < calibrationLinesNeeded)
                        {
                            airDataCount++;
                            _calibration.AddAirDataLine(dataInfo);
                        }
                        else if (_dataAccess.OpcTags.LINAC_STATE.Value == LINAC_STATE_VALUE.XRaysOn)
                        {
                            _normalize.AddDataLine(dataInfo);
                            wasRunning = true;
                        }
                        else if (wasRunning)
                        {
                            airDataCount = 0;
                            wasRunning   = false;
                            _normalize.DataComplete();
                        }
                        else if (!_dataAccess.OpcTags.START_SCAN.Value)
                        {
                            _calibration.AddDarkDataLine(dataInfo);
                        }
                    }
                    else if (AppConfiguration.CalibrationMode == AppConfiguration.CalibrationModeEnum.Persistent)
                    {
                        // persistent calibration. Calibration is done on user command and used for subsequent scans
                        if (_dataAccess.OpcTags.CALIBRATION_SCAN.Value && _calibration.IsCalibrationRunning())
                        {
                            _calibration.AddDataLine(dataInfo);
                            wasRunning = false;
                        }
                        else if (_dataAccess.OpcTags.LINAC_STATE.Value == LINAC_STATE_VALUE.XRaysOn && !_dataAccess.OpcTags.CALIBRATION_SCAN.Value)
                        {
                            _normalize.AddDataLine(dataInfo);
                            wasRunning = true;
                        }
                        else if (wasRunning)
                        {
                            wasRunning = false;
                            _normalize.DataComplete();
                            _log.LogInfo("Force End of Object");
                        }
#if false
                        else if (_dataAccess.OpcTags.CALIBRATION_SCAN.Value && _calibration.IsCalibrationRunning() == false)
                        {
                        }
                        else if (_dataAccess.OpcTags.CALIBRATION_SCAN.Value == false && _calibration.IsCalibrationRunning() == false)
                        {
                            wasRunning = false;
                        }
                        else if (_dataAccess.OpcTags.LINAC_STATE.Value == LINAC_STATE_VALUE.XRaysOn)
                        {
                            _normalize.AddDataLine(dataInfo);
                            wasRunning = true;
                        }
                        else if (wasRunning && (_dataAccess.OpcTags.LINAC_STATE.Value == LINAC_STATE_VALUE.XraysOff ||
                                                _dataAccess.OpcTags.LINAC_STATE.Value == LINAC_STATE_VALUE.ReadyForHVonCommand))
                        {
                            wasRunning = false;
                            _normalize.DataComplete();
                            _log.LogInfo("&&&&&&&&&&&&&&&&&&&&&&&&&&&");
                        }
#endif
                    }
                    else if (AppConfiguration.CalibrationMode == AppConfiguration.CalibrationModeEnum.InlineStandstill)
                    {
                        if (wasRunning == false &&
                            _dataAccess.OpcTags.SCAN_AREA_CLEAR.Value &&
                            airDataCount < calibrationLinesNeeded &&
                            _dataAccess.OpcTags.LINAC_STATE.Value != LINAC_STATE_VALUE.XRaysOn)
                        {
                            //_log.LogInfo("Enabling X-rays for calibration.");
                            _dataAccess.SetHostStopScanValue(true);
                            _dataAccess.EnableXray(true);
                        }
                        // calibrate at the start of a scan
                        else if (_dataAccess.OpcTags.LINAC_STATE.Value == LINAC_STATE_VALUE.XRaysOn &&
                                 airDataCount < calibrationLinesNeeded)
                        {
                            if (!_dataAccess.OpcTags.HOST_STOP_SCAN.Value)
                            {
                                // prevent the user from scanning while the air data is being collected
                                //_log.LogInfo("Beginning air data collection. Setting HOST_STOP_SCAN true.");
                                _dataAccess.SetHostStopScanValue(true);
                            }
                            else
                            {
                                // collect air data
                                airDataCount++;
                                _calibration.AddAirDataLine(dataInfo);

                                if (airDataCount == calibrationLinesNeeded)
                                {
                                    _log.LogInfo("Air data complete, disabling X-rays.");
                                    _dataAccess.SetHostStopScanValue(false);
                                    _dataAccess.EnableXray(false);
                                    waitingForXRaysOff = true;
                                }
                            }
                        }
                        else if (_dataAccess.OpcTags.LINAC_STATE.Value == LINAC_STATE_VALUE.XRaysOn && waitingForXRaysOff == true)
                        {
                            // do nothing
                        }
                        else if (_dataAccess.OpcTags.LINAC_STATE.Value != LINAC_STATE_VALUE.XRaysOn && waitingForXRaysOff == true)
                        {
                            waitingForXRaysOff = false;
                        }
                        else if (_dataAccess.OpcTags.LINAC_STATE.Value == LINAC_STATE_VALUE.XRaysOn)
                        {
                            _normalize.AddDataLine(dataInfo);
                            wasRunning = true;
                        }
                        else if (wasRunning)
                        {
                            airDataCount = 0;
                            wasRunning   = false;
                            _normalize.DataComplete();
                        }
                        else if (!_dataAccess.OpcTags.START_SCAN.Value)
                        {
                            _calibration.AddDarkDataLine(dataInfo);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (!_processEnd.WaitOne(0))
                    {
                        _log.LogError(ex);
                    }
                }
            }
        }
示例#18
0
 private void FrameWork_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         _AdornerLayerManager.Add(_StatusInfoDisplay.GetType().Name, _StatusAdorner);
         _AdornerLayerManager.Show(_StatusAdorner);
         _AdornerLayerManager.Show(_AboutAdorner);
     }
     catch (Exception ex)
     {
         _Logger.LogError(ex);
         throw ex;
     }
 }
示例#19
0
        private void ListenForServices()
        {
            HostDiscovery serviceDiscovery = new HostDiscovery(typeof(ISubsystem), new TimeSpan(0, 0, 0, 2, 0));

            while (!_Shutdown)
            {
                try
                {
                    Collection <EndpointDiscoveryMetadata> sourceEndpoints = serviceDiscovery.GetAvailableConnections();

                    if (sourceEndpoints.Count > 0)
                    {
                        for (int index = 0; index < sourceEndpoints.Count; index++)
                        {
                            string           alias            = GetAlias(sourceEndpoints[index].Extensions);
                            string           assemblyTag      = GetAssemblyTag(sourceEndpoints[index].Extensions);
                            SubsystemService subsystemService = GetService(alias);

                            if (subsystemService == null)
                            {
                                subsystemService = AddSubsystem(alias, assemblyTag, sourceEndpoints[index].Address);

                                Thread assemblyThread = new Thread(new ParameterizedThreadStart(delegate
                                {
                                    GetAssembly(subsystemService);
                                }));
                                assemblyThread.IsBackground = true;
                                assemblyThread.Start();
                            }
                            else
                            {
                                subsystemService.CommCheckTimer.Change(_SubsystemCommTimeoutMsec, Timeout.Infinite);
                            }
                        }
                    }
                }
                catch (ThreadAbortException) { }
                catch (Exception ex)
                {
                    _Logger.LogError(ex);
                }
            }
        }