datasheet window wip
This commit is contained in:
48
Datasheet.Designer.cs
generated
Normal file
48
Datasheet.Designer.cs
generated
Normal file
@@ -0,0 +1,48 @@
|
||||
namespace Gidrolock_Modbus_Scanner
|
||||
{
|
||||
partial class Datasheet
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Datasheet));
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// Datasheet
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(740, 450);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.Name = "Datasheet";
|
||||
this.Text = "Datasheet";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
36
Datasheet.cs
Normal file
36
Datasheet.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Gidrolock_Modbus_Scanner
|
||||
{
|
||||
public partial class Datasheet : Form
|
||||
{
|
||||
int pollDelay = 250; // delay between each entry poll, ms
|
||||
List<EntryUI> entries = new List<EntryUI>();
|
||||
|
||||
public Datasheet()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
|
||||
public class EntryUI : GroupBox
|
||||
{
|
||||
public Label Label_Name;
|
||||
public Label Label_Value;
|
||||
public ToolTip ToolTip;
|
||||
public EntryUI(string name, string description, int address, string registerType, string dataType)
|
||||
{
|
||||
Label_Name.Text = name;
|
||||
ToolTip.SetToolTip(this, description);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="JSONParser.cs" />
|
||||
<Compile Include="json.cs" />
|
||||
<Compile Include="Modbus.cs" />
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
@@ -79,6 +79,7 @@
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Timeout.cs" />
|
||||
<Compile Include="Tools.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Gidrolock_Modbus_Scanner
|
||||
{
|
||||
public struct Entry
|
||||
{
|
||||
public string label;
|
||||
public RegisterType registerType;
|
||||
public int offset;
|
||||
public int length;
|
||||
|
||||
public Entry(string label, RegisterType registerType, int offset, int length)
|
||||
{
|
||||
this.label = label;
|
||||
this.registerType = registerType;
|
||||
this.offset = offset;
|
||||
this.length = length;
|
||||
}
|
||||
}
|
||||
public enum RegisterType { Coil, DiscreteInput, HoldingRegister, InputRegister }
|
||||
}
|
||||
44
Json.cs
Normal file
44
Json.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
||||
namespace Gidrolock_Modbus_Scanner
|
||||
{
|
||||
public class Device
|
||||
{
|
||||
public string name;
|
||||
public string description;
|
||||
public List<Entry> entries;
|
||||
|
||||
public Device(string name, string description, List<Entry> entries)
|
||||
{
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.entries = entries;
|
||||
}
|
||||
}
|
||||
public struct Entry
|
||||
{
|
||||
public string name;
|
||||
public RegisterType registerType;
|
||||
public int address;
|
||||
public int length;
|
||||
public string dataType;
|
||||
public bool readOnce;
|
||||
|
||||
public Entry(string name, RegisterType registerType, int address, int length, string dataType, bool readOnce)
|
||||
{
|
||||
this.name = name;
|
||||
this.registerType = registerType;
|
||||
this.address = address;
|
||||
this.length = length;
|
||||
this.dataType = dataType;
|
||||
this.readOnce = readOnce;
|
||||
}
|
||||
}
|
||||
public enum RegisterType { Coil, DiscreteInput, HoldingRegister, InputRegister }
|
||||
}
|
||||
63
Form1.Designer.cs → Main.Designer.cs
generated
63
Form1.Designer.cs → Main.Designer.cs
generated
@@ -51,7 +51,7 @@
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.CBox_Ports = new System.Windows.Forms.ComboBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.ButtonConnect = new System.Windows.Forms.Button();
|
||||
this.Button_Connect = new System.Windows.Forms.Button();
|
||||
this.TextBox_Log = new System.Windows.Forms.TextBox();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.panel6 = new System.Windows.Forms.Panel();
|
||||
@@ -80,6 +80,9 @@
|
||||
this.groupBox4 = new System.Windows.Forms.GroupBox();
|
||||
this.Radio_Ethernet = new System.Windows.Forms.RadioButton();
|
||||
this.Radio_SerialPort = new System.Windows.Forms.RadioButton();
|
||||
this.Button_LoadConfig = new System.Windows.Forms.Button();
|
||||
this.label12 = new System.Windows.Forms.Label();
|
||||
this.Label_Config = new System.Windows.Forms.Label();
|
||||
this.GBox_Serial.SuspendLayout();
|
||||
this.panel11.SuspendLayout();
|
||||
this.panel10.SuspendLayout();
|
||||
@@ -308,17 +311,17 @@
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "Порт";
|
||||
//
|
||||
// ButtonConnect
|
||||
// Button_Connect
|
||||
//
|
||||
this.ButtonConnect.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
this.Button_Connect.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonConnect.Location = new System.Drawing.Point(203, 155);
|
||||
this.ButtonConnect.Name = "ButtonConnect";
|
||||
this.ButtonConnect.Size = new System.Drawing.Size(100, 25);
|
||||
this.ButtonConnect.TabIndex = 4;
|
||||
this.ButtonConnect.Text = "Подключиться";
|
||||
this.ButtonConnect.UseVisualStyleBackColor = true;
|
||||
this.ButtonConnect.Click += new System.EventHandler(this.ButtonConnect_Click);
|
||||
this.Button_Connect.Location = new System.Drawing.Point(402, 155);
|
||||
this.Button_Connect.Name = "Button_Connect";
|
||||
this.Button_Connect.Size = new System.Drawing.Size(100, 25);
|
||||
this.Button_Connect.TabIndex = 4;
|
||||
this.Button_Connect.Text = "Подключиться";
|
||||
this.Button_Connect.UseVisualStyleBackColor = true;
|
||||
this.Button_Connect.Click += new System.EventHandler(this.ButtonConnect_Click);
|
||||
//
|
||||
// TextBox_Log
|
||||
//
|
||||
@@ -579,17 +582,50 @@
|
||||
this.Radio_SerialPort.UseVisualStyleBackColor = true;
|
||||
this.Radio_SerialPort.CheckedChanged += new System.EventHandler(this.Radio_SerialPort_CheckedChanged);
|
||||
//
|
||||
// Button_LoadConfig
|
||||
//
|
||||
this.Button_LoadConfig.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.Button_LoadConfig.Location = new System.Drawing.Point(292, 155);
|
||||
this.Button_LoadConfig.Name = "Button_LoadConfig";
|
||||
this.Button_LoadConfig.Size = new System.Drawing.Size(100, 25);
|
||||
this.Button_LoadConfig.TabIndex = 8;
|
||||
this.Button_LoadConfig.Text = "Выбрать";
|
||||
this.Button_LoadConfig.UseVisualStyleBackColor = true;
|
||||
this.Button_LoadConfig.Click += new System.EventHandler(this.LoadConfig);
|
||||
//
|
||||
// label12
|
||||
//
|
||||
this.label12.AutoSize = true;
|
||||
this.label12.Location = new System.Drawing.Point(9, 161);
|
||||
this.label12.Name = "label12";
|
||||
this.label12.Size = new System.Drawing.Size(83, 13);
|
||||
this.label12.TabIndex = 9;
|
||||
this.label12.Text = "Конфигурация:";
|
||||
//
|
||||
// Label_Config
|
||||
//
|
||||
this.Label_Config.AutoSize = true;
|
||||
this.Label_Config.Location = new System.Drawing.Point(90, 161);
|
||||
this.Label_Config.Name = "Label_Config";
|
||||
this.Label_Config.Size = new System.Drawing.Size(66, 13);
|
||||
this.Label_Config.TabIndex = 1;
|
||||
this.Label_Config.Text = "не выбрана";
|
||||
//
|
||||
// App
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(514, 391);
|
||||
this.Controls.Add(this.Label_Config);
|
||||
this.Controls.Add(this.label12);
|
||||
this.Controls.Add(this.Button_LoadConfig);
|
||||
this.Controls.Add(this.groupBox4);
|
||||
this.Controls.Add(this.GBox_Ethernet);
|
||||
this.Controls.Add(this.groupBox2);
|
||||
this.Controls.Add(this.TextBox_Log);
|
||||
this.Controls.Add(this.GBox_Serial);
|
||||
this.Controls.Add(this.ButtonConnect);
|
||||
this.Controls.Add(this.Button_Connect);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MaximizeBox = false;
|
||||
this.Name = "App";
|
||||
@@ -647,7 +683,7 @@
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.ComboBox CBox_Ports;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Button ButtonConnect;
|
||||
private System.Windows.Forms.Button Button_Connect;
|
||||
private System.Windows.Forms.TextBox TextBox_Log;
|
||||
private System.Windows.Forms.GroupBox groupBox2;
|
||||
private System.Windows.Forms.Panel panel5;
|
||||
@@ -691,6 +727,9 @@
|
||||
private System.Windows.Forms.GroupBox groupBox4;
|
||||
private System.Windows.Forms.RadioButton Radio_Ethernet;
|
||||
private System.Windows.Forms.RadioButton Radio_SerialPort;
|
||||
private System.Windows.Forms.Button Button_LoadConfig;
|
||||
private System.Windows.Forms.Label label12;
|
||||
private System.Windows.Forms.Label Label_Config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ using System.Windows.Forms.Automation;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Net.Sockets;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Gidrolock_Modbus_Scanner
|
||||
{
|
||||
@@ -32,14 +34,15 @@ namespace Gidrolock_Modbus_Scanner
|
||||
public bool isAwaitingResponse = false;
|
||||
public bool isProcessingResponse = false;
|
||||
public short[] res = new short[12];
|
||||
public SerialPort port = new SerialPort();
|
||||
public static SerialPort port = new SerialPort();
|
||||
public int expectedLength = 0;
|
||||
|
||||
public static Device device;
|
||||
|
||||
public App()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(PortDataReceived);
|
||||
port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(PortDataReceived);
|
||||
this.UpDown_ModbusID.Value = 30;
|
||||
TextBox_Log.Text = "Приложение готово к работе.";
|
||||
|
||||
@@ -117,8 +120,8 @@ namespace Gidrolock_Modbus_Scanner
|
||||
void Init()
|
||||
{
|
||||
if (UpDown_ModbusID.Value == 0)
|
||||
ButtonConnect.Text = "Найти адрес";
|
||||
else ButtonConnect.Text = "Подключиться";
|
||||
Button_Connect.Text = "Найти адрес";
|
||||
else Button_Connect.Text = "Подключиться";
|
||||
}
|
||||
|
||||
async Task SendMessageAsync(FunctionCode functionCode, ushort address, ushort length)
|
||||
@@ -139,8 +142,8 @@ namespace Gidrolock_Modbus_Scanner
|
||||
port.DataBits = DataBits[CBox_DataBits.SelectedIndex];
|
||||
port.StopBits = (StopBits)CBox_StopBits.SelectedIndex;
|
||||
|
||||
port.ReadTimeout = 1000;
|
||||
port.WriteTimeout = 1000;
|
||||
port.ReadTimeout = 3000;
|
||||
port.WriteTimeout = 3000;
|
||||
|
||||
|
||||
offset = 0;
|
||||
@@ -159,7 +162,7 @@ namespace Gidrolock_Modbus_Scanner
|
||||
var send = await Modbus.ReadRegAsync(port, functionCode, (byte)UpDown_ModbusID.Value, address, length);
|
||||
AddLog("Отправка сообщения: " + messageParsed);
|
||||
isAwaitingResponse = true;
|
||||
Task timer = Task.Delay(2000);
|
||||
Task timer = Task.Delay(port.ReadTimeout);
|
||||
await timer.ContinueWith(_ =>
|
||||
{
|
||||
if (isAwaitingResponse)
|
||||
@@ -205,11 +208,18 @@ namespace Gidrolock_Modbus_Scanner
|
||||
|
||||
private async void ButtonConnect_Click(object sender, EventArgs e)
|
||||
{
|
||||
AddLog("Попытка подключиться к устройству Gidrolock.");
|
||||
|
||||
if (Radio_SerialPort.Checked)
|
||||
await SendMessageAsync(FunctionCode.InputRegister, 200, 6);
|
||||
//else EthernetParse();
|
||||
if (device is null)
|
||||
MessageBox.Show("Выберите конфигурацию для подключения и опроса устройства.");
|
||||
else
|
||||
{
|
||||
AddLog("Попытка подключиться к устройству " + device.name);
|
||||
Datasheet datasheet = new Datasheet();
|
||||
/*
|
||||
if (Radio_SerialPort.Checked)
|
||||
await SendMessageAsync(FunctionCode.InputRegister, 200, 6);
|
||||
//else EthernetParse();
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
async void EthernetParse()
|
||||
@@ -351,6 +361,44 @@ namespace Gidrolock_Modbus_Scanner
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
private void LoadConfig(object sender, EventArgs e)
|
||||
{
|
||||
var fileContent = string.Empty;
|
||||
var filePath = string.Empty;
|
||||
|
||||
using (OpenFileDialog openFileDialog = new OpenFileDialog())
|
||||
{
|
||||
openFileDialog.InitialDirectory = Application.StartupPath;
|
||||
openFileDialog.Filter = "JSON files (*.json)|*.json";
|
||||
openFileDialog.FilterIndex = 2;
|
||||
openFileDialog.RestoreDirectory = true;
|
||||
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
//Get the path of specified file
|
||||
filePath = openFileDialog.FileName;
|
||||
|
||||
//Read the contents of the file into a stream
|
||||
var fileStream = openFileDialog.OpenFile();
|
||||
|
||||
using (StreamReader reader = new StreamReader(fileStream))
|
||||
{
|
||||
fileContent = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
device = JsonConvert.DeserializeObject<Device>(fileContent);
|
||||
Label_Config.Text = device.name;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
MessageBox.Show(err.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
Timeout.cs
10
Timeout.cs
@@ -1,10 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Gidrolock_Modbus_Scanner
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user