298 lines
11 KiB
C#
298 lines
11 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Diagnostics;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using System.Windows;
|
|||
|
|
using System.Windows.Controls;
|
|||
|
|
using System.Windows.Data;
|
|||
|
|
using System.Windows.Documents;
|
|||
|
|
using System.Windows.Input;
|
|||
|
|
using System.Windows.Media;
|
|||
|
|
using System.Windows.Media.Imaging;
|
|||
|
|
using System.Windows.Shapes;
|
|||
|
|
using System.Windows.Threading;
|
|||
|
|
using Telerik.Windows.Controls.StepProgressBar;
|
|||
|
|
|
|||
|
|
namespace eDosStation
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Interaction logic for ShowEPDDose.xaml
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class ShowEPDDose : Window
|
|||
|
|
{
|
|||
|
|
private enum eEntryState { none, getepd, epdtimeout, epdError, epdOK, final };
|
|||
|
|
#pragma warning disable CS0414 // The field 'ShowEPDDose.EntryState' is assigned but its value is never used
|
|||
|
|
private eEntryState EntryState;
|
|||
|
|
#pragma warning restore CS0414 // The field 'ShowEPDDose.EntryState' is assigned but its value is never used
|
|||
|
|
|
|||
|
|
Station thisStation;
|
|||
|
|
EpdBaseClr.Epd2 ep;
|
|||
|
|
DispatcherTimer dispatcherTimer;
|
|||
|
|
private DateTime ResultTime;
|
|||
|
|
private User thisUser;
|
|||
|
|
#pragma warning disable CS0414 // The field 'ShowEPDDose.EpdReading' is assigned but its value is never used
|
|||
|
|
private bool EpdReading;
|
|||
|
|
#pragma warning restore CS0414 // The field 'ShowEPDDose.EpdReading' is assigned but its value is never used
|
|||
|
|
private bool FinalTimeOut;
|
|||
|
|
|
|||
|
|
public ShowEPDDose(Station curStation)
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
thisStation = curStation;
|
|||
|
|
EpdReading = false;
|
|||
|
|
FinalTimeOut = false;
|
|||
|
|
EntryState = eEntryState.none;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
private void CountDown(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
double v = (ResultTime - DateTime.Now).TotalSeconds;
|
|||
|
|
if (v > DosimeterView.Progress.Minimum)
|
|||
|
|
{
|
|||
|
|
DosimeterView.Progress.Value = v;
|
|||
|
|
DosimeterView.ProgressText.Text = ((int)v).ToString();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
SetTimedOutAndEnd();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region EPD Callback
|
|||
|
|
private void Ep_EpdTO(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdTOEventArgs e)
|
|||
|
|
{
|
|||
|
|
System.Diagnostics.Debug.WriteLine("TIME OUT");
|
|||
|
|
DosimeterView.Dispatcher.InvokeAsync(() => { SetTimedOutAndEnd(); });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Ep_EpdError(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdErrorEventArgs e)
|
|||
|
|
{
|
|||
|
|
System.Diagnostics.Debug.WriteLine("ERROR ");
|
|||
|
|
DosimeterView.Dispatcher.InvokeAsync(() => {
|
|||
|
|
MessageBox.Show($"EPD Error {e.returnValue} {e.ErrorRV} {e.ErrorStep}");
|
|||
|
|
DosimeterView.Dispatcher.InvokeAsync(() => { SetTimedOutAndEnd(); });
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Ep_EpdRead(EpdBaseClr.Epd2 Sender, EpdBaseClr.EpdEventArgs e)
|
|||
|
|
{
|
|||
|
|
EpdReading = false;
|
|||
|
|
dispatcherTimer?.Stop();
|
|||
|
|
DosimeterView.Dispatcher.InvokeAsync(() => LoadDoses());
|
|||
|
|
}
|
|||
|
|
private void Ep_EpdProgress(EpdBaseClr.Epd2 Sender, EpdSteps step, EpdStepResults result)
|
|||
|
|
{
|
|||
|
|
System.Diagnostics.Debug.WriteLine($"EPD Progress step:{step} result:{result}");
|
|||
|
|
int index = -1;
|
|||
|
|
StepStatus st = StepStatus.NotStarted;
|
|||
|
|
|
|||
|
|
switch (step)
|
|||
|
|
{
|
|||
|
|
case EpdSteps.StepStartCom: index = 0; break;
|
|||
|
|
case EpdSteps.StepConnecting: index = 1; break;
|
|||
|
|
case EpdSteps.StepReadStatus: index = 2; break;
|
|||
|
|
case EpdSteps.StepReadCounts: index = 3; break;
|
|||
|
|
default: System.Diagnostics.Debug.WriteLine($"step {step}"); break;
|
|||
|
|
}
|
|||
|
|
switch (result)
|
|||
|
|
{
|
|||
|
|
case EpdStepResults.OK: st = StepStatus.Completed; break;
|
|||
|
|
case EpdStepResults.Error: st = StepStatus.Indeterminate; break;
|
|||
|
|
case EpdStepResults.Started: st = StepStatus.Indeterminate; break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (index >= 0 && index <= DosimeterView.stepEPD.Items.Count)
|
|||
|
|
{
|
|||
|
|
this.Dispatcher.Invoke(() =>
|
|||
|
|
{
|
|||
|
|
DosimeterView.stepEPD.SelectedIndex = index;
|
|||
|
|
DosimeterView.stepEPD.SelectedItemStatus = st;
|
|||
|
|
|
|||
|
|
// Optional: Force the progress step visual item to update status if needed
|
|||
|
|
if (DosimeterView.stepEPD.ItemContainerGenerator.ContainerFromIndex(index) is FrameworkElement container)
|
|||
|
|
{
|
|||
|
|
container.UpdateLayout();
|
|||
|
|
}
|
|||
|
|
}, System.Windows.Threading.DispatcherPriority.Normal);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
private void LoadDoses()
|
|||
|
|
{
|
|||
|
|
int rv = 0;
|
|||
|
|
if (ep == null) return;
|
|||
|
|
rv = ep.GetAll(true);
|
|||
|
|
if (rv != 0) MessageBox.Show("Communication error");
|
|||
|
|
|
|||
|
|
DosimeterView.isIssued.Text = ep.EPDIssued ? AppFormats.Yes : AppFormats.No;
|
|||
|
|
string sPersID = ep.WearerName.Trim();
|
|||
|
|
DosimeterView.Wearer.Text = sPersID;
|
|||
|
|
DosimeterView.EpdVisit.Text = ep.WearerID.ToString();
|
|||
|
|
|
|||
|
|
DosimeterView.HardVersion.Text = ep.HardVersion.ToString() + '.' + ep.HardVersionMinor.ToString(); // ep.SoftVersion.ToString();
|
|||
|
|
|
|||
|
|
|
|||
|
|
DosimeterView.hasAlarm.Text = ep.eDoshasAlarm ? AppFormats.Yes : AppFormats.No;
|
|||
|
|
|
|||
|
|
|
|||
|
|
DosimeterView.epdid.Text = ep.EpdID.ToString();
|
|||
|
|
var stype = new StringBuilder();
|
|||
|
|
if (ep.isMK3) stype.Append("MK3 "); else stype.Append("MK2 ");
|
|||
|
|
if (ep.isBG) stype.Append(" BG"); else stype.Append(" NG");
|
|||
|
|
DosimeterView.epdtype.Text = stype.ToString();
|
|||
|
|
|
|||
|
|
Decoder.AlarmToTextBox(DosimeterView.sAlarm, ep);
|
|||
|
|
|
|||
|
|
DosimeterView.HpDose07l.Text = ep.Hp07Name;
|
|||
|
|
DosimeterView.HpDose10l.Text = ep.Hp10Name;
|
|||
|
|
|
|||
|
|
DosimeterView.HpDose07.Text = string.Format(AppFormats.DoseFormat, ep.Hp07);// $"{ep.Hp07:0.00} µSv";
|
|||
|
|
DosimeterView.HpDose10.Text = string.Format(AppFormats.DoseFormat, ep.Hp10);// $"{ep.Hp10:0.00} µSv";
|
|||
|
|
|
|||
|
|
DosimeterView.HP10AlarmDose1l.Text = "Warning " + ep.Hp10Name;
|
|||
|
|
DosimeterView.HP10AlarmDose2l.Text = "Alarm " + ep.Hp10Name;
|
|||
|
|
DosimeterView.HP07AlarmDosel.Text = "Alarm " + ep.Hp07Name;
|
|||
|
|
|
|||
|
|
DosimeterView.HP10AlarmDose1.Text = string.Format(AppFormats.DoseFormat, ep.Hp10THDose1);
|
|||
|
|
DosimeterView.HP10AlarmDose2.Text = string.Format(AppFormats.DoseFormat, ep.Hp10THDose2);
|
|||
|
|
DosimeterView.HP07AlarmDose.Text = string.Format(AppFormats.DoseFormat, ep.Hp07THDose);
|
|||
|
|
|
|||
|
|
DosimeterView.HpPeak07l.Text = ep.Hp07Name + " Peak";
|
|||
|
|
DosimeterView.HpPeak07.Text = string.Format(AppFormats.DoseFormatPeak, ep.Hp07Peak, ep.Hp07PeakTime); //$"{ep.Hp07Peak:0.00} µSv {ep.Hp07PeakTime:yyyy-MM-dd HH:mm} ";
|
|||
|
|
|
|||
|
|
DosimeterView.HpPeak10l.Text = ep.Hp10Name + " Peak";
|
|||
|
|
DosimeterView.HpPeak10.Text = string.Format(AppFormats.DoseFormatPeak, ep.Hp10Peak, ep.Hp10PeakTime); //$"{ep.Hp10Peak:0.00} µSv {ep.Hp10PeakTime:yyyy-MM-dd HH:mm} ";
|
|||
|
|
|
|||
|
|
if (ep.isNG)
|
|||
|
|
{
|
|||
|
|
DosimeterView.lNGain.Visibility = DosimeterView.NGain.Visibility = Visibility.Visible;
|
|||
|
|
DosimeterView.NGain.Text = ep.NGgain.ToString("#.##");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
DosimeterView.lNGain.Visibility = DosimeterView.NGain.Visibility = Visibility.Hidden;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!string.IsNullOrEmpty(sPersID))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
thisUser = thisStation.dataInterface.GetUser(string.Empty, sPersID, false);
|
|||
|
|
DosimeterView.epdUserMargin.Text = thisUser.Margin.ToString();
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
DosimeterView.epdUserMargin.Text = "--";
|
|||
|
|
|
|||
|
|
DosimeterView.Progress.Visibility = Visibility.Collapsed;
|
|||
|
|
DosimeterView.bEpdCancel.IsEnabled = true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|||
|
|
{
|
|||
|
|
FinalTimeOut = false;
|
|||
|
|
EpdReading = false;
|
|||
|
|
|
|||
|
|
ep = new EpdBaseClr.Epd2(thisStation.ComPort, thisStation.OnlyMK2);
|
|||
|
|
ep.SetFeedbackSound(thisStation.useBeep, thisStation.useBeepMK3());
|
|||
|
|
ep.EpdRead += Ep_EpdRead;
|
|||
|
|
ep.EpdError += Ep_EpdError;
|
|||
|
|
ep.EpdTO += Ep_EpdTO;
|
|||
|
|
ep.EpdProgress += Ep_EpdProgress;
|
|||
|
|
|
|||
|
|
dispatcherTimer = new DispatcherTimer(DispatcherPriority.Background);
|
|||
|
|
dispatcherTimer.Interval = thisStation.ScreenProgressBarInterval;
|
|||
|
|
dispatcherTimer.Tick += CountDown;
|
|||
|
|
ResultTime = DateTime.Now.AddSeconds(thisStation.ScreenEPDTimeout);
|
|||
|
|
DosimeterView.Progress.Value = DosimeterView.Progress.Maximum = thisStation.ScreenEPDTimeout;
|
|||
|
|
dispatcherTimer.Start();
|
|||
|
|
startEPDRead();
|
|||
|
|
|
|||
|
|
//dispatcherTimer = new DispatcherTimer(DispatcherPriority.Normal);
|
|||
|
|
//dispatcherTimer.Interval = TimeSpan.FromMilliseconds(thisStation.EPDTimeOut / 10);
|
|||
|
|
//Progress.Maximum = Progress.Value = dispatcherTimer.Interval.TotalSeconds * 10;
|
|||
|
|
//dispatcherTimer.Tick += CountDown;
|
|||
|
|
//Dispatcher.InvokeAsync(() => ep.Wait(thisStation.EPDTimeOut, 1),DispatcherPriority.Background);
|
|||
|
|
//dispatcherTimer.Start();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
private void startEPDRead()
|
|||
|
|
{
|
|||
|
|
EpdReading = true; DosimeterView.bEpdCancel.IsEnabled = false;
|
|||
|
|
DosimeterView.Dispatcher.InvokeAsync(new Action(() => { ep.Wait(thisStation.EPDTimeOut, thisStation.EPDRetries); }), DispatcherPriority.Background);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SetTimedOutAndEnd()
|
|||
|
|
{
|
|||
|
|
if (!FinalTimeOut)
|
|||
|
|
{
|
|||
|
|
DosimeterView.bEpdCancel.IsEnabled = true;
|
|||
|
|
FinalTimeOut = true;
|
|||
|
|
dispatcherTimer?.Stop();
|
|||
|
|
DosimeterView.Progress.Value = 0;
|
|||
|
|
DosimeterView.Progress.Background = System.Windows.Media.Brushes.Red;
|
|||
|
|
statusEPD.Content = "Time out";
|
|||
|
|
DosimeterView.tWaitFor.Text = "Lezer niet gevonden !";
|
|||
|
|
dispatcherTimer = new DispatcherTimer(DispatcherPriority.Background);
|
|||
|
|
dispatcherTimer.Tick += ShowAndEnd;
|
|||
|
|
dispatcherTimer.Interval = thisStation.ShowTimeoutTime;
|
|||
|
|
dispatcherTimer.Start();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void ShowAndEnd(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
dispatcherTimer?.Stop();
|
|||
|
|
dispatcherTimer = null;
|
|||
|
|
endPage();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void endPage()
|
|||
|
|
{
|
|||
|
|
this.Close();
|
|||
|
|
}
|
|||
|
|
private void DosimeterView_CloseClicked(object sender, RoutedEventArgs e)
|
|||
|
|
{
|
|||
|
|
endPage();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void RadButton_Click(object sender, RoutedEventArgs e)
|
|||
|
|
{
|
|||
|
|
endPage();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|||
|
|
{
|
|||
|
|
dispatcherTimer?.Stop();
|
|||
|
|
dispatcherTimer = null;
|
|||
|
|
EpdReading = true;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (ep != null)
|
|||
|
|
{
|
|||
|
|
ep.WaitEnd();
|
|||
|
|
ep.Dispose();
|
|||
|
|
ep = null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
System.Diagnostics.Debug.WriteLine(ex.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|