735 lines
31 KiB
C#
735 lines
31 KiB
C#
using ByteArrayStyle;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Claims;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.Consts;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
|
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
|
|
|
namespace Xylem.Common.Ui.GenesisToolBox
|
|
{
|
|
//CUSTOMER_AlarmEnableMask UInt32 Bit set of those alarms which are being monitored.
|
|
//CUSTOMER_AlarmBroadcastMask UInt32 Bit set of those alarms which will generate events.
|
|
//CUSTOMER_AlarmVisualMask UInt32 Bit set of those alarms which are displayed with IDs and the alarm icon.
|
|
|
|
[Flags]
|
|
internal enum AlarmMask
|
|
{
|
|
ALARM_REBOOT = 1 << 0,
|
|
ALARM_LOW_BATTERY = 1 << 1,
|
|
ALARM_VERY_LOW_BATTERY = 1 << 2, /* For consistency with st_alarm_bit_t only */
|
|
ALARM_CONFIG_ERROR = 1 << 3,
|
|
ALARM_EMPTY_PIPE = 1 << 4,
|
|
ALARM_MAGNETIC_TAMPER = 1 << 5, /* For consistency with st_alarm_bit_t only */
|
|
ALARM_REVERSE_FLOW = 1 << 6,
|
|
ALARM_SUSPECT_LEAK = 1 << 7,
|
|
ALARM_BROKEN_PIPE = 1 << 8,
|
|
ALARM_LOW_PRESSURE = 1 << 9,
|
|
ALARM_HIGH_PRESSURE = 1 << 10,
|
|
ALARM_LOW_TEMPERATURE = 1 << 11,
|
|
ALARM_HIGH_TEMPERATURE = 1 << 12,
|
|
ALARM_RADIO_ERROR = 1 << 13,
|
|
ALARM_METROLOGY_PARAMS = 1 << 14,
|
|
ALARM_METROLOGY_MEASURE = 1 << 15,
|
|
ALARM_MAX = 1 << 16
|
|
};
|
|
|
|
|
|
|
|
[Flags]
|
|
internal enum DataLoggerMask
|
|
{
|
|
LOG_RESERVED_2 = 0x20000000, //!< not yet defined
|
|
LOG_RESERVED_1 = 0x10000000, //!< not yet defined
|
|
LOG_REC_CRC_VAL = 0x08000000, //!< CRC of this record
|
|
LOG_EXT_ALARM_STATE = 0x04000000, //<! Extended Alarm Status
|
|
LOG_CUR_TEMP_VAL = 0x02000000, //!< Temperature Current Value
|
|
LOG_CUR_PRESS_VAL = 0x01000000, //!< Pressure Current Value
|
|
LOG_MAX_TEMP_TIME = 0x00800000, //!< Temperature Maximum
|
|
LOG_MAX_TEMP_VAL = 0x00400000, //!< Temperature Maximum
|
|
LOG_MIN_TEMP_TIME = 0x00200000, //!< Temperature Minimum
|
|
LOG_MIN_TEMP_VAL = 0x00100000, //!< Temperature Minimum
|
|
LOG_MAX_PRESS_TIME = 0x00080000, //!< Pressure Maximum Time
|
|
LOG_MAX_PRESS_VAL = 0x00040000, //!< Pressure Maximum
|
|
LOG_MIN_PRESS_TIME = 0x00020000, //!< Pressure Minimum Time
|
|
LOG_MIN_PRESS_VAL = 0x00010000, //!< Pressure Minimum
|
|
LOG_ITEM_SELECTOR_2 = 0x00008000, //!< not yet defined; reserved
|
|
LOG_ITEM_SELECTOR_1 = 0x00004000, //!< Selector bit for Page0 or Page1
|
|
LOG_DATE_TIME = 0x00002000, //!< DateTime Second bit
|
|
LOG_FORWARD_COUNTER = 0x00001000, //!< ForwardCounter
|
|
LOG_MIN_FLOW_TIME = 0x00000800, //!< Date/Time of FlowMin
|
|
LOG_MIN_FLOW_VAL = 0x00000400, //!< Value of FlowMin
|
|
LOG_BROKEN_PIPE_FLOW_TIME = 0x00000200, //!< Date/Time of BrokenPipe
|
|
LOG_BROKEN_PIPE_FLOW_VAL = 0x00000100, //!< Value of BrokenPipe
|
|
LOG_CUR_FLOW_VAL = 0x00000080, //!< Current Flow Value (Average of Period)
|
|
LOG_PEAK_FLOW_TIME = 0x00000040, //!< Date/Time of PeakFlow
|
|
LOG_PEAK_FLOW_VAL = 0x00000020, //!< Value of PeakFlow
|
|
LOG_MAX_FLOW_TIME = 0x00000010, //!< Date/Time of MaxFlow
|
|
LOG_MAX_FLOW_VAL = 0x00000008, //!< Value of MaxFlow
|
|
LOG_REVERSE_COUNTER = 0x00000004, //!< Backward or ReverseCounter
|
|
LOG_BILLING_COUNTER = 0x00000002, //!< BillingCounter
|
|
LOG_ALARM_STATE = 0x00000001, //!< AlarmState (16 bits)
|
|
LOG_DATE_TIME_0 = 0x00000000, //!< DateTime of complete record
|
|
};
|
|
|
|
|
|
class LoggingContent
|
|
{
|
|
public const byte AlarmStatus = 0; // 0x00000001 ;The active alarm information at UTC32
|
|
public const byte BillingCounter = 1; // 0x00000002 ;The billing counter at UTC32
|
|
public const byte ReverseCounter = 2; // 0x00000004 ;The reverse counter at UTC32
|
|
public const byte MaxFlow = 3; // 0x00000008 ;The maximum flow of the current FDR period UTC32n -… UTC32n-1
|
|
public const byte MaxFlowTime = 4; // 0x00000010 ;The Date/Time information when Qmax happened in the FDR period
|
|
public const byte PeakFlow = 5; // 0x00000020 ;The peak flow of the current FDR period
|
|
public const byte PeakFlowTime = 6; // 0x00000040 ;The Date/Time information when Qpeak happened in the FDR period
|
|
public const byte AvgFlow = 7; // 0x00000080 ;The average flow rate in the current FDR period
|
|
public const byte BrokenPipe = 8; // 0x00000100 ;The weak flow in the current FDR period
|
|
public const byte BrokenPipeTime = 9; // 0x00000200 ;The Date/Time information when Qweak happened in the FDR period
|
|
public const byte MinFlow = 10; // 0x00000400 ;The minimum flow in the current FDR period
|
|
public const byte MinFlowTime = 11; // 0x00000800 ;The Date/Time information when Qmin happened in the FDR period
|
|
public const byte ForwardCounter = 12; // 0x00001000 ;The forward counter at UTC32
|
|
public const byte _UTC32 = 13; // 0x00002000 ;Date/Time information when the record was stored.
|
|
public const byte _MaskSelector_1_1 = 14; // 0x00004000 ;Two selector bits to switch the bitmask of the RF-communication between the internal pages
|
|
public const byte _MaskSelector_1_2 = 15; // 0x00008000 ;
|
|
public const byte MinPress = 16; // 0x00010000 ;The minimum pressure in the current LOG period
|
|
public const byte MinPressTime = 17; // 0x00020000 ;The number of 1-second intervals when Pmin happened in the LOG period
|
|
public const byte MaxPress = 18; // 0x00040000 ;The maximum pressure in the current LOG period
|
|
public const byte MaxPressTime = 19; // 0x00080000 ;The number of 1-second intervals when Pmax happened in the LOG period
|
|
public const byte MinTemp = 20; // 0x00100000 ;The minimum temperature in the current LOG period
|
|
public const byte MinTempTime = 21; // 0x00200000 ;The number of 1-second intervals when Tmin happened in the LOG period
|
|
public const byte MaxTemp = 22; // 0x00400000 ;The maximum temperature in the current LOG period
|
|
public const byte MaxTempTime = 23; // 0x00800000 ;The number of 1-second intervals when Tmax happened in the LOG period
|
|
public const byte CurrentPress = 24; // 0x01000000 ;The last measured instantaneous pressure at RTC32
|
|
public const byte CurrentTemp = 25; // 0x02000000 ;The last measured instantaneous temperature at RTC32
|
|
public const byte ExtendedAlarm = 26; // 0x04000000 ;"Similar to the AlarmStatus; P and T related Alarms. "
|
|
public const byte _RecordCheckSum = 27; // 0x08000000 ;A Checksum across the entire FDR record
|
|
public const byte _Reserved_1 = 28; // 0x10000000 ;A reserved mask for a further item
|
|
public const byte _Reserved_2 = 29; // 0x20000000 ;A reserved mask for a further item
|
|
public const byte _MaskSelector_2_1 = 30; // 0x40000000 ;The mirror of the MaskSelector_1
|
|
public const byte _MaskSelector_2_2 = 31; // 0x80000000 ;The mirror of the MaskSelector_2
|
|
}
|
|
|
|
|
|
|
|
public partial class FrmAlarmMng : Form
|
|
{
|
|
private GenesisMeter _currentGenesis;
|
|
private MeterBatch _meterBatch = new MeterBatch();
|
|
private List<NumericUpDown> registerControls = new List<NumericUpDown>();
|
|
|
|
public FrmAlarmMng()
|
|
{
|
|
InitializeComponent();
|
|
|
|
var RegisterSource = new List<Tuple<String, Type, String, UInt32, UInt32, UInt32>>();
|
|
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_ExcessFlowVolumeThreshold", typeof(UInt32), "Flow rate above which broken pipe alarm is set in 1/256 l/h ", 0, 4294967295, 639999));
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_LeakTimeThreshold", typeof(UInt32), "Time threshold for leak alarm in minutes ", 0, 69632, 360));
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_ReverseFlowTimeThreshold", typeof(UInt16), "Number of measurements in reverse flow required to set reverse flow alarm ", 0, 65535, 1800));
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_ExcessFlowTimeThreshold", typeof(UInt32), "Time threshold for broken pipe alarm in minutes ", 0, 69632, 180));
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_LeakFlowThreshold", typeof(UInt32), "Flow rate above which leak alarm can be set in 1/256 l/h ", 0, 4294967295, 6399));
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_TemperatureHighThreshold", typeof(UInt32), "High temperature alarm threshold in 0.1°C ", 0, 800, 500));
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_TemperatureHighDelay", typeof(UInt32), "Time threshold for high temperature alarm in seconds ", 0, 10800, 600));
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_TemperatureLowThreshold", typeof(UInt32), "Low temperature alarm threshold in 0.1°C ", 0, 4294967295, 20));
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_TemperatureLowDelay", typeof(UInt32), "Time threshold for low temperature alarm in seconds ", 0, 10800, 600));
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_PressureHighThreshold", typeof(UInt32), "High pressure alarm threshold in Pa ", 0, 2550000, 1600000));
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_PressureHighDelay", typeof(UInt32), "Time threshold for high pressure alarm in seconds ", 0, 10800, 600));
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_PressureLowThreshold", typeof(UInt32), "Low pressure alarm threshold in Pa ", 0, 2550000, 30000));
|
|
RegisterSource.Add(new Tuple<String, Type, String, UInt32, UInt32, UInt32>("CUSTOMER_PressureLowDelay", typeof(UInt32), "Time threshold for low pressure alarm in seconds ", 0, 10800, 600));
|
|
var i = 0;
|
|
|
|
var currentHeight = 70;
|
|
foreach (var item in RegisterSource)
|
|
{
|
|
Label lblName = new Label();
|
|
Label lblType = new Label();
|
|
Label lblMin = new Label();
|
|
Label lblMax = new Label();
|
|
Label lblDefault = new Label();
|
|
TextBox txtDesc = new TextBox();
|
|
|
|
NumericUpDown nud = new NumericUpDown();
|
|
|
|
nud.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((Byte)(0)));
|
|
nud.Location = new System.Drawing.Point(230, currentHeight);
|
|
nud.Name = $"nudc{i}";
|
|
nud.Size = new System.Drawing.Size(140, 25);
|
|
nud.Tag = item;
|
|
|
|
nud.Minimum = item.Item4;
|
|
nud.Maximum = item.Item5;
|
|
|
|
|
|
registerControls.Add(nud);
|
|
//
|
|
// lblc1
|
|
//
|
|
lblName.AutoSize = true;
|
|
lblName.Location = new System.Drawing.Point(10, currentHeight);
|
|
lblName.Name = $"lblName{i}";
|
|
lblName.Size = new System.Drawing.Size(220, 15);
|
|
lblName.Text = item.Item1;
|
|
|
|
|
|
currentHeight = currentHeight + 25;
|
|
|
|
txtDesc.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((Byte)(0)));
|
|
|
|
txtDesc.Enabled = false;
|
|
txtDesc.Multiline = true;
|
|
txtDesc.Name = $"txtDesc{i}";
|
|
txtDesc.Location = new System.Drawing.Point(10, currentHeight);
|
|
txtDesc.Size = new System.Drawing.Size(480, 20);
|
|
txtDesc.Text = $"Def={item.Item6} Min={item.Item4} Max={item.Item5} Desc={item.Item3.Trim()}";
|
|
|
|
|
|
currentHeight = currentHeight + 25;
|
|
|
|
|
|
i = i + 1;
|
|
groupBox5.Controls.Add(lblName);
|
|
groupBox5.Controls.Add(nud);
|
|
groupBox5.Controls.Add(txtDesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
//CUSTOMER StoreConfiguration UInt32 Store all configuration items in non-volatile memory.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void btnRead_Click(Object sender, EventArgs e)
|
|
{
|
|
if (_currentGenesis != null)
|
|
{
|
|
clbAlarms.ItemCheck -= clbAlarms_ItemCheck;
|
|
var cAlarm = _currentGenesis.GetAlarms();
|
|
//MessageBox.Show($"Checkalarm EMPTY_PIPE = { _currentGenesis.HasAlarms(Alarm.EMPTY_PIPE)}");
|
|
|
|
clbAlarms.Items.Clear();
|
|
foreach (Alarm suit in (Alarm[])Enum.GetValues(typeof(Alarm)))
|
|
{
|
|
|
|
clbAlarms.Items.Add(suit, cAlarm.HasFlag(suit));
|
|
}
|
|
clbAlarms.ItemCheck += clbAlarms_ItemCheck;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(@"not connected");
|
|
}
|
|
}
|
|
private void clbAlarms_SelectedIndexChanged(Object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
private void clbAlarms_ItemCheck(Object sender, ItemCheckEventArgs e)
|
|
{
|
|
if (e.NewValue == CheckState.Checked)
|
|
{
|
|
MessageBox.Show(@"Alarms cannot write, they have to set by meter");
|
|
e.NewValue = CheckState.Unchecked;
|
|
}
|
|
else if (e.NewValue == CheckState.Unchecked)
|
|
{
|
|
if (_currentGenesis != null)
|
|
{
|
|
//_currentGenesis.ResetAlarm(Alarm.EMPTY_PIPE | Alarm.REBOOT);
|
|
var allEnums = ((Alarm[])Enum.GetValues(typeof(Alarm)));
|
|
if (allEnums.Length > e.Index)
|
|
{
|
|
_currentGenesis.ResetAlarm(allEnums[e.Index]);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void FrmAlarmMng_FormClosing(Object sender, FormClosingEventArgs e)
|
|
{
|
|
|
|
_currentGenesis?.Dispose();
|
|
_meterBatch?.Dispose();
|
|
}
|
|
|
|
private void btnReadAEM_Click(Object sender, EventArgs e)
|
|
{
|
|
ReadAlarm("CUSTOMER_AlarmEnableMask", lblAEM, clbAEM);
|
|
}
|
|
|
|
private Boolean lockEvents = false;
|
|
private void ReadAlarm(String registerName, Label resultLable, CheckedListBox clb)
|
|
{
|
|
if (_currentGenesis != null && _currentGenesis.IsLoggedOn)
|
|
{
|
|
lockEvents = true;
|
|
clb.Items.Clear();
|
|
|
|
|
|
var registerContent = _currentGenesis.ReadRegister(registerName).ToList();
|
|
|
|
var hashCode = RegisterConverter.ByteArrayToValue<UInt32>(registerContent.ToArray());
|
|
registerContent.Reverse();
|
|
resultLable.Text = ByteStyler.ToString(registerContent.ToArray());
|
|
var fullAlarm = (AlarmMask)hashCode;
|
|
var codeCounter = 0;
|
|
foreach (AlarmMask alarm in (AlarmMask[])Enum.GetValues(typeof(AlarmMask)))
|
|
{
|
|
var ItemChecked = fullAlarm.HasFlag(alarm);
|
|
clb.Items.Add($"{alarm.ToString()}(Code{codeCounter})", ItemChecked);
|
|
codeCounter = codeCounter + 1;
|
|
}
|
|
lockEvents = false;
|
|
}
|
|
}
|
|
|
|
|
|
private void setAlarm(String registerName, Label resultLable, CheckedListBox clb, Int32 changedIndex, Boolean changedValue)
|
|
{
|
|
if (lockEvents)
|
|
{
|
|
return;
|
|
}
|
|
if (_currentGenesis != null && _currentGenesis.IsLoggedOn)
|
|
{
|
|
lockEvents = true;
|
|
AlarmMask helper = 0;
|
|
UInt32 sumIChecked = 0;
|
|
StringBuilder sb = new StringBuilder();
|
|
for (Int32 i = 0; i < clb.Items.Count; i++)
|
|
{
|
|
if (i == changedIndex)
|
|
{
|
|
if (changedValue)
|
|
{
|
|
sb.AppendLine($"{i} << 1");
|
|
sumIChecked = sumIChecked + (UInt32)(1 << (i));
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
else if (clb.GetItemChecked(i))
|
|
{
|
|
//sb.Append("=1;");
|
|
//helper = helper.GetHashCode() + ((AlarmMaskOrigin)i) >> 1;
|
|
sb.AppendLine($"{i} << 1");
|
|
sumIChecked = sumIChecked + (UInt32)(1 << (i));
|
|
}
|
|
else
|
|
{
|
|
//sb.Append("=0;");
|
|
}
|
|
|
|
}
|
|
//40915
|
|
var binHelper = RegisterConverter.ValueToByteArray(sumIChecked);
|
|
binHelper.Reverse();
|
|
|
|
|
|
_currentGenesis.WriteRegister(registerName, sumIChecked, true, true);
|
|
_currentGenesis.WriteRegister(registerName, new Byte[] { 0x00, 0x00, 0x80, 0x53 }.Reverse().ToArray(), true, true);
|
|
|
|
resultLable.Text = ByteStyler.ToString(binHelper);
|
|
lockEvents = false;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private void btnABM_Click(Object sender, EventArgs e)
|
|
{
|
|
ReadAlarm("CUSTOMER_AlarmBroadcastMask", lblABM, clbABM);
|
|
}
|
|
|
|
private void btnAVM_Click(Object sender, EventArgs e)
|
|
{
|
|
ReadAlarm("CUSTOMER_AlarmVisualMask", lblAVM, clbAVM);
|
|
}
|
|
|
|
private void clbABM_SelectedIndexChanged(Object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void clbAVM_SelectedIndexChanged(Object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void clbAEM_ItemCheck(Object sender, ItemCheckEventArgs e)
|
|
{
|
|
|
|
setAlarm("CUSTOMER_AlarmEnableMask", lblAEM, clbAEM, e.Index, e.NewValue == CheckState.Checked);
|
|
}
|
|
|
|
private void clbAEM_SelectedIndexChanged(Object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void clbABM_ItemCheck(Object sender, ItemCheckEventArgs e)
|
|
{
|
|
setAlarm("CUSTOMER_AlarmBroadcastMask", lblABM, clbABM, e.Index, e.NewValue == CheckState.Checked);
|
|
}
|
|
|
|
private void clbAVM_ItemCheck(Object sender, ItemCheckEventArgs e)
|
|
{
|
|
setAlarm("CUSTOMER_AlarmVisualMask", lblAVM, clbAVM, e.Index, e.NewValue == CheckState.Checked);
|
|
}
|
|
|
|
private void button1_Click(Object sender, EventArgs e)
|
|
{
|
|
//read
|
|
if (_currentGenesis != null && _currentGenesis.IsLoggedOn)
|
|
{
|
|
foreach (var nud in registerControls)
|
|
{
|
|
if (nud.Tag is Tuple<String, Type, String, UInt32, UInt32, UInt32> source)
|
|
{
|
|
var a = _currentGenesis.ReadRegister(source.Item1);
|
|
if (source.Item2 == typeof(UInt32))
|
|
{
|
|
nud.Value = RegisterConverter.ByteArrayToValue<UInt32>(a);
|
|
}
|
|
else if (source.Item2 == typeof(UInt16))
|
|
{
|
|
nud.Value = RegisterConverter.ByteArrayToValue<UInt16>(a);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void button2_Click(Object sender, EventArgs e)
|
|
{
|
|
//write
|
|
|
|
}
|
|
|
|
private void button3_Click(Object sender, EventArgs e)
|
|
{
|
|
if (_currentGenesis != null && _currentGenesis.IsLoggedOn)
|
|
{
|
|
_currentGenesis.WriteRegister("SENSUSRADIO_SYSTEMSTATE", 0xFF, true, false);
|
|
}
|
|
}
|
|
|
|
private void button4_Click(Object sender, EventArgs e)
|
|
{
|
|
if (_currentGenesis != null && _currentGenesis.IsLoggedOn)
|
|
{
|
|
_currentGenesis.Logout();
|
|
}
|
|
}
|
|
|
|
private void btnReadMain_Click(Object sender, EventArgs e)
|
|
{
|
|
if (_currentGenesis != null && _currentGenesis.IsLoggedOn)
|
|
{
|
|
var registerContent = _currentGenesis.ReadRegister("SENSUSRADIO_MainAlarmMask").ToList();
|
|
var hashCode = RegisterConverter.ByteArrayToValue<UInt32>(registerContent.ToArray());
|
|
registerContent.Reverse();
|
|
lblSENSUSRADIO_MainAlarmMask.Text = ByteStyler.ToString(registerContent.ToArray());
|
|
|
|
|
|
registerContent = _currentGenesis.ReadRegister("SENSUSRADIO_ExtendedAlarmMask").ToList();
|
|
hashCode = RegisterConverter.ByteArrayToValue<UInt32>(registerContent.ToArray());
|
|
registerContent.Reverse();
|
|
lblRadioExt.Text = ByteStyler.ToString(registerContent.ToArray());
|
|
}
|
|
}
|
|
|
|
private void btnRadioExt_Click(Object sender, EventArgs e)
|
|
{
|
|
if (_currentGenesis != null && _currentGenesis.IsLoggedOn)
|
|
{
|
|
_currentGenesis.WriteRegister("SENSUSRADIO_SYSTEMSTATE", 0xFF, true, false);
|
|
}
|
|
}
|
|
|
|
private void button5_Click(Object sender, EventArgs e)
|
|
{
|
|
if (_currentGenesis != null && _currentGenesis.IsLoggedOn)
|
|
{
|
|
_currentGenesis.ResetAlarm(Alarm.ALL);
|
|
}
|
|
}
|
|
private void finishMeter(GenesisMeter Meter)
|
|
{
|
|
Meter.ResetAlarm(Alarm.ALL);//(true, new byte[] { 0x00, 0x00, 0x00, 0x01 });
|
|
|
|
Meter.SetLcdText(true, new Byte[] { 0x00, 0x00, 0x00, 0x01 });
|
|
|
|
Meter.ResetAlarm(Alarm.EMPTY_PIPE);//(true, new byte[] { 0x00, 0x00, 0x00, 0x01 });
|
|
_currentGenesis.WriteRegister(Register.Metrologyasst.PulseMode, 5, true, true);
|
|
var useRadio = true;
|
|
if (useRadio)
|
|
{
|
|
if (Meter.StoreAllConfigurations())
|
|
{
|
|
|
|
var writeList = new List<Boolean>();
|
|
|
|
writeList.Add(Meter.WriteRegister("SENSUSRADIO_SystemState", 1, true, false));
|
|
writeList.Add(Meter.WriteRegister("SENSUSRADIO_MainAlarmMask", 0, true, false));
|
|
writeList.Add(Meter.WriteRegister("SENSUSRADIO_ExtendedAlarmMask", 0, true, false));
|
|
|
|
|
|
|
|
writeList.Add(Meter.WriteRegister("SENSUSRADIO_SystemState", 0xFF, true, false));
|
|
//Thread.Sleep(5000);
|
|
Meter.Logout();
|
|
Thread.Sleep(5000);
|
|
Meter.ReLogin();
|
|
var radioResetSuccess = Meter.ReadRegister("SENSUSRADIO_SystemState");
|
|
var SENSUSRADIO_MainAlarmMask = Meter.ReadRegister("SENSUSRADIO_MainAlarmMask");
|
|
var SENSUSRADIO_ExtendedAlarmMask = Meter.ReadRegister("SENSUSRADIO_ExtendedAlarmMask");
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void btnConnect_Click(Object sender, EventArgs e)
|
|
{
|
|
Int32 slotNR = 0;
|
|
if (!string.IsNullOrEmpty(cbComSlot.SelectedItem.ToString()) &&
|
|
int.TryParse(cbComSlot.SelectedItem.ToString(), out slotNR))
|
|
{
|
|
try
|
|
{
|
|
button6.Enabled = false;
|
|
button7.Enabled = false;
|
|
_meterBatch.RemoveAllMeters();
|
|
_currentGenesis = new GenesisMeter();
|
|
|
|
_currentGenesis.SetupFromConfigFile(slotNR);
|
|
// _currentGenesis.EnableAutoLogon();
|
|
_meterBatch.AddMeter(_currentGenesis);
|
|
|
|
if (_currentGenesis.Login())
|
|
{
|
|
_currentGenesis.WriteRegister(Register.Metrologyasst.PulseMode, 0);
|
|
button6.Enabled = true;
|
|
button7.Enabled = false;
|
|
MessageBox.Show(@"Weiter");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(@"Noch mal 1. Connect");
|
|
}
|
|
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void button6_Click(Object sender, EventArgs e)
|
|
{
|
|
_currentGenesis.WriteRegister("CUSTOMER_AlarmEnableMask", new Byte[] { 0x00, 0x00, 0x9F, 0xDC }.Reverse().ToArray());
|
|
_currentGenesis.WriteRegister("CUSTOMER_AlarmBroadcastMask", new Byte[] { 0x00, 0x00, 0x80, 0x53 }.Reverse().ToArray());
|
|
_currentGenesis.WriteRegister("CUSTOMER_AlarmVisualMask", new Byte[] { 0x00, 0x00, 0x9F, 0xDC }.Reverse().ToArray());
|
|
|
|
|
|
|
|
|
|
|
|
ReadAlarm("CUSTOMER_AlarmEnableMask", lblAEM, clbAEM);
|
|
ReadAlarm("CUSTOMER_AlarmBroadcastMask", lblABM, clbABM);
|
|
ReadAlarm("CUSTOMER_AlarmVisualMask", lblAVM, clbAVM);
|
|
|
|
var cAlarm = _currentGenesis.GetAlarms();
|
|
//MessageBox.Show($"Checkalarm EMPTY_PIPE = { _currentGenesis.HasAlarms(Alarm.EMPTY_PIPE)}");
|
|
|
|
Boolean retry = false;
|
|
Boolean roland = false;
|
|
|
|
|
|
if (lblAEM.Text == "00-00-80-53" && lblABM.Text == "00-00-1F-DC" && lblAVM.Text == "00-00-1F-DC")
|
|
{
|
|
if (cAlarm == Alarm.EMPTY_PIPE)
|
|
{
|
|
MessageBox.Show(@"weiter");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(@"Emptypipe fehlt bitte vor dem verpacken überprüfen");
|
|
}
|
|
|
|
button7.Enabled = true;
|
|
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(@"fehler");
|
|
}
|
|
}
|
|
|
|
private void button7_Click(Object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
finishMeter(_currentGenesis);
|
|
File.AppendAllText("WriteLines.txt", _currentGenesis.PcbId + "mit Update;");
|
|
MessageBox.Show(@"fertig");
|
|
|
|
button6.Enabled = false;
|
|
button7.Enabled = false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
File.AppendAllText("WriteLinesError.txt", ex.Message);
|
|
if (ex.Message.Contains("Check the configuration.json for latest version!"))
|
|
{
|
|
_currentGenesis.Login();
|
|
MessageBox.Show(@"Wiederholen 3.");
|
|
}
|
|
MessageBox.Show(@"fehler");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void button8_Click(Object sender, EventArgs e)
|
|
{
|
|
checkedListBox1.ItemCheck -= checkedListBox1_ItemCheck;
|
|
|
|
checkedListBox1.Items.Clear();
|
|
foreach (DataLoggerMask suit in (DataLoggerMask[])Enum.GetValues(typeof(DataLoggerMask)))
|
|
{
|
|
|
|
checkedListBox1.Items.Add(suit, false);
|
|
}
|
|
checkedListBox1.ItemCheck += checkedListBox1_ItemCheck;
|
|
|
|
|
|
// setze 1 - um die einstellung zu aktivieren
|
|
var content = 1 << LoggingContent.AlarmStatus
|
|
| 1 << LoggingContent.BillingCounter
|
|
| 0 << LoggingContent.ReverseCounter
|
|
| 1 << LoggingContent.MaxFlow
|
|
| 1 << LoggingContent.MaxFlowTime
|
|
| 0 << LoggingContent.PeakFlow
|
|
| 0 << LoggingContent.PeakFlowTime
|
|
| 0 << LoggingContent.AvgFlow
|
|
| 0 << LoggingContent.BrokenPipe
|
|
| 0 << LoggingContent.BrokenPipeTime
|
|
| 0 << LoggingContent.MinFlow
|
|
| 0 << LoggingContent.MinFlowTime
|
|
| 0 << LoggingContent.ForwardCounter
|
|
| 0 << LoggingContent._UTC32
|
|
| 0 << LoggingContent._MaskSelector_1_1
|
|
| 0 << LoggingContent._MaskSelector_1_2
|
|
| 0 << LoggingContent.MinPress
|
|
| 0 << LoggingContent.MinPressTime
|
|
| 0 << LoggingContent.MaxPress
|
|
| 0 << LoggingContent.MaxPressTime
|
|
| 0 << LoggingContent.MinTemp
|
|
| 0 << LoggingContent.MinTempTime
|
|
| 0 << LoggingContent.MaxTemp
|
|
| 0 << LoggingContent.MaxTempTime
|
|
| 0 << LoggingContent.CurrentPress
|
|
| 0 << LoggingContent.CurrentTemp
|
|
| 1 << LoggingContent.ExtendedAlarm
|
|
| 0 << LoggingContent._RecordCheckSum
|
|
| 0 << LoggingContent._Reserved_1
|
|
| 0 << LoggingContent._Reserved_2
|
|
| 0 << LoggingContent._MaskSelector_2_1
|
|
| 0 << LoggingContent._MaskSelector_2_2;
|
|
|
|
var contentBytes = BitConverter.GetBytes(content);
|
|
Array.Reverse(contentBytes);
|
|
Console.WriteLine($"CONTENT: {content} - {BitConverter.ToString(contentBytes)}");
|
|
// CONTENT: 67110031 - 04-00-04-8F
|
|
|
|
}
|
|
|
|
private void checkedListBox1_SelectedIndexChanged(Object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void setLogger(String registerName, Label resultLable, CheckedListBox clb, Int32 changedIndex, Boolean changedValue)
|
|
{
|
|
if (lockEvents)
|
|
{
|
|
return;
|
|
}
|
|
|
|
lockEvents = true;
|
|
DataLoggerMask helper = 0;
|
|
UInt32 sumIChecked = 0;
|
|
StringBuilder sb = new StringBuilder();
|
|
for (Int32 i = 0; i < clb.Items.Count; i++)
|
|
{
|
|
if (i == changedIndex)
|
|
{
|
|
if (changedValue)
|
|
{
|
|
sb.AppendLine($"{i} << 1");
|
|
sumIChecked = sumIChecked + (UInt32)(1 << (i));
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
else if (clb.GetItemChecked(i))
|
|
{
|
|
//sb.Append("=1;");
|
|
//helper = helper.GetHashCode() + ((AlarmMaskOrigin)i) >> 1;
|
|
sb.AppendLine($"{i} << 1");
|
|
sumIChecked = sumIChecked + (UInt32)(1 << (i));
|
|
}
|
|
else
|
|
{
|
|
//sb.Append("=0;");
|
|
}
|
|
|
|
}
|
|
//40915
|
|
var binHelper = RegisterConverter.ValueToByteArray(sumIChecked);
|
|
binHelper.Reverse();
|
|
|
|
|
|
|
|
resultLable.Text = ByteStyler.ToString(binHelper);
|
|
lockEvents = false;
|
|
|
|
|
|
}
|
|
|
|
private void checkedListBox1_ItemCheck(Object sender, ItemCheckEventArgs e)
|
|
{
|
|
setLogger("loger", label12, checkedListBox1, e.Index, e.NewValue == CheckState.Checked);
|
|
}
|
|
}
|
|
}
|