added baudrate configuration

This commit is contained in:
nikzori
2025-01-24 17:54:04 +03:00
parent 48bc4b94ff
commit 0012d3e8a1
6 changed files with 168 additions and 65 deletions

76
Datasheet.Designer.cs generated
View File

@@ -46,13 +46,15 @@
this.label7 = new System.Windows.Forms.Label();
this.labelAlarm = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.buttonAlarm = new System.Windows.Forms.Button();
this.buttonValve = new System.Windows.Forms.Button();
this.labelValve = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.sensorPanel = new System.Windows.Forms.FlowLayoutPanel();
this.label9 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.label8 = new System.Windows.Forms.Label();
this.cBoxSpeed = new System.Windows.Forms.ComboBox();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudModbusID)).BeginInit();
this.groupBox2.SuspendLayout();
@@ -60,6 +62,9 @@
//
// groupBox1
//
this.groupBox1.Controls.Add(this.cBoxSpeed);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.label8);
this.groupBox1.Controls.Add(this.labelBattery);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.buttonPoll);
@@ -70,9 +75,9 @@
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(304, 12);
this.groupBox1.Location = new System.Drawing.Point(291, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(221, 101);
this.groupBox1.Size = new System.Drawing.Size(234, 126);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инфо";
@@ -98,7 +103,7 @@
// buttonPoll
//
this.buttonPoll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonPoll.Location = new System.Drawing.Point(140, 43);
this.buttonPoll.Location = new System.Drawing.Point(153, 43);
this.buttonPoll.Name = "buttonPoll";
this.buttonPoll.Size = new System.Drawing.Size(75, 23);
this.buttonPoll.TabIndex = 7;
@@ -108,7 +113,7 @@
//
// buttonSetID
//
this.buttonSetID.Location = new System.Drawing.Point(140, 68);
this.buttonSetID.Location = new System.Drawing.Point(153, 68);
this.buttonSetID.Name = "buttonSetID";
this.buttonSetID.Size = new System.Drawing.Size(75, 23);
this.buttonSetID.TabIndex = 6;
@@ -138,7 +143,7 @@
//
this.nudModbusID.Location = new System.Drawing.Point(74, 71);
this.nudModbusID.Name = "nudModbusID";
this.nudModbusID.Size = new System.Drawing.Size(50, 20);
this.nudModbusID.Size = new System.Drawing.Size(49, 20);
this.nudModbusID.TabIndex = 3;
//
// label3
@@ -175,14 +180,13 @@
this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.labelAlarm);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.button2);
this.groupBox2.Controls.Add(this.buttonAlarm);
this.groupBox2.Controls.Add(this.buttonValve);
this.groupBox2.Controls.Add(this.labelValve);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Location = new System.Drawing.Point(13, 12);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(285, 100);
this.groupBox2.Size = new System.Drawing.Size(272, 126);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Общее";
@@ -200,7 +204,7 @@
//
this.buttonCleaning.Location = new System.Drawing.Point(125, 72);
this.buttonCleaning.Name = "buttonCleaning";
this.buttonCleaning.Size = new System.Drawing.Size(73, 23);
this.buttonCleaning.Size = new System.Drawing.Size(140, 23);
this.buttonCleaning.TabIndex = 8;
this.buttonCleaning.Text = "Включить";
this.buttonCleaning.UseVisualStyleBackColor = true;
@@ -233,20 +237,11 @@
this.label5.TabIndex = 5;
this.label5.Text = "Протечка:";
//
// button2
//
this.button2.Location = new System.Drawing.Point(204, 14);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(73, 52);
this.button2.TabIndex = 4;
this.button2.Text = "Аварийное открытие";
this.button2.UseVisualStyleBackColor = true;
//
// buttonAlarm
//
this.buttonAlarm.Location = new System.Drawing.Point(125, 43);
this.buttonAlarm.Name = "buttonAlarm";
this.buttonAlarm.Size = new System.Drawing.Size(73, 23);
this.buttonAlarm.Size = new System.Drawing.Size(140, 23);
this.buttonAlarm.TabIndex = 3;
this.buttonAlarm.Text = "Авария";
this.buttonAlarm.UseVisualStyleBackColor = true;
@@ -256,7 +251,7 @@
//
this.buttonValve.Location = new System.Drawing.Point(125, 14);
this.buttonValve.Name = "buttonValve";
this.buttonValve.Size = new System.Drawing.Size(73, 23);
this.buttonValve.Size = new System.Drawing.Size(140, 23);
this.buttonValve.TabIndex = 2;
this.buttonValve.Text = "Закрыть";
this.buttonValve.UseVisualStyleBackColor = true;
@@ -287,26 +282,53 @@
this.sensorPanel.AutoScroll = true;
this.sensorPanel.BackColor = System.Drawing.Color.Gainsboro;
this.sensorPanel.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.sensorPanel.Location = new System.Drawing.Point(13, 135);
this.sensorPanel.Location = new System.Drawing.Point(13, 168);
this.sensorPanel.Name = "sensorPanel";
this.sensorPanel.Size = new System.Drawing.Size(512, 175);
this.sensorPanel.Size = new System.Drawing.Size(512, 248);
this.sensorPanel.TabIndex = 4;
this.sensorPanel.WrapContents = false;
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(10, 119);
this.label9.Location = new System.Drawing.Point(10, 152);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(50, 13);
this.label9.TabIndex = 5;
this.label9.Text = "Датчики";
//
// button1
//
this.button1.Location = new System.Drawing.Point(153, 94);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 12;
this.button1.Text = "Изменить";
this.button1.UseVisualStyleBackColor = true;
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(6, 99);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(58, 13);
this.label8.TabIndex = 10;
this.label8.Text = "Скорость:";
//
// cBoxSpeed
//
this.cBoxSpeed.FormattingEnabled = true;
this.cBoxSpeed.Location = new System.Drawing.Point(74, 97);
this.cBoxSpeed.Name = "cBoxSpeed";
this.cBoxSpeed.Size = new System.Drawing.Size(73, 21);
this.cBoxSpeed.TabIndex = 13;
this.cBoxSpeed.Text = "9600";
//
// Datasheet
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(537, 322);
this.ClientSize = new System.Drawing.Size(537, 428);
this.Controls.Add(this.label9);
this.Controls.Add(this.sensorPanel);
this.Controls.Add(this.groupBox2);
@@ -315,7 +337,7 @@
this.MaximizeBox = false;
this.Name = "Datasheet";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Text = "Datasheet";
this.Text = "Config";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudModbusID)).EndInit();
@@ -342,7 +364,6 @@
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button buttonValve;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button buttonAlarm;
private System.Windows.Forms.Label labelCleaning;
private System.Windows.Forms.Button buttonCleaning;
@@ -352,5 +373,8 @@
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label labelBattery;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.ComboBox cBoxSpeed;
}
}

