todo: organize entry rows Y positions; figure out how to update value label
This commit is contained in:
57
Datasheet.Designer.cs
generated
57
Datasheet.Designer.cs
generated
@@ -28,33 +28,18 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
|
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Datasheet));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Datasheet));
|
||||||
this.DGV_Device = new System.Windows.Forms.DataGridView();
|
|
||||||
this.Label_DeviceNameLabel = new System.Windows.Forms.Label();
|
this.Label_DeviceNameLabel = new System.Windows.Forms.Label();
|
||||||
this.Label_DescriptionLabel = new System.Windows.Forms.Label();
|
this.Label_DescriptionLabel = new System.Windows.Forms.Label();
|
||||||
this.Label_DeviceName = new System.Windows.Forms.Label();
|
this.Label_DeviceName = new System.Windows.Forms.Label();
|
||||||
this.Label_Description = new System.Windows.Forms.Label();
|
this.Label_Description = new System.Windows.Forms.Label();
|
||||||
this.Button_StartStop = new System.Windows.Forms.Button();
|
this.Button_StartStop = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.DGV_Device)).BeginInit();
|
this.Panel_Device = new System.Windows.Forms.Panel();
|
||||||
|
this.PD_Scrollbar = new System.Windows.Forms.VScrollBar();
|
||||||
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
|
this.Panel_Device.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// DGV_Device
|
|
||||||
//
|
|
||||||
this.DGV_Device.AllowUserToAddRows = false;
|
|
||||||
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
|
|
||||||
this.DGV_Device.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
|
|
||||||
this.DGV_Device.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
|
||||||
| System.Windows.Forms.AnchorStyles.Left)
|
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
|
||||||
this.DGV_Device.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
|
||||||
this.DGV_Device.Location = new System.Drawing.Point(13, 68);
|
|
||||||
this.DGV_Device.MultiSelect = false;
|
|
||||||
this.DGV_Device.Name = "DGV_Device";
|
|
||||||
this.DGV_Device.RowHeadersVisible = false;
|
|
||||||
this.DGV_Device.Size = new System.Drawing.Size(567, 420);
|
|
||||||
this.DGV_Device.TabIndex = 0;
|
|
||||||
//
|
|
||||||
// Label_DeviceNameLabel
|
// Label_DeviceNameLabel
|
||||||
//
|
//
|
||||||
this.Label_DeviceNameLabel.AutoSize = true;
|
this.Label_DeviceNameLabel.AutoSize = true;
|
||||||
@@ -102,33 +87,59 @@
|
|||||||
this.Button_StartStop.UseVisualStyleBackColor = true;
|
this.Button_StartStop.UseVisualStyleBackColor = true;
|
||||||
this.Button_StartStop.Click += new System.EventHandler(this.Button_StartStop_Click);
|
this.Button_StartStop.Click += new System.EventHandler(this.Button_StartStop_Click);
|
||||||
//
|
//
|
||||||
|
// Panel_Device
|
||||||
|
//
|
||||||
|
this.Panel_Device.Controls.Add(this.PD_Scrollbar);
|
||||||
|
this.Panel_Device.Location = new System.Drawing.Point(13, 77);
|
||||||
|
this.Panel_Device.Name = "Panel_Device";
|
||||||
|
this.Panel_Device.Size = new System.Drawing.Size(567, 411);
|
||||||
|
this.Panel_Device.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// PD_Scrollbar
|
||||||
|
//
|
||||||
|
this.PD_Scrollbar.Location = new System.Drawing.Point(549, 0);
|
||||||
|
this.PD_Scrollbar.Name = "PD_Scrollbar";
|
||||||
|
this.PD_Scrollbar.Size = new System.Drawing.Size(17, 440);
|
||||||
|
this.PD_Scrollbar.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
this.label1.AutoSize = true;
|
||||||
|
this.label1.Location = new System.Drawing.Point(13, 64);
|
||||||
|
this.label1.Name = "label1";
|
||||||
|
this.label1.Size = new System.Drawing.Size(14, 13);
|
||||||
|
this.label1.TabIndex = 7;
|
||||||
|
this.label1.Text = "#";
|
||||||
|
//
|
||||||
// Datasheet
|
// Datasheet
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(592, 500);
|
this.ClientSize = new System.Drawing.Size(592, 500);
|
||||||
|
this.Controls.Add(this.label1);
|
||||||
|
this.Controls.Add(this.Panel_Device);
|
||||||
this.Controls.Add(this.Button_StartStop);
|
this.Controls.Add(this.Button_StartStop);
|
||||||
this.Controls.Add(this.Label_Description);
|
this.Controls.Add(this.Label_Description);
|
||||||
this.Controls.Add(this.Label_DeviceName);
|
this.Controls.Add(this.Label_DeviceName);
|
||||||
this.Controls.Add(this.Label_DescriptionLabel);
|
this.Controls.Add(this.Label_DescriptionLabel);
|
||||||
this.Controls.Add(this.Label_DeviceNameLabel);
|
this.Controls.Add(this.Label_DeviceNameLabel);
|
||||||
this.Controls.Add(this.DGV_Device);
|
|
||||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||||
this.Name = "Datasheet";
|
this.Name = "Datasheet";
|
||||||
this.Text = "Datasheet";
|
this.Text = "Datasheet";
|
||||||
((System.ComponentModel.ISupportInitialize)(this.DGV_Device)).EndInit();
|
this.Panel_Device.ResumeLayout(false);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.DataGridView DGV_Device;
|
|
||||||
private System.Windows.Forms.Label Label_DeviceNameLabel;
|
private System.Windows.Forms.Label Label_DeviceNameLabel;
|
||||||
private System.Windows.Forms.Label Label_DescriptionLabel;
|
private System.Windows.Forms.Label Label_DescriptionLabel;
|
||||||
private System.Windows.Forms.Label Label_DeviceName;
|
private System.Windows.Forms.Label Label_DeviceName;
|
||||||
private System.Windows.Forms.Label Label_Description;
|
private System.Windows.Forms.Label Label_Description;
|
||||||
private System.Windows.Forms.Button Button_StartStop;
|
private System.Windows.Forms.Button Button_StartStop;
|
||||||
|
private System.Windows.Forms.Panel Panel_Device;
|
||||||
|
private System.Windows.Forms.VScrollBar PD_Scrollbar;
|
||||||
|
private System.Windows.Forms.Label label1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
212
Datasheet.cs
212
Datasheet.cs
@@ -1,16 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Runtime.Remoting.Messaging;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
|
||||||
namespace Gidrolock_Modbus_Scanner
|
namespace Gidrolock_Modbus_Scanner
|
||||||
{
|
{
|
||||||
@@ -25,6 +22,7 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
byte slaveID;
|
byte slaveID;
|
||||||
Device device = App.device;
|
Device device = App.device;
|
||||||
List<Entry> entries;
|
List<Entry> entries;
|
||||||
|
List<EntryRow> entryRows;
|
||||||
int activeEntryIndex; // entry index for modbus responses
|
int activeEntryIndex; // entry index for modbus responses
|
||||||
int activeDGVIndex; // index for DGV rows
|
int activeDGVIndex; // index for DGV rows
|
||||||
SerialPort port = Modbus.port;
|
SerialPort port = Modbus.port;
|
||||||
@@ -41,38 +39,11 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
Label_DeviceName.Text = device.name;
|
Label_DeviceName.Text = device.name;
|
||||||
Label_Description.Text = device.description;
|
Label_Description.Text = device.description;
|
||||||
|
|
||||||
DGV_Device.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
|
||||||
DGV_Device.MultiSelect = false;
|
|
||||||
DGV_Device.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
|
|
||||||
DGV_Device.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
|
||||||
|
|
||||||
DGV_Device.Columns.Add("#", "#");
|
|
||||||
DGV_Device.Columns[0].FillWeight = 20;
|
|
||||||
DGV_Device.Columns[0].ReadOnly = true;
|
|
||||||
DGV_Device.Columns.Add("Name", "Имя");
|
|
||||||
DGV_Device.Columns[1].FillWeight = 40;
|
|
||||||
DGV_Device.Columns[1].ReadOnly = true;
|
|
||||||
DGV_Device.Columns.Add("Value", "Значение");
|
|
||||||
DGV_Device.Columns[2].FillWeight = 60;
|
|
||||||
DGV_Device.Columns.Add("Address", "Адрес");
|
|
||||||
DGV_Device.Columns[3].FillWeight = 30;
|
|
||||||
DGV_Device.Columns[3].ReadOnly = true;
|
|
||||||
DGV_Device.Columns.Add(new DataGridViewCheckBoxColumn());
|
|
||||||
DGV_Device.Columns[4].Name = "Опрос";
|
|
||||||
DGV_Device.Columns[4].FillWeight = 20;
|
|
||||||
DGV_Device.Columns[4].ValueType = typeof(bool);
|
|
||||||
|
|
||||||
int rowCount = 0;
|
int rowCount = 0;
|
||||||
|
|
||||||
DGV_Device.CellEndEdit += (o, e) =>
|
entryRows = new List<EntryRow>();
|
||||||
{
|
|
||||||
if (e.ColumnIndex == 2)
|
|
||||||
{
|
|
||||||
int y = e.RowIndex;
|
|
||||||
Console.WriteLine("Row " + y + " current value: " + DGV_Device.Rows[y].Cells[2].Value.ToString());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach (Entry e in entries)
|
foreach (Entry e in entries)
|
||||||
{
|
{
|
||||||
if (e.length > 1)
|
if (e.length > 1)
|
||||||
@@ -80,9 +51,7 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
// multi-register entry check
|
// multi-register entry check
|
||||||
if ((e.length == 2 && e.dataType == "uint32") || e.dataType == "string")
|
if ((e.length == 2 && e.dataType == "uint32") || e.dataType == "string")
|
||||||
{
|
{
|
||||||
DGV_Device.Rows.Add(rowCount, e.name, "", e.address);
|
entryRows.Add(new EntryRow(rowCount, e.address, e.name));
|
||||||
if (e.registerType == RegisterType.Input || e.registerType == RegisterType.Discrete)
|
|
||||||
DGV_Device.Rows[rowCount].Cells[2].ReadOnly = true;
|
|
||||||
rowCount++;
|
rowCount++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -90,19 +59,13 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
for (int i = 0; i < e.length; i++)
|
for (int i = 0; i < e.length; i++)
|
||||||
{
|
{
|
||||||
if (i < e.labels.Count)
|
if (i < e.labels.Count)
|
||||||
DGV_Device.Rows.Add(rowCount, e.name + ": " + e.labels[i], "", e.address + i);
|
|
||||||
else DGV_Device.Rows.Add(rowCount, e.address + i, "", e.address + i);
|
|
||||||
|
|
||||||
if (i != 0) // Hide rightmost cells for extra registers in the Entry
|
|
||||||
{
|
{
|
||||||
DGV_Device.Rows[rowCount].Cells[4] = new DataGridViewTextBoxCell();
|
entryRows.Add(new EntryRow(rowCount, e.address + i, e.labels[i]));
|
||||||
DGV_Device.Rows[rowCount].Cells[4].Value = "";
|
}
|
||||||
DGV_Device.Rows[rowCount].Cells[4].Style.ForeColor = Color.DarkGray;
|
else
|
||||||
DGV_Device.Rows[rowCount].Cells[4].Style.BackColor = Color.DarkGray;
|
{
|
||||||
DGV_Device.Rows[rowCount].Cells[4].ReadOnly = true;
|
entryRows.Add(new EntryRow(rowCount, e.address + i, (e.address + i).ToString()));
|
||||||
}
|
}
|
||||||
if (e.registerType == RegisterType.Input || e.registerType == RegisterType.Discrete)
|
|
||||||
DGV_Device.Rows[rowCount].Cells[2].ReadOnly = true;
|
|
||||||
rowCount++;
|
rowCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,39 +73,12 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DGV_Device.Rows.Add(rowCount, e.name, "", e.address);
|
entryRows.Add(new EntryRow(rowCount, e.address, e.name));
|
||||||
if (e.registerType == RegisterType.Input || e.registerType == RegisterType.Discrete)
|
|
||||||
DGV_Device.Rows[rowCount].Cells[2].ReadOnly = true;
|
|
||||||
if (e.registerType == RegisterType.Coil)
|
|
||||||
{
|
|
||||||
DGV_Device.Rows[rowCount].Cells[2] = new DataGridViewComboBoxCell();
|
|
||||||
var cbc = DGV_Device.Rows[rowCount].Cells[2] as DataGridViewComboBoxCell;
|
|
||||||
if (e.valueParse != null)
|
|
||||||
{
|
|
||||||
if (e.valueParse.ContainsKey("false"))
|
|
||||||
cbc.Items.Add(e.valueParse["false"]);
|
|
||||||
if (e.valueParse.ContainsKey("true"))
|
|
||||||
cbc.Items.Add(e.valueParse["true"]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cbc.Items.Add("False");
|
|
||||||
cbc.Items.Add("True");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rowCount++;
|
rowCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (DataGridViewRow row in DGV_Device.Rows)
|
foreach (EntryRow row in entryRows)
|
||||||
{
|
Panel_Device.Controls.Add(row);
|
||||||
row.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
|
||||||
if (row.Cells[2] is DataGridViewComboBoxCell)
|
|
||||||
row.Cells[2].Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (DataGridViewColumn column in DGV_Device.Columns)
|
|
||||||
column.SortMode = DataGridViewColumnSortMode.NotSortable; // disabling sorting for now
|
|
||||||
|
|
||||||
FormClosing += (s, e) => { closed = true; };
|
FormClosing += (s, e) => { closed = true; };
|
||||||
Task.Run(() => AutoPollAsync());
|
Task.Run(() => AutoPollAsync());
|
||||||
}
|
}
|
||||||
@@ -158,9 +94,7 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
{
|
{
|
||||||
if (isPolling)
|
if (isPolling)
|
||||||
{
|
{
|
||||||
// holy fuck DGV is awful
|
if (entryRows[activeDGVIndex].chboxPanel.chbox.Checked)
|
||||||
DataGridViewCheckBoxCell chbox = DGV_Device.Rows[activeDGVIndex].Cells[4] as DataGridViewCheckBoxCell;
|
|
||||||
if (Convert.ToBoolean(chbox.Value))
|
|
||||||
{
|
{
|
||||||
//Console.WriteLine("Polling for " + device.entries[activeEntryIndex].name);
|
//Console.WriteLine("Polling for " + device.entries[activeEntryIndex].name);
|
||||||
await PollForEntry(entries[activeEntryIndex]);
|
await PollForEntry(entries[activeEntryIndex]);
|
||||||
@@ -182,7 +116,7 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
activeEntryIndex++;
|
activeEntryIndex++;
|
||||||
if (activeEntryIndex >= device.entries.Count)
|
if (activeEntryIndex >= device.entries.Count)
|
||||||
activeEntryIndex = 0;
|
activeEntryIndex = 0;
|
||||||
if (activeDGVIndex >= DGV_Device.RowCount)
|
if (activeDGVIndex >= entryRows.Count)
|
||||||
activeDGVIndex = 0;
|
activeDGVIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,8 +157,7 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
{
|
{
|
||||||
if (entries[activeEntryIndex].readOnce)
|
if (entries[activeEntryIndex].readOnce)
|
||||||
{
|
{
|
||||||
DataGridViewCheckBoxCell chbox = DGV_Device.Rows[activeDGVIndex].Cells[4] as DataGridViewCheckBoxCell;
|
entryRows[activeDGVIndex].chboxPanel.chbox.Checked = false;
|
||||||
chbox.Value = false;
|
|
||||||
}
|
}
|
||||||
int dbc = e.Message[2]; // data byte count
|
int dbc = e.Message[2]; // data byte count
|
||||||
switch (entries[activeEntryIndex].dataType)
|
switch (entries[activeEntryIndex].dataType)
|
||||||
@@ -233,45 +166,32 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
if (entries[activeEntryIndex].labels is null || entries[activeEntryIndex].labels.Count == 0) // assume that no labels = 1 entry
|
if (entries[activeEntryIndex].labels is null || entries[activeEntryIndex].labels.Count == 0) // assume that no labels = 1 entry
|
||||||
{
|
{
|
||||||
//no valueParse keys
|
//no valueParse keys
|
||||||
if (entries[activeEntryIndex].valueParse is null || entries[activeEntryIndex].valueParse.Keys.Count == 0)
|
if (entries[activeEntryIndex].valueParse is null || entries[activeEntryIndex].valueParse.Keys.Count == 0)
|
||||||
{
|
{
|
||||||
// coil combobox
|
// coil combobox
|
||||||
if (entries[activeEntryIndex].registerType == RegisterType.Coil)
|
if (entries[activeEntryIndex].registerType == RegisterType.Coil)
|
||||||
{
|
{
|
||||||
DGV_Device.Invoke((MethodInvoker)delegate
|
entryRows[activeDGVIndex].SetValue(e.Data[0] > 0x00 ? "True" : "False");
|
||||||
{
|
|
||||||
var cbc = DGV_Device.Rows[activeDGVIndex].Cells[2] as DataGridViewComboBoxCell;
|
|
||||||
cbc.Value = e.Data[0] > 0x00 ? cbc.Items[1] : cbc.Items[0];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// discrete inputs
|
// discrete inputs
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DGV_Device.Invoke((MethodInvoker)delegate
|
entryRows[activeDGVIndex].SetValue(e.Data[0] > 0x00 ? "True" : "False");
|
||||||
{
|
|
||||||
DGV_Device.Rows[activeDGVIndex].Cells[2].Value = e.Data[0] > 0x00 ? "true" : "false";
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try { DGV_Device.Rows[activeDGVIndex].Cells[2].Value = e.Data[0] > 0x00 ? entries[activeEntryIndex].valueParse["true"] : entries[activeEntryIndex].valueParse["false"]; }
|
try { entryRows[activeDGVIndex].valueLabel.Text = e.Data[0] > 0x00 ? entries[activeEntryIndex].valueParse["true"] : entries[activeEntryIndex].valueParse["false"]; }
|
||||||
catch (Exception err)
|
catch (Exception err)
|
||||||
{
|
{
|
||||||
|
// coil combobox
|
||||||
if (entries[activeEntryIndex].registerType == RegisterType.Coil)
|
if (entries[activeEntryIndex].registerType == RegisterType.Coil)
|
||||||
{
|
{
|
||||||
DGV_Device.Invoke((MethodInvoker)delegate
|
entryRows[activeDGVIndex].SetValue(e.Data[0] > 0x00 ? "True" : "False");
|
||||||
{
|
|
||||||
var cbc = DGV_Device.Rows[activeDGVIndex].Cells[2] as DataGridViewComboBoxCell;
|
|
||||||
cbc.Value = e.Data[0] > 0x00 ? cbc.Items[1] : cbc.Items[0];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else // discrete inputs
|
||||||
{
|
{
|
||||||
DGV_Device.Invoke((MethodInvoker)delegate
|
entryRows[activeDGVIndex].SetValue(e.Data[0] > 0x00 ? "True" : "False");
|
||||||
{
|
|
||||||
DGV_Device.Rows[activeDGVIndex].Cells[2].Value = e.Data[0] > 0x00 ? "True" : "False";
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,18 +212,11 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
{
|
{
|
||||||
if (entries[activeEntryIndex].registerType == RegisterType.Coil)
|
if (entries[activeEntryIndex].registerType == RegisterType.Coil)
|
||||||
{
|
{
|
||||||
DGV_Device.Invoke((MethodInvoker)delegate
|
entryRows[activeDGVIndex].SetValue(e.Data[0] > 0x00 ? "True" : "False");
|
||||||
{
|
|
||||||
var cbc = DGV_Device.Rows[activeDGVIndex].Cells[2] as DataGridViewComboBoxCell;
|
|
||||||
cbc.Value = e.Data[0] > 0x00 ? cbc.Items[1] : cbc.Items[0];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DGV_Device.Invoke((MethodInvoker)delegate
|
entryRows[activeDGVIndex].SetValue(e.Data[0] > 0x00 ? "True" : "False");
|
||||||
{
|
|
||||||
DGV_Device.Rows[activeDGVIndex].Cells[2].Value = e.Data[0] > 0x00 ? "true": "false";
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
activeDGVIndex++;
|
activeDGVIndex++;
|
||||||
}
|
}
|
||||||
@@ -318,17 +231,18 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
//Array.Reverse(e.Data); // this was necessary, but something changed, idk
|
//Array.Reverse(e.Data); // this was necessary, but something changed, idk
|
||||||
|
|
||||||
//Console.WriteLine("ushort parsed value: " + value);
|
//Console.WriteLine("ushort parsed value: " + value);
|
||||||
DGV_Device.Rows[activeDGVIndex].Cells[2].Value = value;
|
entryRows[activeDGVIndex].SetValue(value.ToString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DGV_Device.Rows[activeDGVIndex].Cells[2].Value = entries[activeEntryIndex].valueParse[value.ToString()];
|
entryRows[activeDGVIndex].SetValue(entries[activeEntryIndex].valueParse[value.ToString()]);
|
||||||
}
|
}
|
||||||
catch (Exception err)
|
catch (Exception err)
|
||||||
{
|
{
|
||||||
DGV_Device.Rows[activeDGVIndex].Cells[2].Value = value; MessageBox.Show("Error parsing uint value at address: " + entries[activeEntryIndex].address + "; " + err.Message, "uint16 parse");
|
entryRows[activeDGVIndex].SetValue(value.ToString());
|
||||||
|
MessageBox.Show("Error parsing uint value at address: " + entries[activeEntryIndex].address + "; " + err.Message, "uint16 parse");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,21 +264,19 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
{
|
{
|
||||||
if (device.entries[activeEntryIndex].valueParse != null)
|
if (device.entries[activeEntryIndex].valueParse != null)
|
||||||
{
|
{
|
||||||
DGV_Device.Invoke((MethodInvoker)delegate
|
entryRows[activeDGVIndex].SetValue(values[i].ToString());
|
||||||
{
|
|
||||||
DGV_Device.Rows[activeDGVIndex].Cells[2].Value = device.entries[activeEntryIndex].valueParse[values[i].ToString()];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DGV_Device.Rows[activeDGVIndex].Cells[2].Value = values[i];
|
entryRows[activeDGVIndex].SetValue(values[i].ToString());
|
||||||
}
|
}
|
||||||
activeDGVIndex++;
|
activeDGVIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception err)
|
catch (Exception err)
|
||||||
{
|
{
|
||||||
DGV_Device.Rows[activeDGVIndex].Cells[2].Value = value; MessageBox.Show("Error parsing uint value at address: " + entries[activeEntryIndex].address + "; " + err.Message, "uint16 group req parse");
|
entryRows[activeDGVIndex].SetValue(value.ToString());
|
||||||
|
MessageBox.Show("Error parsing uint value at address: " + entries[activeEntryIndex].address + "; " + err.Message, "uint16 group req parse");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,7 +284,7 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
break;
|
break;
|
||||||
case ("uint32"):
|
case ("uint32"):
|
||||||
Array.Reverse(e.Data);
|
Array.Reverse(e.Data);
|
||||||
DGV_Device.Rows[activeDGVIndex].Cells[2].Value = BitConverter.ToUInt32(e.Data, 0);
|
entryRows[activeDGVIndex].SetValue(BitConverter.ToUInt32(e.Data, 0).ToString());
|
||||||
|
|
||||||
activeDGVIndex++;
|
activeDGVIndex++;
|
||||||
|
|
||||||
@@ -385,7 +297,7 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
bytes.Add(e.Data[i]);
|
bytes.Add(e.Data[i]);
|
||||||
}
|
}
|
||||||
bytes.Reverse();
|
bytes.Reverse();
|
||||||
DGV_Device.Rows[activeDGVIndex].Cells[2].Value = System.Text.Encoding.UTF8.GetString(bytes.ToArray());
|
entryRows[activeDGVIndex].SetValue(System.Text.Encoding.UTF8.GetString(bytes.ToArray()));
|
||||||
|
|
||||||
activeDGVIndex++;
|
activeDGVIndex++;
|
||||||
|
|
||||||
@@ -395,7 +307,7 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
activeDGVIndex++;
|
activeDGVIndex++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (activeDGVIndex >= DGV_Device.RowCount)
|
if (activeDGVIndex >= entryRows.Count)
|
||||||
activeDGVIndex = 0;
|
activeDGVIndex = 0;
|
||||||
|
|
||||||
//MessageBox.Show("Получен ответ от устройства: " + dataCleaned, "Успех", MessageBoxButtons.OK);
|
//MessageBox.Show("Получен ответ от устройства: " + dataCleaned, "Успех", MessageBoxButtons.OK);
|
||||||
@@ -404,7 +316,7 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
catch (Exception err) { MessageBox.Show(err.Message, "Publish response error"); }
|
catch (Exception err) { MessageBox.Show(err.Message, "Publish response error"); }
|
||||||
|
|
||||||
}
|
}
|
||||||
if (activeDGVIndex >= DGV_Device.Rows.Count)
|
if (activeDGVIndex >= entryRows.Count)
|
||||||
activeDGVIndex = 0;
|
activeDGVIndex = 0;
|
||||||
isAwaitingResponse = false;
|
isAwaitingResponse = false;
|
||||||
}
|
}
|
||||||
@@ -414,6 +326,52 @@ namespace Gidrolock_Modbus_Scanner
|
|||||||
isPolling = !isPolling;
|
isPolling = !isPolling;
|
||||||
Button_StartStop.Text = (isPolling ? "Стоп" : "Старт");
|
Button_StartStop.Text = (isPolling ? "Стоп" : "Старт");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
public class EntryRow : Panel
|
||||||
|
{
|
||||||
|
public CheckboxPanel chboxPanel = new CheckboxPanel() { Width = 20, Height = 20 };
|
||||||
|
public Label numberLabel = new Label() { Height = 20, Width = 30, TextAlign = ContentAlignment.MiddleLeft };
|
||||||
|
public Label addressLabel = new Label() { Height = 20, Width = 60, TextAlign = ContentAlignment.MiddleLeft };
|
||||||
|
public Label nameLabel = new Label() { Height = 20, Width = 220, TextAlign = ContentAlignment.MiddleLeft };
|
||||||
|
public Label valueLabel = new Label() { Height = 20, Width = 220, TextAlign = ContentAlignment.MiddleLeft };
|
||||||
|
|
||||||
|
public void SetValue(string value)
|
||||||
|
{
|
||||||
|
valueLabel.Text = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntryRow(int number, int address, string name)
|
||||||
|
{
|
||||||
|
chboxPanel.Parent = this;
|
||||||
|
numberLabel.Parent = this;
|
||||||
|
addressLabel.Parent = this;
|
||||||
|
nameLabel.Parent = this;
|
||||||
|
valueLabel.Parent = this;
|
||||||
|
|
||||||
|
chboxPanel.Location = new Point(Left, Top);
|
||||||
|
numberLabel.Location = new Point(20, Top);
|
||||||
|
addressLabel.Location = new Point(50, Top);
|
||||||
|
nameLabel.Location = new Point(110, Top);
|
||||||
|
valueLabel.Location = new Point(330, Top);
|
||||||
|
|
||||||
|
numberLabel.Text = number.ToString();
|
||||||
|
addressLabel.Text = address.ToString();
|
||||||
|
nameLabel.Text = name.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CheckboxPanel : Panel
|
||||||
|
{
|
||||||
|
public CheckBox chbox;
|
||||||
|
public CheckboxPanel() : base()
|
||||||
|
{
|
||||||
|
chbox = new CheckBox() { Parent = this, Location = new Point(Left, Top) };
|
||||||
|
}
|
||||||
|
public void SetVisibility(bool value)
|
||||||
|
{
|
||||||
|
chbox.Visible = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user