removed device selection in favour of auto-detection

This commit is contained in:
nikzori
2025-01-27 11:23:57 +03:00
parent 0012d3e8a1
commit 6514007cdb
5 changed files with 117 additions and 174 deletions

View File

@@ -346,6 +346,38 @@ namespace Gidrolock_Modbus_Scanner
buttonCleaning.Text = cleaningStatus ? "Выключить" : "Включить";
}
}
private async void buttonSetSpeed_Click(object sender, EventArgs e)
{
try
{
string str = cBoxSpeed.Items[cBoxSpeed.SelectedIndex].ToString();
str = str.Substring(0, str.Length - 2); //clip off two zeroes at the end
ushort newSpeed = (ushort)Int16.Parse(str);
//Console.WriteLine("Baudrate: " + newSpeed);
// send speed value to device
// await for response
Modbus.WriteSingleAsync(FunctionCode.WriteRegister, modbusID, device.baudRate.address, newSpeed);
await Task.Delay(2000).ContinueWith(_ =>
{
if (isAwaitingResponse)
{
MessageBox.Show("Превышено время ожидания ответа от устройства.");
isAwaitingResponse = false;
}
return false;
});
while (isAwaitingResponse) { continue; }
if (latestMessage.Status != ModbusStatus.Error)
{
port.Close();
port.BaudRate = newSpeed;
port.Open();
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
}
public class Sensor : FlowLayoutPanel
{