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); } } }
public BusinessManager(DetectorsDataAccess dataAccess, EventLoggerAccess log) { _dataAccess = dataAccess; _log = log; _statusManager = new DetectorsStatusManager(dataAccess, log); _requestManager = new RequestManager(dataAccess, (StatusManager)_statusManager, log); log.LogInfo("Using calibration: " + AppConfiguration.CalibrationMode.ToString()); if (AppConfiguration.CalibrationMode == AppConfiguration.CalibrationModeEnum.Inline) { _calibration = new CalibrationInline(log, _dataAccess, _statusManager); } else if (AppConfiguration.CalibrationMode == AppConfiguration.CalibrationModeEnum.Persistent) { _calibration = new CalibrationPersistent(log, _dataAccess, _statusManager); } else if (AppConfiguration.CalibrationMode == AppConfiguration.CalibrationModeEnum.InlineStandstill) { _calibration = new CalibrationInline(log, _dataAccess, _statusManager); } _normalize = new NormalizeData(log, dataAccess, _calibration); _processThread = Threads.Create(ProcessDataThreadMethod, ref _processEnd, "Business Data thread"); _processThread.Start(); }
public void Dispose() { if (_udpClient != null) { _logger.LogInfo(MethodBase.GetCurrentMethod().Name + ": exiting multicast group"); _udpClient.Close(); } }
private void UpdateStatusTag(string tagName, int value) { StatusElement statusElement = _Statuses.Find(tagName); statusElement.Value = value; _logger.LogInfo("*******" + tagName + " = " + statusElement.Value + " = , Actual Value = " + value); base.SendStatusUpdate(); }
public RealTimeViewerHost(string address, int dataPort, int udpClientPort, EventLoggerAccess logger) { _logger = logger; IPAddress multicastAddress = IPAddress.Parse(address); _udpClient = new UdpClient(udpClientPort); _udpClient.JoinMulticastGroup(multicastAddress); _udpClient.Ttl = 255; _udpClient.Connect(new IPEndPoint(multicastAddress, dataPort)); _logger.LogInfo(MethodBase.GetCurrentMethod().Name + ": joined multicast group " + multicastAddress.ToString() + ":" + udpClientPort.ToString()); }
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); } } } }
public MainWindow() { InitializeComponent(); _eventLoggerAccess = new EventLoggerAccess(); _eventLoggerAccess.LogMessageUpdate += new LogMessageUpdateHandler(LogMessage); _eventLoggerAccess.LogInfo("DetectorsApp Started"); _dataAccess = new DetectorsDataAccess(_eventLoggerAccess); _businessManager = new BusinessManager(_dataAccess, _eventLoggerAccess); _dataAccess.Connect(); CurrentLineIdTextBlk.DataContext = _dataAccess.Detectors; TestAPCS.Content = new TestAPCS(_dataAccess); TestNCB.Content = new TestNCB(_dataAccess, _businessManager); TestAPCS.Visibility = AppConfiguration.ShowDebugDisplays ? Visibility.Visible : Visibility.Collapsed; TestNCB.Visibility = TestAPCS.Visibility; }
public App() { bool createdNew = true; mutex = new Mutex(true, "Dashboard", out createdNew); if (createdNew) { if (Environment.GetCommandLineArgs().Length > 1) { foreach (string arg in Environment.GetCommandLineArgs()) { if (string.Compare(arg, "Operator", true) == 0 || string.Compare(arg, "Supervisor", true) == 0 || string.Compare(arg, "Maintenance", true) == 0 || string.Compare(arg, "Engineer", true) == 0) { ConfigurationManager.AppSettings["SystemOperationMode"] = arg; break; } } EventLoggerAccess logger = new EventLoggerAccess(); _UIManager = new UIManager(logger); _DataAccess = new DataAccess(logger); _AssemblyManager = new AssemblyManager(_UIManager, _DataAccess, logger); _DataAccess.StartUp(); _UIManager.Show(); logger.LogInfo("Dashboard Client Started"); } else { Application.Current.Shutdown(); } } else { Process current = Process.GetCurrentProcess(); foreach (Process process in Process.GetProcessesByName(current.ProcessName)) { SetForegroundWindow(process.MainWindowHandle); } Application.Current.Shutdown(); } }
public DetectorsDataAccess(EventLoggerAccess logger) : base(logger) { _logger = logger; _detectorsAccess = new DetectorsAccess(_logger); _detectorsAccess.ReadyEvent += new ConnectionStateChangeHandler(OnDetectorsChange); _apcsAccess = new ApcsAccess(logger); _apcsAccess.ReadyEvent += new ConnectionStateChangeHandler(OnApcsChange); _apcsAccess.Start(); _detectorsAccess.Start(); _OpcTags = new OpcTags(); base.TagUpdate += new PLCTagUpdateHandler(_OpcTags.DataAccess_TagUpdate); base.TagUpdate += new PLCTagUpdateHandler(DetectorsDataAccess_TagUpdate); _cargoHostEndPoint = new CargoHostEndPoint(AppConfiguration.CargoHostServer, AppConfiguration.CargoHostPort); _logger.LogInfo("Cargo Host HostEndPoint is " + _cargoHostEndPoint.IPAddress + ":" + _cargoHostEndPoint.IPPort.ToString()); _rawDataAccess = new RawDataAccess(_logger, _detectorsAccess); _realTimeViewer = new RealTimeViewer(_logger); }
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); } } } }
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); } } }