2025-01-24 11:50:32 +03:00
|
|
|
|
using System;
|
2025-01-24 11:46:36 +03:00
|
|
|
|
using System.Collections;
|
2024-12-05 15:57:07 +03:00
|
|
|
|
using System.Collections.Generic;
|
2025-03-06 10:16:30 +03:00
|
|
|
|
using System.Diagnostics;
|
2024-12-05 15:57:07 +03:00
|
|
|
|
using System.Drawing;
|
2025-02-28 18:00:17 +03:00
|
|
|
|
using System.IO;
|
2024-12-06 16:32:10 +03:00
|
|
|
|
using System.IO.Ports;
|
2024-12-05 15:57:07 +03:00
|
|
|
|
using System.Linq;
|
2025-03-06 10:16:30 +03:00
|
|
|
|
using System.Security.Cryptography;
|
2025-02-28 18:00:17 +03:00
|
|
|
|
using System.Threading;
|
2024-12-05 15:57:07 +03:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Gidrolock_Modbus_Scanner
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class Datasheet : Form
|
|
|
|
|
|
{
|
2025-01-14 11:31:23 +03:00
|
|
|
|
byte modbusID;
|
|
|
|
|
|
Device device;
|
|
|
|
|
|
|
2025-04-09 15:26:50 +03:00
|
|
|
|
public static ModbusResponseEventArgs latestMessage;
|
2025-01-21 14:38:59 +03:00
|
|
|
|
|
2025-01-14 11:31:23 +03:00
|
|
|
|
SerialPort port = Modbus.port;
|
2024-12-16 11:35:20 +03:00
|
|
|
|
bool isPolling = false;
|
2025-03-06 10:16:30 +03:00
|
|
|
|
static bool isAwaitingResponse = false;
|
2025-03-07 16:49:07 +03:00
|
|
|
|
static bool responseReceived = false;
|
2025-01-21 14:38:59 +03:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-08 17:11:57 +03:00
|
|
|
|
bool isValveClosed = false;
|
2025-01-21 14:38:59 +03:00
|
|
|
|
bool alarmStatus = false;
|
|
|
|
|
|
bool cleaningStatus = false;
|
2024-12-09 16:24:02 +03:00
|
|
|
|
|
2025-01-24 11:46:36 +03:00
|
|
|
|
List<WiredSensor> wiredSensors = new List<WiredSensor>();
|
|
|
|
|
|
List<WirelessSensor> wirelessSensors;
|
2025-02-28 18:00:17 +03:00
|
|
|
|
public static string firmwarePath;
|
2025-01-24 11:46:36 +03:00
|
|
|
|
|
2025-03-06 10:16:30 +03:00
|
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
2025-02-28 18:00:17 +03:00
|
|
|
|
Thread fileThread = new Thread((ThreadStart)delegate
|
|
|
|
|
|
{
|
|
|
|
|
|
OpenFileDialog ofd = new OpenFileDialog();
|
|
|
|
|
|
ofd.InitialDirectory = Application.StartupPath;
|
|
|
|
|
|
ofd.RestoreDirectory = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (ofd.ShowDialog() == DialogResult.OK)
|
|
|
|
|
|
firmwarePath = ofd.FileName;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-03-06 10:16:30 +03:00
|
|
|
|
public Datasheet(byte modbusID, Device device) : base()
|
2024-12-05 15:57:07 +03:00
|
|
|
|
{
|
2025-01-24 11:46:36 +03:00
|
|
|
|
InitializeComponent();
|
2025-03-06 10:16:30 +03:00
|
|
|
|
firmwareProgressBar.Minimum = 0;
|
|
|
|
|
|
firmwareProgressBar.Maximum = 100;
|
2025-01-14 11:31:23 +03:00
|
|
|
|
nudModbusID.Minimum = 1;
|
|
|
|
|
|
nudModbusID.Maximum = 246;
|
2025-01-24 11:46:36 +03:00
|
|
|
|
nudModbusID.Value = modbusID;
|
2025-01-14 11:31:23 +03:00
|
|
|
|
this.modbusID = modbusID;
|
|
|
|
|
|
this.device = device;
|
2025-01-21 14:38:59 +03:00
|
|
|
|
|
2025-01-24 17:54:04 +03:00
|
|
|
|
cBoxSpeed.Items.Add("1200");
|
|
|
|
|
|
cBoxSpeed.Items.Add("2400");
|
|
|
|
|
|
cBoxSpeed.Items.Add("4800");
|
|
|
|
|
|
cBoxSpeed.Items.Add("9600");
|
|
|
|
|
|
cBoxSpeed.Items.Add("14400");
|
|
|
|
|
|
cBoxSpeed.Items.Add("19200");
|
|
|
|
|
|
cBoxSpeed.Items.Add("38400");
|
|
|
|
|
|
cBoxSpeed.Items.Add("57600");
|
|
|
|
|
|
cBoxSpeed.Items.Add("115200");
|
|
|
|
|
|
cBoxSpeed.Text = port.BaudRate.ToString();
|
|
|
|
|
|
|
2025-01-24 11:46:36 +03:00
|
|
|
|
labelModel.Text = device.name;
|
|
|
|
|
|
labelFirmware.Text = "v???";
|
|
|
|
|
|
|
2025-01-21 14:38:59 +03:00
|
|
|
|
if (!device.hasCleaningMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
labelCleaning.Text = "Недоступна.";
|
|
|
|
|
|
buttonCleaning.Enabled = false;
|
|
|
|
|
|
}
|
2025-01-24 11:46:36 +03:00
|
|
|
|
if (!device.hasBattery)
|
|
|
|
|
|
labelBattery.Text = "Нет";
|
|
|
|
|
|
else labelBattery.Text = "???%";
|
|
|
|
|
|
|
2025-03-07 16:49:07 +03:00
|
|
|
|
Modbus.ResponseReceived += (sndr, msg) => { responseReceived = true; latestMessage = msg; isAwaitingResponse = false; };
|
2025-01-21 14:38:59 +03:00
|
|
|
|
|
2025-01-24 11:46:36 +03:00
|
|
|
|
for (int i = 0; i < device.wiredSensors; i++)
|
|
|
|
|
|
{
|
2025-06-24 10:09:11 +03:00
|
|
|
|
WiredSensor ws = new WiredSensor(i,device) { Width = 495, Height = 24 };
|
2025-01-24 11:46:36 +03:00
|
|
|
|
sensorPanel.Controls.Add(ws);
|
|
|
|
|
|
ws.Visible = true;
|
2025-02-28 18:00:17 +03:00
|
|
|
|
|
2025-06-24 10:09:11 +03:00
|
|
|
|
if (device.modelName == "PRPLS1")
|
|
|
|
|
|
{
|
|
|
|
|
|
ws.wspPlusEntry = device.wspPlusMode[i];
|
|
|
|
|
|
ws.wspPlusCheckbox.CheckedChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ushort value = ws.wspPlusCheckbox.Checked ? (ushort)0xFF00 : (ushort)0x0000;
|
|
|
|
|
|
SetEntry(ws.wspPlusEntry, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception err) { MessageBox.Show(err.Message, "WSP+ toggle error"); }
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2025-01-24 11:46:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
if (device.hasScenarioSensor)
|
|
|
|
|
|
{
|
|
|
|
|
|
ScenarioSensor scenSen = new ScenarioSensor() { Width = 495, Height = 24 };
|
|
|
|
|
|
sensorPanel.Controls.Add(scenSen);
|
|
|
|
|
|
scenSen.Visible = true;
|
|
|
|
|
|
}
|
2025-01-24 17:54:04 +03:00
|
|
|
|
if (device.wiredSensors < device.sensorAlarm.length)
|
2025-01-21 14:38:59 +03:00
|
|
|
|
{
|
2025-01-24 11:46:36 +03:00
|
|
|
|
wirelessSensors = new List<WirelessSensor>();
|
2025-01-24 17:54:04 +03:00
|
|
|
|
int wsrIndex = device.sensorAlarm.length - device.wiredSensors - (device.hasScenarioSensor ? 1 : 0);
|
2025-01-24 11:46:36 +03:00
|
|
|
|
for (int i = 0; i < wsrIndex; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
WirelessSensor wsr = new WirelessSensor(i) { Width = 495, Height = 24 };
|
|
|
|
|
|
sensorPanel.Controls.Add(wsr);
|
|
|
|
|
|
wsr.Visible = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sensorPanel.Controls.Count; i++)
|
|
|
|
|
|
sensorPanel.Controls[i].BackColor = i % 2 == 0 ? Color.White : Color.LightGray;
|
2025-01-21 14:38:59 +03:00
|
|
|
|
|
2025-01-24 11:46:36 +03:00
|
|
|
|
|
2025-03-06 10:16:30 +03:00
|
|
|
|
sensorPanel.Update();
|
2025-01-21 14:38:59 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void buttonPoll_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
if (isPolling)
|
|
|
|
|
|
return;
|
2025-01-21 14:38:59 +03:00
|
|
|
|
// hardcoded for now, probably easier to keep it like this in the future
|
2025-01-24 11:46:36 +03:00
|
|
|
|
try
|
2025-01-21 14:38:59 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
await Task.Run(() =>
|
2025-02-17 15:50:15 +03:00
|
|
|
|
{
|
|
|
|
|
|
|
2025-04-09 15:26:50 +03:00
|
|
|
|
bool res = PollEntry(device.firmware);
|
|
|
|
|
|
Console.WriteLine("Polling for alarm status, poll success: " + res);
|
2025-02-17 15:50:15 +03:00
|
|
|
|
if (res)
|
|
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
this.Invoke(new MethodInvoker(delegate { labelFirmware.Text = App.ByteArrayToUnicode(latestMessage.Data); }));
|
2025-02-17 15:50:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-09 15:26:50 +03:00
|
|
|
|
if (device.hasBattery)
|
2025-01-24 11:46:36 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
res = PollEntry(device.batteryCharge);
|
|
|
|
|
|
if (res)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { labelBattery.Text = latestMessage.Data.Last().ToString(); }));
|
|
|
|
|
|
}
|
2025-01-24 11:46:36 +03:00
|
|
|
|
}
|
2025-02-17 15:50:15 +03:00
|
|
|
|
|
2025-04-09 15:26:50 +03:00
|
|
|
|
res = PollEntry(device.valveStatus);
|
|
|
|
|
|
Console.WriteLine("Polling for valve status, poll success: " + res);
|
|
|
|
|
|
if (res)
|
2025-01-24 11:46:36 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
if (latestMessage.Data.Last() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
isValveClosed = true;
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { labelValve.Text = "Закрыт"; }));
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { buttonValve.Text = "Открыть"; }));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
isValveClosed = false;
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { labelValve.Text = "Открыт"; }));
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { buttonValve.Text = "Закрыть"; }));
|
|
|
|
|
|
}
|
2025-01-24 11:46:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-09 15:26:50 +03:00
|
|
|
|
res = PollEntry(device.alarmStatus);
|
|
|
|
|
|
Console.WriteLine("Polling for alarm status, poll success: " + res);
|
2025-01-24 11:46:36 +03:00
|
|
|
|
if (res)
|
|
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
Console.WriteLine("Alarm data: " + Modbus.ByteArrayToString(latestMessage.Data));
|
|
|
|
|
|
Console.WriteLine("Alarm data.last: " + latestMessage.Data.Last().ToString());
|
2025-01-24 11:46:36 +03:00
|
|
|
|
if (latestMessage.Data.Last() > 0)
|
|
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
alarmStatus = true;
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { buttonAlarm.Text = "Выключить"; }));
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { labelAlarm.Text = "Протечка!"; }));
|
2025-01-24 11:46:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
alarmStatus = false;
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { buttonAlarm.Text = "Авария"; }));
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { labelAlarm.Text = "нет"; }));
|
2025-01-24 11:46:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-09 15:26:50 +03:00
|
|
|
|
if (device.hasCleaningMode)
|
2025-04-02 12:40:39 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
res = PollEntry(device.cleaningMode);
|
2025-04-02 12:40:39 +03:00
|
|
|
|
if (res)
|
|
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
if (latestMessage.Data.Last() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
cleaningStatus = true;
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { buttonCleaning.Text = "Выключить"; }));
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { labelCleaning.Text = "вкл"; }));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
cleaningStatus = false;
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { buttonCleaning.Text = "Включить"; }));
|
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate { labelCleaning.Text = "выкл"; }));
|
|
|
|
|
|
}
|
2025-04-02 12:40:39 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-24 10:09:11 +03:00
|
|
|
|
if (device.wspPlusMode != null || device.wspPlusMode.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
for(int i = 0; i < device.wspPlusMode.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
res = PollEntry(device.wspPlusMode[i]);
|
|
|
|
|
|
if (res)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool value = latestMessage.Data[0] > 0x00 ? true : false;
|
|
|
|
|
|
WiredSensor snsr = sensorPanel.Controls[i] as WiredSensor;
|
|
|
|
|
|
snsr.Invoke(new MethodInvoker(delegate { snsr.wspPlusCheckbox.Checked = value; }));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-09 15:26:50 +03:00
|
|
|
|
if (device.wiredLineBreak != null || device.wiredLineBreak.Count > 0)
|
2025-01-24 11:46:36 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
for (int i = 0; i < device.wiredLineBreak.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
res = PollEntry(device.wiredLineBreak[i]);
|
|
|
|
|
|
if (res)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool value = latestMessage.Data[0] > 0x00 ? true : false;
|
|
|
|
|
|
WiredSensor snsr = sensorPanel.Controls[i] as WiredSensor;
|
|
|
|
|
|
snsr.Invoke(new MethodInvoker(delegate { snsr.labelBreak.Text = value ? "Обрыв!" : "ОК"; }));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-01-24 11:46:36 +03:00
|
|
|
|
}
|
2025-01-24 17:54:04 +03:00
|
|
|
|
|
2025-04-09 15:26:50 +03:00
|
|
|
|
res = PollEntry(device.sensorAlarm);
|
|
|
|
|
|
if (res)
|
2025-01-24 17:54:04 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
BitArray bArray = new BitArray(latestMessage.Data);
|
|
|
|
|
|
bool[] bools = new bool[bArray.Length];
|
|
|
|
|
|
bArray.CopyTo(bools, 0);
|
|
|
|
|
|
for (int i = 0; i < sensorPanel.Controls.Count; i++)
|
2025-01-24 17:54:04 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
Sensor snsr = sensorPanel.Controls[i] as Sensor;
|
|
|
|
|
|
snsr.Invoke(new MethodInvoker(delegate { snsr.labelLeak.Text = bools[i] ? "Протечка!" : "нет"; }));
|
2025-01-24 17:54:04 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-09 15:26:50 +03:00
|
|
|
|
Console.WriteLine("Polling for radio status");
|
|
|
|
|
|
res = PollEntry(device.radioStatus);
|
|
|
|
|
|
if (res)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<byte> values = new List<byte>(latestMessage.Data.Length / 2);
|
|
|
|
|
|
for (int i = 1; i < latestMessage.Data.Length; i += 2)
|
|
|
|
|
|
values.Add(latestMessage.Data[i]);
|
|
|
|
|
|
int add = device.wiredSensors + (device.hasScenarioSensor ? 1 : 0);
|
|
|
|
|
|
for (int i = 0; i < sensorPanel.Controls.Count - add; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
WirelessSensor snsr = sensorPanel.Controls[i + add] as WirelessSensor;
|
|
|
|
|
|
string txt = "нет";
|
|
|
|
|
|
switch (values[i])
|
|
|
|
|
|
{
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
txt = "норма";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
txt = "протечка";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
txt = "разряжен";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
txt = "потеря";
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
snsr.Invoke(new MethodInvoker(delegate { snsr.labelStatus.Text = txt; }));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-01-21 14:38:59 +03:00
|
|
|
|
}
|
2025-01-24 11:46:36 +03:00
|
|
|
|
catch (Exception err) { MessageBox.Show(err.Message); }
|
2024-12-06 16:32:10 +03:00
|
|
|
|
}
|
2024-12-05 17:52:25 +03:00
|
|
|
|
|
2025-04-09 15:26:50 +03:00
|
|
|
|
bool PollEntry(Entry entry)
|
2025-01-21 14:38:59 +03:00
|
|
|
|
{
|
2025-04-08 17:11:57 +03:00
|
|
|
|
latestMessage = null;
|
2025-01-24 11:46:36 +03:00
|
|
|
|
bool res = false;
|
2025-01-21 14:38:59 +03:00
|
|
|
|
isAwaitingResponse = true;
|
2025-04-09 15:26:50 +03:00
|
|
|
|
isPolling = true;
|
2025-03-06 10:16:30 +03:00
|
|
|
|
|
2025-04-08 17:11:57 +03:00
|
|
|
|
Modbus.ReadRegAsync(modbusID, (FunctionCode)entry.registerType, entry.address, entry.length);
|
2025-03-06 10:16:30 +03:00
|
|
|
|
stopwatch.Restart();
|
|
|
|
|
|
|
2025-04-08 17:11:57 +03:00
|
|
|
|
while (isAwaitingResponse && latestMessage == null)
|
2025-01-24 11:46:36 +03:00
|
|
|
|
{
|
2025-04-08 17:11:57 +03:00
|
|
|
|
if (stopwatch.ElapsedMilliseconds > 5000)
|
2025-01-24 11:46:36 +03:00
|
|
|
|
{
|
2025-03-06 10:16:30 +03:00
|
|
|
|
Console.WriteLine("Response timed out.");
|
|
|
|
|
|
break;
|
2025-01-24 11:46:36 +03:00
|
|
|
|
}
|
2025-03-06 10:16:30 +03:00
|
|
|
|
}
|
2025-01-24 11:46:36 +03:00
|
|
|
|
|
|
|
|
|
|
if (latestMessage != null && latestMessage.Status != ModbusStatus.Error)
|
|
|
|
|
|
res = true;
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Poll attempt finished");
|
2025-04-09 15:26:50 +03:00
|
|
|
|
isPolling = false;
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
|
|
|
|
|
bool SetEntry(Entry entry, ushort value)
|
|
|
|
|
|
{
|
|
|
|
|
|
latestMessage = null;
|
|
|
|
|
|
bool res = false;
|
|
|
|
|
|
isAwaitingResponse = true;
|
|
|
|
|
|
isPolling = true;
|
|
|
|
|
|
FunctionCode fc = FunctionCode.WriteCoil;
|
|
|
|
|
|
if (entry.registerType == RegisterType.Holding)
|
|
|
|
|
|
fc = FunctionCode.WriteRegister;
|
|
|
|
|
|
|
|
|
|
|
|
Modbus.WriteSingleAsync(fc, modbusID, entry.address, value);
|
|
|
|
|
|
stopwatch.Restart();
|
|
|
|
|
|
|
|
|
|
|
|
while (isAwaitingResponse && latestMessage == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (stopwatch.ElapsedMilliseconds > port.ReadTimeout)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("Response timed out.");
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (latestMessage != null && latestMessage.Status == ModbusStatus.WriteSuccess)
|
|
|
|
|
|
res = true;
|
|
|
|
|
|
isPolling = false;
|
2025-01-24 11:46:36 +03:00
|
|
|
|
return res;
|
|
|
|
|
|
}
|
2025-01-21 14:38:59 +03:00
|
|
|
|
|
2025-03-19 15:27:37 +03:00
|
|
|
|
// Задать новый Slave ID для устройства
|
2025-01-24 11:46:36 +03:00
|
|
|
|
private async void buttonSetID_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte newID = (byte)nudModbusID.Value; // should prevent assigning wrong ID if UpDown is fiddled with in the middle of request
|
2025-03-06 10:16:30 +03:00
|
|
|
|
isAwaitingResponse = true;
|
2025-04-08 17:11:57 +03:00
|
|
|
|
latestMessage = null;
|
2025-01-24 11:46:36 +03:00
|
|
|
|
Modbus.WriteSingleAsync(FunctionCode.WriteRegister, modbusID, 128, newID);
|
2025-03-06 10:16:30 +03:00
|
|
|
|
|
|
|
|
|
|
stopwatch.Restart();
|
|
|
|
|
|
while (isAwaitingResponse)
|
2025-01-21 14:38:59 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
if (stopwatch.ElapsedMilliseconds > 10000)
|
2025-01-21 14:38:59 +03:00
|
|
|
|
{
|
2025-03-06 10:16:30 +03:00
|
|
|
|
Console.WriteLine("Response timed out.");
|
|
|
|
|
|
break;
|
2025-01-21 14:38:59 +03:00
|
|
|
|
}
|
2025-03-06 10:16:30 +03:00
|
|
|
|
}
|
2025-01-21 14:38:59 +03:00
|
|
|
|
|
2025-01-24 11:46:36 +03:00
|
|
|
|
if (latestMessage != null && latestMessage.Status != ModbusStatus.Error)
|
|
|
|
|
|
modbusID = newID;
|
2025-01-21 14:38:59 +03:00
|
|
|
|
}
|
2025-01-24 11:46:36 +03:00
|
|
|
|
|
2025-03-19 15:27:37 +03:00
|
|
|
|
// Кран
|
2025-01-24 11:46:36 +03:00
|
|
|
|
private async void buttonValve_Click(object sender, EventArgs e)
|
2024-12-06 16:32:10 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
try
|
2024-12-09 16:24:02 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
await Task.Run(() =>
|
2025-01-24 11:46:36 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
ushort value = isValveClosed ? (ushort)0 : (ushort)0xFF00;
|
|
|
|
|
|
if (SetEntry(device.valveStatus, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
isValveClosed = !isValveClosed;
|
|
|
|
|
|
labelValve.Invoke(new MethodInvoker(delegate { labelValve.Text = isValveClosed ? "Закрыт" : "Открыт"; }));
|
|
|
|
|
|
buttonValve.Invoke(new MethodInvoker(delegate { buttonValve.Text = isValveClosed ? "Открыть" : "Закрыть"; }));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-03-06 10:16:30 +03:00
|
|
|
|
}
|
2025-04-09 15:26:50 +03:00
|
|
|
|
catch (Exception err)
|
2025-01-24 11:46:36 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
MessageBox.Show(err.Message, "Valve Set Error");
|
2025-01-24 11:46:36 +03:00
|
|
|
|
}
|
2024-12-26 15:59:39 +03:00
|
|
|
|
}
|
2025-01-17 10:40:18 +03:00
|
|
|
|
|
2025-03-19 15:27:37 +03:00
|
|
|
|
// Авария
|
2025-04-09 15:26:50 +03:00
|
|
|
|
private void buttonAlarm_Click(object sender, EventArgs e)
|
2025-01-17 10:40:18 +03:00
|
|
|
|
{
|
2025-01-24 11:46:36 +03:00
|
|
|
|
ushort value = alarmStatus ? (ushort)0 : (ushort)0xFF00;
|
2025-04-09 15:26:50 +03:00
|
|
|
|
if (SetEntry(device.alarmStatus, value))
|
2025-01-24 11:46:36 +03:00
|
|
|
|
{
|
|
|
|
|
|
alarmStatus = !alarmStatus;
|
|
|
|
|
|
labelAlarm.Text = alarmStatus ? "Протечка!" : "Нет";
|
|
|
|
|
|
buttonAlarm.Text = alarmStatus ? "Выключить" : "Авария";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-19 15:27:37 +03:00
|
|
|
|
// Режим уборки
|
2025-04-09 15:26:50 +03:00
|
|
|
|
private void buttonCleaning_Click(object sender, EventArgs e)
|
2025-01-24 11:46:36 +03:00
|
|
|
|
{
|
|
|
|
|
|
ushort value = cleaningStatus ? (ushort)0 : (ushort)0xFF00;
|
2025-04-09 15:26:50 +03:00
|
|
|
|
if (SetEntry(device.cleaningMode, value))
|
2025-01-24 11:46:36 +03:00
|
|
|
|
{
|
|
|
|
|
|
cleaningStatus = !cleaningStatus;
|
|
|
|
|
|
labelCleaning.Text = cleaningStatus ? "вкл" : "выкл";
|
|
|
|
|
|
buttonCleaning.Text = cleaningStatus ? "Выключить" : "Включить";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-01-27 11:23:57 +03:00
|
|
|
|
|
2025-03-19 15:27:37 +03:00
|
|
|
|
// Задать скорость передачи данных для устройства
|
2025-04-09 15:26:50 +03:00
|
|
|
|
private void buttonSetSpeed_Click(object sender, EventArgs e)
|
2025-01-27 11:23:57 +03:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string str = cBoxSpeed.Items[cBoxSpeed.SelectedIndex].ToString();
|
|
|
|
|
|
str = str.Substring(0, str.Length - 2); //clip off two zeroes at the end
|
|
|
|
|
|
ushort newSpeed = (ushort)Int16.Parse(str);
|
2025-04-09 15:26:50 +03:00
|
|
|
|
Console.WriteLine("new speed: " + newSpeed);
|
|
|
|
|
|
if (SetEntry(device.baudRate, newSpeed))
|
2025-01-27 11:23:57 +03:00
|
|
|
|
{
|
2025-04-09 15:26:50 +03:00
|
|
|
|
//port.Close();
|
|
|
|
|
|
port.BaudRate = newSpeed * 100;
|
|
|
|
|
|
//port.Open();
|
2025-01-27 11:23:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex) { MessageBox.Show(ex.Message); }
|
|
|
|
|
|
}
|
2025-02-28 18:00:17 +03:00
|
|
|
|
|
2025-03-19 15:27:37 +03:00
|
|
|
|
// Выбор файла прошивки
|
2025-02-28 18:00:17 +03:00
|
|
|
|
private void BrowseFirmware_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-03-07 16:49:07 +03:00
|
|
|
|
fileThread.SetApartmentState(ApartmentState.STA);
|
2025-02-28 18:00:17 +03:00
|
|
|
|
fileThread.Start();
|
|
|
|
|
|
while (!fileThread.IsAlive) { Thread.Sleep(1); }
|
|
|
|
|
|
Thread.Sleep(1);
|
|
|
|
|
|
fileThread.Join();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception err) { MessageBox.Show(err.Message); }
|
2025-03-06 10:16:30 +03:00
|
|
|
|
|
|
|
|
|
|
firmwarePathLabel.Invoke(new MethodInvoker(delegate { firmwarePathLabel.Text = firmwarePath; }));
|
2025-02-28 18:00:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-19 15:27:37 +03:00
|
|
|
|
// Запись прошивки
|
2025-03-06 10:16:30 +03:00
|
|
|
|
private async void WriteFirmware_Click(object sender, EventArgs e)
|
2025-02-28 18:00:17 +03:00
|
|
|
|
{
|
2025-03-06 10:16:30 +03:00
|
|
|
|
if (firmwarePath is null || firmwarePath.Length == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("Выберите файл прошивки.");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-03-07 16:49:07 +03:00
|
|
|
|
int cntr = 0;
|
|
|
|
|
|
|
2025-02-28 18:00:17 +03:00
|
|
|
|
FileStream fileStream = File.OpenRead(firmwarePath);
|
|
|
|
|
|
long bytesLeft = fileStream.Length;
|
2025-03-06 10:16:30 +03:00
|
|
|
|
long bytesTotal = fileStream.Length;
|
|
|
|
|
|
int count = 64;
|
|
|
|
|
|
byte[] buffer = new byte[count];
|
2025-02-28 18:00:17 +03:00
|
|
|
|
byte[] bdma;
|
2025-03-06 10:16:30 +03:00
|
|
|
|
short _flashAddr = 0;
|
|
|
|
|
|
byte[] flashAddr = new byte[2];
|
|
|
|
|
|
byte[] CRC;
|
2025-02-28 18:00:17 +03:00
|
|
|
|
List<byte> message;
|
2025-03-06 10:16:30 +03:00
|
|
|
|
bool firstMessageSent = false;
|
|
|
|
|
|
long bytesWritten = 0;
|
|
|
|
|
|
await Task.Run(() =>
|
2025-02-28 18:00:17 +03:00
|
|
|
|
{
|
|
|
|
|
|
while (bytesLeft > 0)
|
|
|
|
|
|
{
|
2025-03-07 16:49:07 +03:00
|
|
|
|
if (firstMessageSent && port.BaudRate != 9600) // after first message the device is sent into recovery mode which only supports 9600 bps
|
2025-03-06 10:16:30 +03:00
|
|
|
|
{
|
|
|
|
|
|
port.Close();
|
|
|
|
|
|
port.BaudRate = 9600;
|
|
|
|
|
|
port.Open();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-28 18:00:17 +03:00
|
|
|
|
count = bytesLeft > 64 ? 64 : (int)bytesLeft;
|
|
|
|
|
|
buffer = new byte[count];
|
2025-03-06 10:16:30 +03:00
|
|
|
|
fileStream.Read(buffer, 0, count);
|
2025-02-28 18:00:17 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bdma = new byte[2];
|
2025-03-06 10:16:30 +03:00
|
|
|
|
bdma[0] = (byte)((bytesLeft & 0xFF_00) >> 8);
|
|
|
|
|
|
bdma[1] = (byte)(bytesLeft & 0x00_FF);
|
|
|
|
|
|
|
|
|
|
|
|
flashAddr[0] = (byte)((_flashAddr & 0xFF_00) >> 8);
|
|
|
|
|
|
flashAddr[1] = (byte)(_flashAddr & 0x00_FF);
|
2025-02-28 18:00:17 +03:00
|
|
|
|
|
|
|
|
|
|
message = new List<byte>();
|
|
|
|
|
|
message.Add(modbusID); // device ID
|
|
|
|
|
|
message.Add(0x10); // function code
|
|
|
|
|
|
message.Add(0xFF); // register address
|
|
|
|
|
|
message.Add(0xFF); // register address
|
|
|
|
|
|
message.Add(0x00); // regCnt (?)
|
|
|
|
|
|
message.Add(0x21); // regCnt (?)
|
|
|
|
|
|
message.Add(0x42); // data bytecount
|
|
|
|
|
|
|
2025-03-06 10:16:30 +03:00
|
|
|
|
message.Add(flashAddr[0]);
|
|
|
|
|
|
message.Add(flashAddr[1]);
|
2025-02-28 18:00:17 +03:00
|
|
|
|
|
2025-03-06 10:16:30 +03:00
|
|
|
|
try
|
2025-02-28 18:00:17 +03:00
|
|
|
|
{
|
2025-03-06 10:16:30 +03:00
|
|
|
|
for (int i = 0; i < buffer.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
message.Add(buffer[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
message.Add(0x00);
|
|
|
|
|
|
message.Add(0x00);
|
|
|
|
|
|
CRC = new byte[2];
|
|
|
|
|
|
Modbus.GetCRC(message.ToArray(), ref CRC);
|
|
|
|
|
|
message[message.Count - 2] = CRC[0];
|
|
|
|
|
|
message[message.Count - 1] = CRC[1];
|
|
|
|
|
|
|
2025-03-07 16:49:07 +03:00
|
|
|
|
responseReceived = false;
|
2025-03-06 10:16:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
2025-03-07 16:49:07 +03:00
|
|
|
|
while (true)
|
2025-03-06 10:16:30 +03:00
|
|
|
|
{
|
2025-03-07 16:49:07 +03:00
|
|
|
|
if (cntr > 3)
|
2025-03-06 10:16:30 +03:00
|
|
|
|
{
|
2025-03-07 16:49:07 +03:00
|
|
|
|
Console.WriteLine("Response timed out 4 times in a row, aborting. Check connection.");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
isAwaitingResponse = true;
|
2025-04-08 17:11:57 +03:00
|
|
|
|
latestMessage = null;
|
2025-03-07 16:49:07 +03:00
|
|
|
|
Console.WriteLine("Outgoing firmware message: " + Modbus.ByteArrayToString(message.ToArray()));
|
|
|
|
|
|
port.Write(message.ToArray(), 0, message.Count);
|
|
|
|
|
|
stopwatch.Restart();
|
|
|
|
|
|
|
|
|
|
|
|
while (isAwaitingResponse)
|
|
|
|
|
|
{
|
2025-04-08 17:11:57 +03:00
|
|
|
|
if (stopwatch.ElapsedMilliseconds > port.ReadTimeout)
|
2025-03-07 16:49:07 +03:00
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("Response timed out.");
|
|
|
|
|
|
cntr++;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (responseReceived)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (latestMessage.Status == ModbusStatus.Error)
|
|
|
|
|
|
Console.WriteLine("Response received: Error!");
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("Response received: all good;");
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-03-06 10:16:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-07 16:49:07 +03:00
|
|
|
|
cntr = 0;
|
|
|
|
|
|
bytesLeft -= count;
|
|
|
|
|
|
bytesWritten += count;
|
|
|
|
|
|
firmwareProgressBar.Invoke((MethodInvoker)delegate { firmwareProgressBar.Increment((int)(bytesWritten / bytesTotal) * 100); });
|
|
|
|
|
|
|
|
|
|
|
|
_flashAddr += (short)count;
|
|
|
|
|
|
if (port.BaudRate != 9600)
|
|
|
|
|
|
firstMessageSent = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (bytesLeft <= 0)
|
|
|
|
|
|
Console.WriteLine("Reached the end of firmware file.");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show(ex.Message, "Firmware writing error");
|
|
|
|
|
|
return;
|
2025-03-06 10:16:30 +03:00
|
|
|
|
}
|
2025-03-07 16:49:07 +03:00
|
|
|
|
|
2025-03-06 10:16:30 +03:00
|
|
|
|
}
|
2025-02-28 18:00:17 +03:00
|
|
|
|
|
2025-03-06 10:16:30 +03:00
|
|
|
|
/* Final Message */
|
2025-03-07 16:49:07 +03:00
|
|
|
|
message = new List<byte>();
|
2025-03-06 10:16:30 +03:00
|
|
|
|
message.Add(modbusID); // device ID
|
|
|
|
|
|
message.Add(0x10); // function code
|
|
|
|
|
|
message.Add(0xFF); // register address
|
|
|
|
|
|
message.Add(0xFF); // register address
|
|
|
|
|
|
message.Add(0x00); // regCnt (?)
|
|
|
|
|
|
message.Add(0x21); // regCnt (?)
|
|
|
|
|
|
message.Add(0x00); // data bytecount
|
|
|
|
|
|
message.Add(0x00); // CRC
|
|
|
|
|
|
message.Add(0x00); // CRC
|
|
|
|
|
|
CRC = new byte[2];
|
|
|
|
|
|
Modbus.GetCRC(message.ToArray(), ref CRC);
|
|
|
|
|
|
message[message.Count - 2] = CRC[0];
|
|
|
|
|
|
message[message.Count - 1] = CRC[1];
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
2025-02-28 18:00:17 +03:00
|
|
|
|
isAwaitingResponse = true;
|
2025-03-07 16:49:07 +03:00
|
|
|
|
Console.WriteLine("Outgoing firmware message: " + Modbus.ByteArrayToString(message.ToArray()));
|
2025-02-28 18:00:17 +03:00
|
|
|
|
port.Write(message.ToArray(), 0, message.Count);
|
2025-03-06 10:16:30 +03:00
|
|
|
|
stopwatch.Restart();
|
2025-02-28 18:00:17 +03:00
|
|
|
|
|
2025-03-06 10:16:30 +03:00
|
|
|
|
while (isAwaitingResponse)
|
2025-02-28 18:00:17 +03:00
|
|
|
|
{
|
2025-03-07 16:49:07 +03:00
|
|
|
|
if (stopwatch.ElapsedMilliseconds > 1000)
|
2025-02-28 18:00:17 +03:00
|
|
|
|
{
|
2025-03-06 10:16:30 +03:00
|
|
|
|
Console.WriteLine("Response timed out.");
|
|
|
|
|
|
break;
|
2025-02-28 18:00:17 +03:00
|
|
|
|
}
|
2025-03-06 10:16:30 +03:00
|
|
|
|
}
|
2025-03-07 16:49:07 +03:00
|
|
|
|
|
2025-03-06 10:16:30 +03:00
|
|
|
|
if (responseReceived)
|
2025-03-07 16:49:07 +03:00
|
|
|
|
{
|
|
|
|
|
|
if (latestMessage.Status == ModbusStatus.Error)
|
|
|
|
|
|
Console.WriteLine("Response received: Error!");
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("Response received: all good;");
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-28 18:00:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-03-06 10:16:30 +03:00
|
|
|
|
|
2025-02-28 18:00:17 +03:00
|
|
|
|
}
|
2025-01-24 11:46:36 +03:00
|
|
|
|
}
|
2025-06-24 10:09:11 +03:00
|
|
|
|
|
|
|
|
|
|
#region Sensor Classes
|
2025-01-24 11:46:36 +03:00
|
|
|
|
public class Sensor : FlowLayoutPanel
|
|
|
|
|
|
{
|
|
|
|
|
|
public Label labelName = new Label() { Width = 60, Height = 24 };
|
|
|
|
|
|
public Label labelLeakFluff = new Label() { Width = 60, Height = 24 };
|
|
|
|
|
|
public Label labelLeak = new Label() { Width = 50, Height = 24 };
|
|
|
|
|
|
}
|
|
|
|
|
|
public class WiredSensor : Sensor
|
|
|
|
|
|
{
|
|
|
|
|
|
public Label labelBreakFluff = new Label() { Width = 45, Height = 24 };
|
|
|
|
|
|
public Label labelBreak = new Label() { Width = 55, Height = 24 }; // обрыв линии для WSP+
|
|
|
|
|
|
|
2025-06-24 10:09:11 +03:00
|
|
|
|
public Label labelWSPPlusFluff;
|
|
|
|
|
|
public CheckBox wspPlusCheckbox;
|
|
|
|
|
|
public Entry wspPlusEntry; // for WSP+ control
|
|
|
|
|
|
public WiredSensor(int count, Device device)
|
2025-01-24 11:46:36 +03:00
|
|
|
|
{
|
|
|
|
|
|
this.Margin = Padding.Empty;
|
|
|
|
|
|
this.Padding = new Padding(0, 5, 0, 0);
|
|
|
|
|
|
this.WrapContents = false;
|
|
|
|
|
|
this.BackColor = Color.White;
|
|
|
|
|
|
this.Height = 15;
|
|
|
|
|
|
this.FlowDirection = FlowDirection.LeftToRight;
|
|
|
|
|
|
this.Controls.Add(labelName);
|
|
|
|
|
|
|
|
|
|
|
|
this.Controls.Add(labelBreakFluff);
|
|
|
|
|
|
this.Controls.Add(labelBreak);
|
|
|
|
|
|
|
|
|
|
|
|
this.Controls.Add(labelLeakFluff);
|
|
|
|
|
|
this.Controls.Add(labelLeak);
|
|
|
|
|
|
|
|
|
|
|
|
labelName.Text = "WSP " + (count + 1);
|
|
|
|
|
|
|
|
|
|
|
|
labelLeakFluff.Text = "Протечка:";
|
|
|
|
|
|
labelLeak.Text = "неизвестно";
|
|
|
|
|
|
|
|
|
|
|
|
labelBreakFluff.Text = "Обрыв:";
|
|
|
|
|
|
labelBreak.Text = "неизвестно";
|
2025-06-24 10:09:11 +03:00
|
|
|
|
if (device.wspPlusMode != null || device.wspPlusMode.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
labelWSPPlusFluff = new Label() { Width = 45, Height = 24, Text = "WSP+:" };
|
|
|
|
|
|
wspPlusCheckbox = new CheckBox() { Width = 20, Height = 14, Margin = Padding.Empty };
|
|
|
|
|
|
|
|
|
|
|
|
this.Controls.Add(labelWSPPlusFluff);
|
|
|
|
|
|
this.Controls.Add(wspPlusCheckbox);
|
|
|
|
|
|
}
|
2025-01-24 11:46:36 +03:00
|
|
|
|
|
2025-01-17 10:40:18 +03:00
|
|
|
|
}
|
2025-01-24 11:46:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class WirelessSensor : Sensor
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2025-01-24 17:54:04 +03:00
|
|
|
|
public Label labelStatusFluff = new Label() { Width = 45, Height = 24 };
|
|
|
|
|
|
public Label labelStatus = new Label() { Width = 55, Height = 24 };
|
2025-01-17 10:40:18 +03:00
|
|
|
|
|
2025-01-24 11:46:36 +03:00
|
|
|
|
public WirelessSensor(int count)
|
2025-01-17 10:40:18 +03:00
|
|
|
|
{
|
2025-01-24 11:46:36 +03:00
|
|
|
|
this.Margin = Padding.Empty;
|
|
|
|
|
|
this.Padding = new Padding(0, 5, 0, 0);
|
|
|
|
|
|
this.BackColor = Color.White;
|
|
|
|
|
|
this.FlowDirection = FlowDirection.LeftToRight;
|
|
|
|
|
|
this.WrapContents = false;
|
|
|
|
|
|
|
|
|
|
|
|
this.Controls.Add(labelName);
|
2025-01-24 17:54:04 +03:00
|
|
|
|
this.Controls.Add(labelStatusFluff);
|
|
|
|
|
|
this.Controls.Add(labelStatus);
|
2025-01-24 11:46:36 +03:00
|
|
|
|
this.Controls.Add(labelLeakFluff);
|
|
|
|
|
|
this.Controls.Add(labelLeak);
|
|
|
|
|
|
|
|
|
|
|
|
labelName.Text = "WSR " + (count + 1);
|
|
|
|
|
|
|
|
|
|
|
|
labelLeakFluff.Text = "Протечка:";
|
|
|
|
|
|
labelLeak.Text = "неизвестно";
|
|
|
|
|
|
|
2025-01-24 17:54:04 +03:00
|
|
|
|
labelStatusFluff.Text = "Статус:";
|
|
|
|
|
|
labelStatus.Text = "неизвестно";
|
2025-01-17 10:40:18 +03:00
|
|
|
|
}
|
2025-01-24 11:46:36 +03:00
|
|
|
|
}
|
2025-01-21 14:38:59 +03:00
|
|
|
|
|
2025-01-24 11:46:36 +03:00
|
|
|
|
public class ScenarioSensor : Sensor
|
|
|
|
|
|
{
|
|
|
|
|
|
public ScenarioSensor()
|
2025-01-21 14:38:59 +03:00
|
|
|
|
{
|
2025-01-24 11:46:36 +03:00
|
|
|
|
labelName.Width = 172;
|
|
|
|
|
|
this.Margin = Padding.Empty;
|
|
|
|
|
|
this.Padding = new Padding(0, 5, 0, 0);
|
|
|
|
|
|
this.FlowDirection = FlowDirection.LeftToRight;
|
|
|
|
|
|
this.WrapContents = false;
|
2025-01-21 14:38:59 +03:00
|
|
|
|
|
2025-01-24 11:46:36 +03:00
|
|
|
|
this.Controls.Add(labelName);
|
|
|
|
|
|
this.Controls.Add(labelLeakFluff);
|
|
|
|
|
|
this.Controls.Add(labelLeak);
|
|
|
|
|
|
|
|
|
|
|
|
labelName.Text = "Сценарный датчик";
|
|
|
|
|
|
|
|
|
|
|
|
labelLeakFluff.Text = "Протечка:";
|
|
|
|
|
|
labelLeak.Text = "неизвестно";
|
|
|
|
|
|
}
|
2024-12-26 15:59:39 +03:00
|
|
|
|
}
|
2025-06-24 10:09:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|