2 using System.Collections;
3 using System.Collections.Generic;
6 using System.Diagnostics;
7 using System.Runtime.InteropServices;
11 namespace Seci.Standard
25 public static class Dae
31 private static isisicpLib.dae
_icp;
34 private static float _updateRate = 1.0f;
80 public static String RunStatus {
get {
return _runStatus; } }
81 public static String RunNumber {
get {
return _runNumber; } }
82 public static String RbNumber {
get {
return _rbNumber; } }
83 public static String UserName {
get {
return _userName; } }
84 public static String RunTitle {
get {
return _runTitle; } }
85 public static String StartTime {
get {
return _startTime; } }
86 public static String RunDurationTotal {
get {
return _runDurationTotal; } }
87 public static String RunDurationPeriod {
get {
return _runDurationPeriod; } }
88 public static String GoodFramesTotal {
get {
return _goodFramesTotal; } }
89 public static String GoodFramesPeriod {
get {
return _goodFramesPeriod; } }
90 public static String RawFramesTotal {
get {
return _rawFramesTotal; } }
91 public static String RawFramesPeriod {
get {
return _rawFramesPeriod; } }
92 public static String CurrentPeriod {
get {
return _currentPeriod; } }
93 public static String NumberOfPeriods {
get {
return _numberOfPeriods; } }
94 public static String PeriodSequence {
get {
return _periodSequence; } }
95 public static String BeamCurrent {
get {
return _beamCurrent; } }
96 public static String TotalUAmps {
get {
return _totalUAmps; } }
97 public static String CountRate {
get {
return _countRate; } }
98 public static String DaeMemoryUsed {
get {
return _daeMemoryUsed; } }
99 public static String TotalDaeCounts {
get {
return _totalDaeCounts; } }
100 public static String DaeTimingSource {
get {
return _DaeTimingSource; } }
101 public static String MonitorCounts {
get {
return _monitorCounts; } }
102 public static String MonitorSpectrum {
get {
return _monitorSpectrum; } }
103 public static String MonitorFrom {
get {
return _monitorFrom; } }
104 public static String MonitorTo {
get {
return _monitorTo; } }
105 public static String NumberOfTimeChannels {
get {
return _numberOfTimeChannels; } }
106 public static String NumberOfSpectra {
get {
return _numberOfSpectra; } }
109 public static String FilePath {
get {
return _filePath; } set { _filePath = value; } }
110 internal static Boolean Visible {
get {
return _visible; } set { _visible = value; } }
111 internal static Boolean InWaitingState {
get {
return _inWaitingState; } set { _inWaitingState = value; } }
128 internal static void Initialise(String fileName)
130 _filePath = fileName;
134 _daeData = Seci.Properties.Resources.cluster;
145 LabView.LabViewApp.LoadVI(_filePath,
false);
148 LabView.LabViewApp.StartVI(_filePath);
158 _icp =
new isisicpLib.dae();
162 Helpers.ErrorLogger.SeciError(
"LoadDaeVI",
new Exception(
"Could not connect to DAE"));
176 procList = Process.GetProcessesByName(
"isisicp");
178 foreach (Process proc
in procList)
195 procList = Process.GetProcessesByName(
"isisdatasvr");
197 foreach (Process proc
in procList)
218 LabView.LabViewApp.ShowVI(_filePath);
226 LabView.LabViewApp.HideVI(_filePath);
235 LabView.LabViewApp.SetTitleBarVisibility(_filePath, visible);
242 internal static Boolean CheckDaeVIRunning()
244 return LabView.LabViewApp.IsVIRunning(_filePath);
251 internal static List<String> GetDaeControls()
253 return LabView.LabViewApp.GetListOfControls(_filePath);
263 LabView.LabViewApp.SetValue(_filePath,
"New Run Title", title);
265 LabView.LabViewApp.SetValue(_filePath,
"Set Title",
true);
274 internal static Boolean updateRunInformation()
279 if (DateTime.Now >= _lastUpdated.AddSeconds(_updateRate))
285 _icp.updateStatusXML(ref _daeData, out results);
288 _lastUpdated = DateTime.Now;
293 catch (InvalidCastException e)
296 System.Diagnostics.Process[] procList;
298 procList = System.Diagnostics.Process.GetProcessesByName(
"isisicp");
300 if (procList.Length > 0)
305 throw new Exception(e.Message);
307 catch (COMException e)
310 System.Diagnostics.Process[] procList;
312 procList = System.Diagnostics.Process.GetProcessesByName(
"isisicp");
314 if (procList.Length > 0)
319 throw new Exception(e.Message);
323 throw new Exception(e.Message);
335 XmlDocument xml =
new XmlDocument();
336 xml.InnerXml = _daeData;
341 XmlNodeList nodelist = xml.SelectNodes(
"/Cluster/String");
343 for (
int i = 0; i < nodelist.Count; ++i)
345 if (nodelist[i].FirstChild.InnerText ==
"RBNumber")
347 _rbNumber = nodelist[i].LastChild.InnerText;
349 else if (nodelist[i].FirstChild.InnerText ==
"RunTitle")
351 _runTitle = nodelist[i].LastChild.InnerText;
353 else if (nodelist[i].FirstChild.InnerText ==
"UserName")
355 _userName = nodelist[i].LastChild.InnerText;
357 else if (nodelist[i].FirstChild.InnerText ==
"RunNumber")
360 _runNumber = nodelist[i].LastChild.InnerText;
373 else if (nodelist[i].FirstChild.InnerText ==
"StartTime")
375 _startTime = nodelist[i].LastChild.InnerText;
380 nodelist = xml.SelectNodes(
"/Cluster/U32");
382 for (
int i = 0; i < nodelist.Count; ++i)
384 if (nodelist[i].FirstChild.InnerText ==
"GoodFramesTotal")
386 _goodFramesTotal = nodelist[i].LastChild.InnerText;
388 else if (nodelist[i].FirstChild.InnerText ==
"RawFramesTotal")
390 _rawFramesTotal = nodelist[i].LastChild.InnerText;
392 else if (nodelist[i].FirstChild.InnerText ==
"GoodFramesPeriod")
394 _goodFramesPeriod = nodelist[i].LastChild.InnerText;
396 else if (nodelist[i].FirstChild.InnerText ==
"RawFramesPeriod")
398 _rawFramesPeriod = nodelist[i].LastChild.InnerText;
400 else if (nodelist[i].FirstChild.InnerText ==
"RunDurationTotal")
402 int time = Convert.ToInt32(nodelist[i].LastChild.InnerText);
403 TimeSpan actual =
new TimeSpan(0, 0, 0, time);
405 _runDurationTotal = actual.ToString();
407 else if (nodelist[i].FirstChild.InnerText ==
"RunDurationPeriod")
409 int time = Convert.ToInt32(nodelist[i].LastChild.InnerText);
410 TimeSpan actual =
new TimeSpan(0, 0, 0, time);
412 _runDurationPeriod = actual.ToString();
414 else if (nodelist[i].FirstChild.InnerText ==
"NumberOfTimeChannels")
416 _numberOfTimeChannels = nodelist[i].LastChild.InnerText;
418 else if (nodelist[i].FirstChild.InnerText ==
"DAEMemoryUsed")
420 _daeMemoryUsed = nodelist[i].LastChild.InnerText;
422 else if (nodelist[i].FirstChild.InnerText ==
"NumberOfPeriods")
424 _numberOfPeriods = nodelist[i].LastChild.InnerText;
426 else if (nodelist[i].FirstChild.InnerText ==
"CurrentPeriod")
428 _currentPeriod = nodelist[i].LastChild.InnerText;
430 else if (nodelist[i].FirstChild.InnerText ==
"NumberOfSpectra")
432 _numberOfSpectra = nodelist[i].LastChild.InnerText;
434 else if (nodelist[i].FirstChild.InnerText ==
"MonitorCounts")
436 _monitorCounts = nodelist[i].LastChild.InnerText;
438 else if (nodelist[i].FirstChild.InnerText ==
"PeriodSequence")
440 _periodSequence = nodelist[i].LastChild.InnerText;
445 nodelist = xml.SelectNodes(
"/Cluster/I32");
447 for (
int i = 0; i < nodelist.Count; ++i)
449 if (nodelist[i].FirstChild.InnerText ==
"MonitorSpectrum")
451 _monitorSpectrum = nodelist[i].LastChild.InnerText;
456 nodelist = xml.SelectNodes(
"/Cluster/DBL");
458 for (
int i = 0; i < nodelist.Count; ++i)
460 if (nodelist[i].FirstChild.InnerText ==
"BeamCurrent")
462 _beamCurrent = nodelist[i].LastChild.InnerText;
464 else if (nodelist[i].FirstChild.InnerText ==
"TotalUAmps")
466 _totalUAmps = nodelist[i].LastChild.InnerText;
468 else if (nodelist[i].FirstChild.InnerText ==
"TotalDAECounts")
470 _totalDaeCounts = nodelist[i].LastChild.InnerText;
472 else if (nodelist[i].FirstChild.InnerText ==
"MonitorFrom")
474 _monitorFrom = nodelist[i].LastChild.InnerText;
476 else if (nodelist[i].FirstChild.InnerText ==
"MonitorTo")
478 _monitorTo = nodelist[i].LastChild.InnerText;
480 else if (nodelist[i].FirstChild.InnerText ==
"CountRate")
482 _countRate = nodelist[i].LastChild.InnerText;
487 nodelist = xml.SelectNodes(
"/Cluster/EW");
489 for (
int i = 0; i < nodelist.Count; ++i)
491 if (nodelist[i].FirstChild.InnerText ==
"RunStatus")
493 String val = nodelist[i].LastChild.InnerText;
494 String oldStatus = _runStatus;
498 _runStatus =
"PROCESSING";
502 _runStatus =
"SETUP";
506 _runStatus =
"RUNNING";
510 _runStatus =
"PAUSED";
514 _runStatus =
"WAITING";
518 _runStatus =
"VETOING";
522 _runStatus =
"ENDING";
526 _runStatus =
"SAVING";
530 _runStatus =
"UNKNOWN";
533 if (oldStatus ==
"SETUP" && _runStatus !=
"SETUP")
536 if (RunStarted != null)
538 RunStarted(DateTime.Now, _runNumber);
542 if (oldStatus !=
"SETUP" && _runStatus ==
"SETUP")
544 if (RunEnded != null)
546 RunEnded(DateTime.Now, oldRN);
551 else if (nodelist[i].FirstChild.InnerText ==
"DAETimingSource")
553 String val = nodelist[i].LastChild.InnerText;
557 _DaeTimingSource =
"ISIS";
561 _DaeTimingSource =
"Internal";
565 _DaeTimingSource =
"SMP";
569 _DaeTimingSource =
"Muon";
573 _DaeTimingSource =
"Muon MS";
577 _DaeTimingSource =
"ISIS (first TS1)";
589 internal static List<String> GetFormattedValues(Boolean includeUserInfo, Boolean isMuon)
591 List<String> lines =
new List<String>();
593 lines.Add(
"Run Status: " + _runStatus);
594 lines.Add(
"Run Number: " + _runNumber);
598 lines.Add(
"RB Number: " + _rbNumber);
599 lines.Add(
"User(s): " + _userName);
600 lines.Add(
"Title: " + _runTitle);
604 lines.Add(
"RB Number: Unavailable");
605 lines.Add(
"User(s): Unavailable");
606 lines.Add(
"Title: Unavailable");
609 lines.Add(
"Start Time: " + _startTime);
610 lines.Add(
"Total Run Time: " + _runDurationTotal);
611 lines.Add(
"Period Run Time: " + _runDurationPeriod);
612 lines.Add(
"Good Frames (Total): " + _goodFramesTotal);
613 lines.Add(
"Good Frames (Period): " + _goodFramesPeriod);
614 lines.Add(
"Raw Frames (Total): " + _rawFramesTotal);
615 lines.Add(
"Raw Frames (Period): " + _rawFramesPeriod);
616 lines.Add(
"Current Period: " + _currentPeriod);
617 lines.Add(
"Number Of Periods: " + _numberOfPeriods);
618 lines.Add(
"Period Sequence: " + _periodSequence);
619 lines.Add(
"Beam Current: " + _beamCurrent);
623 lines.Add(
"Total MEv: " + _totalDaeCounts);
627 lines.Add(
"Total UAmps: " + _totalUAmps);
630 lines.Add(
"Count-Rate: " + _countRate);
634 lines.Add(
"DAE Memory Used: " + _daeMemoryUsed);
635 lines.Add(
"Total DAE Counts: " + _totalDaeCounts);
636 lines.Add(
"DAE Timing Source: " + _DaeTimingSource);
637 lines.Add(
"Monitor Counts: " + _monitorCounts);
638 lines.Add(
"Monitor Spectrum: " + _monitorSpectrum);
639 lines.Add(
"Monitor From: " + _monitorFrom);
640 lines.Add(
"Monitor To: " + _monitorTo);
641 lines.Add(
"Number Of Time Channels: " + _numberOfTimeChannels);
642 lines.Add(
"Number Of Spectra: " + _numberOfSpectra);
650 #region Set run status
655 internal static void BeginRun()
659 String messages =
"";
660 _icp.beginRun(out messages);
667 internal static void EndRun()
671 String messages =
"";
672 _icp.endRun(out messages);
677 internal static void PauseRun()
681 String messages =
"";
682 _icp.pauseRun(out messages);
689 internal static void ResumeRun()
693 String messages =
"";
694 _icp.resumeRun(out messages);
701 internal static void AbortRun()
705 String messages =
"";
706 _icp.abortRun(out messages);
713 internal static void SaveRun()
717 String messages =
"";
718 _icp.saveRun(out messages);
725 internal static void UpdateRun()
733 internal static void StoreRun()
741 internal static void BeginWaiting()
745 String messages =
"";
746 _icp.startSEWait(out messages);
747 _inWaitingState =
true;
754 internal static void EndWaiting()
758 String messages =
"";
759 _icp.endSEWait(out messages);
760 _inWaitingState =
false;
static String _currentPeriod
static String _daeMemoryUsed
delegate void DaeEventHandler(DateTime time, String runNumber)
Delegate for handling events triggered from the DAE
static void SetTitleBarVisibility(Boolean visible)
This method shows/hides the DAE VI's title bar
static DaeEventHandler RunEnded
The event that is fired when a run ends.
static String _numberOfTimeChannels
static String _monitorSpectrum
static String _totalDaeCounts
static DaeEventHandler RunStarted
The event that is fired when a run starts.
static void KillIcp()
This method will kill the ICP.
static DateTime _lastUpdated
static String _numberOfPeriods
static String _totalUAmps
static Boolean _inWaitingState
static String _DaeTimingSource
static void KillIsisDataSvr()
static void HideDae()
This method hides the DAE VI - it is hidden by default.
static String _rawFramesTotal
This class is a wrapper for the ICP programme that is a default part of SECI. The class is set up to ...
static String _monitorFrom
static void getValuesFromXML()
This method actually read the XML returned from the ICP and extracts the values.
static String _numberOfSpectra
static void SetTitle(String title)
Sets the run title
static String _runDurationTotal
static String _runDurationPeriod
static void ShowDae()
This method shows the DAE VI - it is hidden by default.
static String _periodSequence
static String _rawFramesPeriod
static isisicpLib.dae _icp
static String _monitorCounts
static void LoadDaeVI()
This method loads and starts the DAE VI and creates the DCOM connection to the ICP.
static void connectToIcp()
static String _goodFramesTotal
static String _beamCurrent
static String _goodFramesPeriod