diff --git a/EpdBase/EpdBase.cpp b/EpdBase/EpdBase.cpp index 8b2b326..185e996 100644 --- a/EpdBase/EpdBase.cpp +++ b/EpdBase/EpdBase.cpp @@ -150,6 +150,19 @@ WORD EpdBase::Epd2U::ReadStatus() return 1; } +WORD EpdBase::Epd2U::EPDReadExtraStatus() +{ + CommitRV = ReadA2ConfigStatus( + &byBatADC, + &bySupplyADC, + &byStatus3, + &byStatus4); + + if (CommitRV == 1) CommitRV = Commit(); + if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData); + return CommitRV; +} + WORD EpdBase::Epd2U::EPDReadConfig() { ReadConfigRV = ReadConfig( @@ -205,6 +218,21 @@ WORD EpdBase::Epd2U::TurnOn() return 0; } + +WORD EpdBase::Epd2U::WriteCal() +{ + Password = 9; + //((BYTE *)&Password)[0] = 9; + + CommitRV = MFRLogin(Password); + if (CommitRV == 1) CommitRV = Commit(); + if (CommitRV == 1) CommitRV = MFRWriteCalFactors(K1, K2, K3, K4, K5, K6); + if (CommitRV == 1) CommitRV = Commit(); + if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData); + return CommitRV; +} + + WORD EpdBase::Epd2U::ReadTresHolds() { Hp10THDose1 = Hp10THDose2 = Hp07THDose = 0; @@ -329,7 +357,7 @@ WORD EpdBase::Epd2U::Issue() if (OKRV) OKRV = Commit(); if (OKRV) OKRV = IssueEpd(WearerID, WearerIDLength); if (OKRV) OKRV = Commit(); - if (OKRV) OKRV = WriteWearerName(WearerName,WearerNameLength); + if (OKRV) OKRV = WriteWearerName(WearerName,strlen((char *)WearerName)); if (OKRV) OKRV = Commit(); if (OKRV) OKRV = ClearFailFlag(); // all actions have been completed if (OKRV) OKRV = Commit(); diff --git a/EpdBase/EpdBase.h b/EpdBase/EpdBase.h index 0fdfeae..179e172 100644 --- a/EpdBase/EpdBase.h +++ b/EpdBase/EpdBase.h @@ -177,6 +177,15 @@ namespace EpdBase BYTE OtherAlarmBatVolt = 0; + + DWORD Password = 9; + + + BYTE byBatADC; + BYTE bySupplyADC; + BYTE byStatus3; + BYTE byStatus4; + void StartDiscover(); void Open(DWORD DeviceID); void Close(); @@ -187,9 +196,11 @@ namespace EpdBase Epd2U(int comport); WORD ReadStatus(); + WORD EPDReadExtraStatus(); WORD EPDReadConfig(); WORD TurnOff(); WORD TurnOn(); + WORD WriteCal(); WORD ReadTresHolds(); WORD ReadDoses(); diff --git a/EpdBaseClr/EpdBaseClr.cpp b/EpdBaseClr/EpdBaseClr.cpp index 06afdc5..378ea95 100644 --- a/EpdBaseClr/EpdBaseClr.cpp +++ b/EpdBaseClr/EpdBaseClr.cpp @@ -111,14 +111,10 @@ int EpdBaseClr::Epd2::SetDeIssued() int EpdBaseClr::Epd2::SetIssued() { - epd->AlarmDoseHP07N = Hp07THDose; - epd->AlarmDoseHP101G = Hp10THDose1; - epd->AlarmDoseHP102G = Hp10THDose1; - - epd->Hp07THDose = Hp07THDose; - epd->Hp10THDose1 = Hp10THDose1; - epd->Hp10THDose2 = Hp10THDose2; + epd->Hp07THDose = Hp07THDose*64; + epd->Hp10THDose1 = Hp10THDose1*64; + epd->Hp10THDose2 = Hp10THDose2*64; epd->Hp10Rate1On = Hp10Rate1On; epd->Hp10Rate2On = Hp10Rate2On; @@ -146,6 +142,16 @@ int EpdBaseClr::Epd2::SetIssued() return 0; } + +int EpdBaseClr::Epd2::WriteCalibration() +{ + epd->K3 = K3; + epd->K4 = K4; + int rv= epd->WriteCal(); + return rv; + +} + int EpdBaseClr::Epd2::ReadTresholds() { epd->ReadTresHolds(); @@ -176,4 +182,13 @@ int EpdBaseClr::Epd2::ReadTresholds() HG = epd->HG; return 0; +} + +int EpdBaseClr::Epd2::ReadExtraStatus() +{ + int rv = epd->EPDReadExtraStatus(); + BatADC = epd->byBatADC; + SupplyADC = epd->bySupplyADC; + + return rv; } \ No newline at end of file diff --git a/EpdBaseClr/EpdBaseClr.h b/EpdBaseClr/EpdBaseClr.h index b5afec1..5daa521 100644 --- a/EpdBaseClr/EpdBaseClr.h +++ b/EpdBaseClr/EpdBaseClr.h @@ -82,6 +82,9 @@ namespace EpdBaseClr { int FunctionFlags ; + unsigned short BatADC; + unsigned short SupplyADC; + Epd2(int port); ~Epd2(); !Epd2(); @@ -98,8 +101,12 @@ namespace EpdBaseClr { int SetIssued(); + int WriteCalibration(); + int ReadTresholds(); + int ReadExtraStatus(); + }; diff --git a/eDosStation/EntryBadge.xaml.cs b/eDosStation/EntryBadge.xaml.cs index 0a5bb16..4c8d2ad 100644 --- a/eDosStation/EntryBadge.xaml.cs +++ b/eDosStation/EntryBadge.xaml.cs @@ -56,7 +56,8 @@ namespace eDosStation this.Close(); return; } - + statusEPD.Text = $"EPD: {ep.b.CurrentDeviceID}"; + ep.ReadTresholds(); //ep.Hp07THDose = } @@ -68,8 +69,7 @@ namespace eDosStation if (ep.DiscRV == 1 && ep.b.CurrentDeviceID > 0) { EpdFound = true; - statusEPD.Text = $"EPD: {ep.b.CurrentDeviceID}"; - LoadDoses(); + DoEPD(); } if (!EpdFound) { @@ -89,27 +89,10 @@ namespace eDosStation } - private void GetEPD() + private void DoEPD() { - if (_User == null || CurTaskRow == null) return; - - ep = new EpdBaseClr.Epd2(Properties.Settings.Default.comport); - ep.Connect(); - if (ep.DiscRV == 1 && ep.b.CurrentDeviceID > 0) - { - EpdFound = true; - statusEPD.Text= $"EPD: {ep.b.CurrentDeviceID}"; - LoadDoses(); - } - if (!EpdFound) - { - statusEPD.Text= $"EPD: Wait "; - Search = 100; - dispatcherTimer = new DispatcherTimer(); - dispatcherTimer.Tick += DispatcherTimer_Tick; - dispatcherTimer.Interval = new TimeSpan(0, 0, 2); - dispatcherTimer.Start(); - } + LoadDoses(); + bool isBG = (ep.epdType == 3); int? VisitID = null; @@ -126,7 +109,7 @@ namespace eDosStation pa = new SqlParameter("ID_Visit", SqlDbType.Int, 4); pa.Direction = ParameterDirection.Output; cmd1.Parameters.Add(pa); co.Open(); cmd1.ExecuteNonQuery(); - VisitID = (int ?)cmd1.Parameters["ID_Visit"].Value; + VisitID = (int?)cmd1.Parameters["ID_Visit"].Value; co.Close(); } } @@ -144,7 +127,41 @@ namespace eDosStation ep.Hp10THDose2 = CurTaskRow.Hp10Dose2; ep.Hp07THDose = CurTaskRow.Hp07Dose; + int kx = (int)CurTaskRow.FNGain_ANGainValue; + if (ep.K3 != kx || ep.K4 != kx) + { + ep.K3 = ep.K4 = kx; + ep.WriteCalibration(); + + } + ep.SetIssued(); + } + + private void GetEPD() + { + if (_User == null || CurTaskRow == null) return; + + ep = new EpdBaseClr.Epd2(Properties.Settings.Default.comport); + ep.Connect(); + if (ep.DiscRV == 1 && ep.b.CurrentDeviceID > 0) + { + EpdFound = true; + + DoEPD(); + } + if (!EpdFound) + { + statusEPD.Text= $"EPD: Wait "; + Search = 100; + dispatcherTimer = new DispatcherTimer(); + dispatcherTimer.Tick += DispatcherTimer_Tick; + dispatcherTimer.Interval = new TimeSpan(0, 0, 2); + dispatcherTimer.Start(); + return; + } + + } diff --git a/eDosStation/ShowEPDDose.xaml b/eDosStation/ShowEPDDose.xaml index 8c1454b..c215789 100644 --- a/eDosStation/ShowEPDDose.xaml +++ b/eDosStation/ShowEPDDose.xaml @@ -12,15 +12,17 @@ + + - - - + + + @@ -29,7 +31,7 @@ - + @@ -40,6 +42,13 @@ + + + + + + + diff --git a/eDosStation/ShowEPDDose.xaml.cs b/eDosStation/ShowEPDDose.xaml.cs index 32e3834..0f1c45c 100644 --- a/eDosStation/ShowEPDDose.xaml.cs +++ b/eDosStation/ShowEPDDose.xaml.cs @@ -44,7 +44,13 @@ namespace eDosStation ep.ReadTresholds(); HP10AlarmDose1.Text = $"Alarm HP10(1) {ep.Hp10THDose1:0.00} µSv"; HP10AlarmDose2.Text = $"Alarm HP10(2) {ep.Hp10THDose2:0.00} µSv"; - HP07AlarmDose.Text = $"Alarm HP07 {ep.Hp07THDose:0.00} µSv"; + HP07AlarmDose.Text = $"Alarm HP07 {ep.Hp07THDose:0.00} µSv"; + + ep.ReadExtraStatus(); + + BatVolt.Text = $" {ep.BatADC * 16.0} mV"; + SupplyVolt.Text = $" {ep.SupplyADC* 16.0} mV"; + //int Hp10THDose2; //int Hp07THDose; }