102 lines
2.7 KiB
C#
102 lines
2.7 KiB
C#
using System;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
|
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
|
|
|
namespace Xylem.Common.Ui.GenesisToolBox
|
|
{
|
|
public partial class FrmCustomerText : Form
|
|
{
|
|
private GenesisMeter _currentGenesis;
|
|
private MeterBatch _meterBatch = new MeterBatch();
|
|
public FrmCustomerText()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
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
|
|
{
|
|
_meterBatch.RemoveAllMeters();
|
|
_currentGenesis = new GenesisMeter();
|
|
|
|
_currentGenesis.SetupFromConfigFile(slotNR);
|
|
_currentGenesis.EnableAutoLogon();
|
|
_meterBatch.AddMeter(_currentGenesis);
|
|
|
|
_meterBatch.MetersLogin();
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnRead_Click(Object sender, EventArgs e)
|
|
{
|
|
if (_currentGenesis != null)
|
|
{
|
|
var rawText = _currentGenesis.ReadRegister("SENSUSRADIO_CustomerText", 50);
|
|
if (rawText == null)
|
|
{
|
|
rtbCustomerText.Text = "";
|
|
}
|
|
else
|
|
{
|
|
rtbCustomerText.Text = Encoding.ASCII.GetString(rawText).Split('\0')[0];
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(@"not connected");
|
|
}
|
|
}
|
|
private void btnWriteText_Click(Object sender, EventArgs e)
|
|
{
|
|
if (_currentGenesis != null)
|
|
{
|
|
var rawText = Encoding.ASCII.GetBytes(rtbCustomerText.Text);
|
|
|
|
var r = _currentGenesis.WriteRegister("SENSUSRADIO_CustomerText", rawText);
|
|
|
|
if (r)
|
|
{
|
|
MessageBox.Show($@"Write was successful");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show($@"Write was unsuccessful!");
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(@"not connected");
|
|
}
|
|
}
|
|
|
|
|
|
private void FrmAlarmMng_FormClosing(Object sender, FormClosingEventArgs e)
|
|
{
|
|
|
|
_currentGenesis?.Dispose();
|
|
_meterBatch?.Dispose();
|
|
}
|
|
|
|
|
|
}
|
|
}
|