View File

@@ -40,6 +40,17 @@ namespace Gidrolock_Modbus_Scanner
this.modbusID = modbusID;
this.device = device;
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();
labelModel.Text = device.name;
labelFirmware.Text = "v???";
@@ -67,10 +78,10 @@ namespace Gidrolock_Modbus_Scanner
sensorPanel.Controls.Add(scenSen);
scenSen.Visible = true;
}
if (device.wiredSensors < device.sensorsAlarm.length)
if (device.wiredSensors < device.sensorAlarm.length)
{
wirelessSensors = new List<WirelessSensor>();
int wsrIndex = device.sensorsAlarm.length - device.wiredSensors - (device.hasScenarioSensor ? 1 : 0);
int wsrIndex = device.sensorAlarm.length - device.wiredSensors - (device.hasScenarioSensor ? 1 : 0);
for (int i = 0; i < wsrIndex; i++)
{
WirelessSensor wsr = new WirelessSensor(i) { Width = 495, Height = 24 };
@@ -175,18 +186,50 @@ namespace Gidrolock_Modbus_Scanner
}
}
res = await PollEntry(device.sensorsAlarm);
res = await PollEntry(device.sensorAlarm);
if (res)
{
BitArray bArray = new BitArray(latestMessage.Data);
bool[] bools = new bool[bArray.Length];
bArray.CopyTo(bools, 0);
for (int i = 0; i < device.sensorsAlarm.length; i++)
for (int i = 0; i < sensorPanel.Controls.Count; i++)
{
Sensor snsr = sensorPanel.Controls[i] as Sensor;
snsr.labelLeak.Text = bools[i] ? "Протечка!" : "нет";
}
}
res = await 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; 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.labelStatus.Text = txt;
}
}
}
catch (Exception err) { MessageBox.Show(err.Message); }
}
@@ -316,8 +359,8 @@ namespace Gidrolock_Modbus_Scanner
public Label labelBreakFluff = new Label() { Width = 45, Height = 24 };
public Label labelBreak = new Label() { Width = 55, Height = 24 }; // обрыв линии для WSP+
public Label labelWSPPlusFluff = new Label() { Width = 45, Height = 24 };
public CheckBox wspPlusCheckbox = new CheckBox() { Width = 20, Height = 20 };
//public Label labelWSPPlusFluff = new Label() { Width = 45, Height = 24 };
//public CheckBox wspPlusCheckbox = new CheckBox() { Width = 20, Height = 14 };
public WiredSensor(int count)
{
this.Margin = Padding.Empty;
@@ -334,8 +377,8 @@ namespace Gidrolock_Modbus_Scanner
this.Controls.Add(labelLeakFluff);
this.Controls.Add(labelLeak);
this.Controls.Add(labelWSPPlusFluff);
this.Controls.Add(wspPlusCheckbox);
//this.Controls.Add(labelWSPPlusFluff);
//this.Controls.Add(wspPlusCheckbox);
labelName.Text = "WSP " + (count + 1);
@@ -345,15 +388,16 @@ namespace Gidrolock_Modbus_Scanner
labelBreakFluff.Text = "Обрыв:";
labelBreak.Text = "неизвестно";
labelWSPPlusFluff.Text = "WSP+:";
//labelWSPPlusFluff.Text = "WSP+:";
//wspPlusCheckbox.Margin = Padding.Empty;
}
}
public class WirelessSensor : Sensor
{
public Label labelBatteryFluff = new Label() { Width = 55, Height = 24 };
public Label labelBattery = new Label() { Width = 45, Height = 24 };
public Label labelStatusFluff = new Label() { Width = 45, Height = 24 };
public Label labelStatus = new Label() { Width = 55, Height = 24 };
public WirelessSensor(int count)
{
@@ -364,8 +408,8 @@ namespace Gidrolock_Modbus_Scanner
this.WrapContents = false;
this.Controls.Add(labelName);
this.Controls.Add(labelBatteryFluff);
this.Controls.Add(labelBattery);
this.Controls.Add(labelStatusFluff);
this.Controls.Add(labelStatus);
this.Controls.Add(labelLeakFluff);
this.Controls.Add(labelLeak);
@@ -374,8 +418,8 @@ namespace Gidrolock_Modbus_Scanner
labelLeakFluff.Text = "Протечка:";
labelLeak.Text = "неизвестно";
labelBatteryFluff.Text = "Батарея:";
labelBattery.Text = "???%";
labelStatusFluff.Text = "Статус:";
labelStatus.Text = "неизвестно";
}
}

