autopolling mostly done

This commit is contained in:
nikzori
2024-12-16 15:52:01 +03:00
parent f13922491d
commit f76094cab4
3 changed files with 12 additions and 16 deletions

1
Datasheet.Designer.cs generated
View File

@@ -41,6 +41,7 @@
// //
// DGV_Device // DGV_Device
// //
this.DGV_Device.AllowUserToAddRows = false;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
this.DGV_Device.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; this.DGV_Device.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
this.DGV_Device.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.DGV_Device.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)

View File

@@ -55,7 +55,7 @@ namespace Gidrolock_Modbus_Scanner
DGV_Device.Columns.Add(new DataGridViewCheckBoxColumn()); DGV_Device.Columns.Add(new DataGridViewCheckBoxColumn());
DGV_Device.Columns[4].Name = "Опрос"; DGV_Device.Columns[4].Name = "Опрос";
DGV_Device.Columns[4].FillWeight = 20; DGV_Device.Columns[4].FillWeight = 20;
DGV_Device.Columns[4].ValueType = typeof(bool);
for (int i = 0; i < entries.Count; i++) for (int i = 0; i < entries.Count; i++)
{ {
@@ -83,11 +83,14 @@ namespace Gidrolock_Modbus_Scanner
{ {
for (int i = 0; i < entries.Count; i++) for (int i = 0; i < entries.Count; i++)
{ {
// TODO: figure out how to get the checkbox value out of DataGridView cells; // holy fuck DGV is awful
// holy fuck DGV is awful DataGridViewCheckBoxCell chbox = DGV_Device.Rows[i].Cells[4] as DataGridViewCheckBoxCell;
activeEntryIndex = i; if (Convert.ToBoolean(chbox.Value))
await PollForEntry(entries[i]); {
Console.WriteLine("Polling for " + device.entries[i].name);
activeEntryIndex = i;
await PollForEntry(entries[i]);
}
} }
} }
} }
@@ -101,7 +104,6 @@ namespace Gidrolock_Modbus_Scanner
public async Task PollForEntry(Entry entry) public async Task PollForEntry(Entry entry)
{ {
byte[] message = new byte[9]; byte[] message = new byte[9];
Console.WriteLine("Sending message: " + Modbus.ByteArrayToString(Modbus.BuildMessage(slaveID, (byte)entry.registerType, entry.address, entry.length, ref message)));
var send = await Modbus.ReadRegAsync(port, slaveID, (FunctionCode)entry.registerType, entry.address, entry.length); var send = await Modbus.ReadRegAsync(port, slaveID, (FunctionCode)entry.registerType, entry.address, entry.length);
isAwaitingResponse = true; isAwaitingResponse = true;
@@ -123,11 +125,8 @@ namespace Gidrolock_Modbus_Scanner
if (isAwaitingResponse) if (isAwaitingResponse)
{ {
isAwaitingResponse = false; isAwaitingResponse = false;
try try
{ {
Console.WriteLine("Data after processing in Datasheet.cs: " + Modbus.ByteArrayToString(e.Data));
switch (entries[activeEntryIndex].dataType) switch (entries[activeEntryIndex].dataType)
{ {
case ("bool"): case ("bool"):

View File

@@ -186,8 +186,6 @@ namespace Gidrolock_Modbus_Scanner
static void PortDataReceived(object sender, EventArgs e) static void PortDataReceived(object sender, EventArgs e)
{ {
Console.WriteLine("Data receieved on Serial Port");
try try
{ {
byte[] message = new byte[port.BytesToRead]; byte[] message = new byte[port.BytesToRead];
@@ -197,15 +195,13 @@ namespace Gidrolock_Modbus_Scanner
{ {
port.Read(message, i + 3, 1); port.Read(message, i + 3, 1);
} }
Console.WriteLine("Raw data from port: " + BitConverter.ToString(message));
byte[] data = new byte[length]; byte[] data = new byte[length];
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
data[i] = message[i + 3]; data[i] = message[i + 3];
} }
string dataCleaned = ByteArrayToString(message); string dataCleaned = ByteArrayToString(message);
Console.WriteLine("Received response: " + dataCleaned);
Console.WriteLine("UTF8: " + Encoding.UTF8.GetString(data));
port.DiscardInBuffer(); port.DiscardInBuffer();