inp register group read still doesn`t work
This commit is contained in:
29
Datasheet.cs
29
Datasheet.cs
@@ -122,8 +122,7 @@ namespace Gidrolock_Modbus_Scanner
|
||||
if (Convert.ToBoolean(chbox.Value))
|
||||
{
|
||||
Console.WriteLine("Polling for " + device.entries[activeEntryIndex].name);
|
||||
await PollForEntry(entries[activeEntryIndex]);
|
||||
await Task.Delay(150);
|
||||
await PollForEntry(entries[activeEntryIndex]).ContinueWith(_ => Task.Delay(150));
|
||||
}
|
||||
else //need to skip multiple dgv entries without accidentaly skipping entries
|
||||
{
|
||||
@@ -143,8 +142,6 @@ namespace Gidrolock_Modbus_Scanner
|
||||
activeEntryIndex = 0;
|
||||
if (activeDGVIndex >= DGV_Device.RowCount)
|
||||
activeDGVIndex = 0;
|
||||
|
||||
Console.WriteLine("entry index: " + activeEntryIndex + "; dgv index: " + activeDGVIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,9 +193,9 @@ namespace Gidrolock_Modbus_Scanner
|
||||
else
|
||||
{
|
||||
try { DGV_Device.Rows[activeEntryIndex].Cells[2].Value = e.Data[0] > 0x00 ? entries[activeEntryIndex].valueParse["true"] : entries[activeEntryIndex].valueParse["false"]; }
|
||||
catch
|
||||
catch (Exception err)
|
||||
{
|
||||
Console.WriteLine("Value parsing error for bool entry: " + entries[activeEntryIndex].name);
|
||||
MessageBox.Show("Value parsing error for bool entry: " + entries[activeEntryIndex].name + "; " + err.Message);
|
||||
DGV_Device.Rows[activeEntryIndex].Cells[2].Value = e.Data[0] > 0x00 ? "true" : "false";
|
||||
}
|
||||
}
|
||||
@@ -239,17 +236,23 @@ namespace Gidrolock_Modbus_Scanner
|
||||
{
|
||||
DGV_Device.Rows[activeDGVIndex].Cells[2].Value = entries[activeEntryIndex].valueParse[value.ToString()];
|
||||
}
|
||||
catch { DGV_Device.Rows[activeDGVIndex].Cells[2].Value = value; Console.WriteLine("Error parsing uint value at address: " + entries[activeEntryIndex].address); }
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
activeDGVIndex++;
|
||||
}
|
||||
else // value group
|
||||
{
|
||||
try
|
||||
{
|
||||
List<ushort> values = new List<ushort>();
|
||||
for (int i = 0; i < dbc; i += 2)
|
||||
for (int i = 0; i < dbc - 2; i += 2)
|
||||
{
|
||||
ushort s = BitConverter.ToUInt16(e.Data, i);
|
||||
Console.WriteLine("ushort value: " + s);
|
||||
values.Add(s);
|
||||
}
|
||||
for (int i = 0; i < entries[activeEntryIndex].labels.Count; i++)
|
||||
@@ -258,6 +261,12 @@ namespace Gidrolock_Modbus_Scanner
|
||||
activeDGVIndex++;
|
||||
}
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case ("uint32"):
|
||||
@@ -291,7 +300,9 @@ namespace Gidrolock_Modbus_Scanner
|
||||
//MessageBox.Show("Получен ответ от устройства: " + dataCleaned, "Успех", MessageBoxButtons.OK);
|
||||
port.DiscardInBuffer();
|
||||
}
|
||||
catch { return; }
|
||||
catch (Exception err) {
|
||||
MessageBox.Show(err.Message, "Publish response error");
|
||||
}
|
||||
|
||||
}
|
||||
if (activeDGVIndex >= DGV_Device.Rows.Count)
|
||||
|
||||
@@ -241,7 +241,7 @@ namespace Gidrolock_Modbus_Scanner
|
||||
{
|
||||
byte[] message = new byte[port.BytesToRead];
|
||||
port.Read(message, 0, port.BytesToRead);
|
||||
Console.WriteLine("Incoming message: " + ByteArrayToString(message));
|
||||
Console.WriteLine("Incoming message: " + ByteArrayToString(message, false));
|
||||
if (message[1] <= 0x04) // read functions
|
||||
{
|
||||
Console.WriteLine("It's a read message");
|
||||
@@ -263,7 +263,7 @@ namespace Gidrolock_Modbus_Scanner
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
MessageBox.Show(err.Message);
|
||||
MessageBox.Show(err.Message, "Modbus message reception error");
|
||||
}
|
||||
port.DiscardInBuffer();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user