44
Main.Designer.cs generated
View File

@@ -32,12 +32,14 @@
this.TextBox_Log = new System.Windows.Forms.TextBox();
this.UpDown_ModbusID = new System.Windows.Forms.NumericUpDown();
this.label2 = new System.Windows.Forms.Label();
this.CBox_Ports = new System.Windows.Forms.ComboBox();
this.cBoxPorts = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.cBoxDevice = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.checkboxID = new System.Windows.Forms.CheckBox();
this.cBoxSpeed = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.UpDown_ModbusID)).BeginInit();
this.SuspendLayout();
//
@@ -67,14 +69,14 @@
this.label2.TabIndex = 0;
this.label2.Text = "Modbus ID";
//
// CBox_Ports
// cBoxPorts
//
this.CBox_Ports.FormattingEnabled = true;
this.CBox_Ports.Location = new System.Drawing.Point(139, 24);
this.CBox_Ports.Name = "CBox_Ports";
this.CBox_Ports.Size = new System.Drawing.Size(65, 21);
this.CBox_Ports.TabIndex = 1;
this.CBox_Ports.Text = "COM1";
this.cBoxPorts.FormattingEnabled = true;
this.cBoxPorts.Location = new System.Drawing.Point(139, 24);
this.cBoxPorts.Name = "cBoxPorts";
this.cBoxPorts.Size = new System.Drawing.Size(65, 21);
this.cBoxPorts.TabIndex = 1;
this.cBoxPorts.Text = "COM1";
//
// label1
//
@@ -123,16 +125,36 @@
this.checkboxID.UseVisualStyleBackColor = true;
this.checkboxID.CheckedChanged += new System.EventHandler(this.checkboxID_CheckedChanged);
//
// cBoxSpeed
//
this.cBoxSpeed.FormattingEnabled = true;
this.cBoxSpeed.Location = new System.Drawing.Point(210, 24);
this.cBoxSpeed.Name = "cBoxSpeed";
this.cBoxSpeed.Size = new System.Drawing.Size(78, 21);
this.cBoxSpeed.TabIndex = 7;
this.cBoxSpeed.Text = "9600";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(207, 7);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(55, 13);
this.label4.TabIndex = 6;
this.label4.Text = "Скорость";
//
// App
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(518, 226);
this.Controls.Add(this.cBoxSpeed);
this.Controls.Add(this.label4);
this.Controls.Add(this.checkboxID);
this.Controls.Add(this.label3);
this.Controls.Add(this.cBoxDevice);
this.Controls.Add(this.button1);
this.Controls.Add(this.CBox_Ports);
this.Controls.Add(this.cBoxPorts);
this.Controls.Add(this.label1);
this.Controls.Add(this.UpDown_ModbusID);
this.Controls.Add(this.TextBox_Log);
@@ -155,12 +177,14 @@
private System.Windows.Forms.TextBox TextBox_Log;
private System.Windows.Forms.NumericUpDown UpDown_ModbusID;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox CBox_Ports;
private System.Windows.Forms.ComboBox cBoxPorts;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.CheckBox checkboxID;
private System.Windows.Forms.ComboBox cBoxDevice;
private System.Windows.Forms.ComboBox cBoxSpeed;
private System.Windows.Forms.Label label4;
}
}

37
Main.cs
View File

@@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using Newtonsoft.Json;
namespace Gidrolock_Modbus_Scanner
{
@@ -33,6 +30,17 @@ namespace Gidrolock_Modbus_Scanner
this.UpDown_ModbusID.Value = 0;
TextBox_Log.Text = "Приложение готово к работе.";
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.SelectedIndex = 3;
cBoxDevice.Items.Add("Standard");
cBoxDevice.Items.Add("Premium Plus");
//cBoxDevice.Items.Add("Inteli");
@@ -70,15 +78,15 @@ namespace Gidrolock_Modbus_Scanner
void Form1_Load(object sender, EventArgs e)
{
CBox_Ports.Items.AddRange(SerialPort.GetPortNames());
if (CBox_Ports.Items.Count > 0)
CBox_Ports.SelectedIndex = 0;
cBoxPorts.Items.AddRange(SerialPort.GetPortNames());
if (cBoxPorts.Items.Count > 0)
cBoxPorts.SelectedIndex = 0;
}
#endregion
private async void ButtonConnect_Click(object sender, EventArgs e)
{
if (CBox_Ports.SelectedItem.ToString() == "COM1")
if (cBoxPorts.SelectedItem.ToString() == "COM1")
{
DialogResult res = MessageBox.Show("Выбран серийный порт COM1, который обычно является портом PS/2 или RS-232, не подключенным к Modbus устройству. Продолжить?", "Внимание", MessageBoxButtons.OKCancel);
if (res == DialogResult.Cancel)
@@ -98,8 +106,8 @@ namespace Gidrolock_Modbus_Scanner
port.Close();
port.Handshake = Handshake.None;
port.PortName = CBox_Ports.Text;
port.BaudRate = 9600;
port.PortName = cBoxPorts.Text;
port.BaudRate = Int32.Parse(cBoxSpeed.Items[cBoxSpeed.SelectedIndex].ToString());
port.Parity = Parity.None;
port.DataBits = 8;
port.StopBits = StopBits.One;
@@ -211,8 +219,8 @@ namespace Gidrolock_Modbus_Scanner
void CBox_Ports_Click(object sender, EventArgs e)
{
CBox_Ports.Items.Clear();
CBox_Ports.Items.AddRange(SerialPort.GetPortNames());
cBoxPorts.Items.Clear();
cBoxPorts.Items.AddRange(SerialPort.GetPortNames());
}
void OnResponseReceived(object sender, ModbusResponseEventArgs e)
@@ -358,7 +366,7 @@ namespace Gidrolock_Modbus_Scanner
d.wiredSensors = 2;
d.hasScenarioSensor = true;
d.sensorsAlarm = new Entry(RegisterType.Discrete, 1343, 24);
d.sensorAlarm = new Entry(RegisterType.Discrete, 1343, 24);
d.radioStatus = new Entry(RegisterType.Input, 1215, 21);
@@ -382,7 +390,8 @@ namespace Gidrolock_Modbus_Scanner
d.wiredSensors = 7;
d.hasScenarioSensor = true;
d.sensorsAlarm = new Entry(RegisterType.Discrete, 1343, 29);
d.sensorAlarm = new Entry(RegisterType.Discrete, 1343, 29);
d.radioStatus = new Entry(RegisterType.Input, 1215, 21);
break;
case DeviceType.Premium:
d.modelName = "Premium";
@@ -398,4 +407,6 @@ namespace Gidrolock_Modbus_Scanner
public enum FunctionCode { ReadCoil = 1, ReadDiscrete = 2, ReadHolding = 3, ReadInput = 4, WriteCoil = 5, WriteRegister = 6, WriteMultCoils = 15, WriteMultRegisters = 16 };
//public enum SelectedPath { File, Folder };
public enum DeviceType { Standard, PremiumPlus, Inteli, Premium };

View File

@@ -21,7 +21,7 @@ namespace Gidrolock_Modbus_Scanner
public int wiredSensors;
public bool hasScenarioSensor;
public Entry sensorsAlarm;
public Entry sensorAlarm;
public List<Entry> wiredLineBreak;

BIN
screenshot-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB