Files
gidrolock-configurator/Datasheet.cs

63 lines
1.6 KiB
C#
Raw Normal View History

2024-12-05 15:57:07 +03:00
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO.Ports;
2024-12-05 15:57:07 +03:00
using System.Linq;
using System.Threading;
2024-12-05 15:57:07 +03:00
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
2024-12-05 15:57:07 +03:00
namespace Gidrolock_Modbus_Scanner
{
2025-01-17 10:40:18 +03:00
/*
* This is more of a View than a View-Controller
* Relegate everything to interface functions for models
*/
2024-12-05 15:57:07 +03:00
public partial class Datasheet : Form
{
2025-01-14 11:31:23 +03:00
byte modbusID;
Device device;
SerialPort port = Modbus.port;
2024-12-16 11:35:20 +03:00
bool isPolling = false;
2024-12-09 16:24:02 +03:00
bool isAwaitingResponse = false;
byte[] message = new byte[255];
2025-01-14 11:31:23 +03:00
public Datasheet(byte modbusID, Device device)
2024-12-05 15:57:07 +03:00
{
2025-01-14 11:31:23 +03:00
nudModbusID.Minimum = 1;
nudModbusID.Maximum = 246;
this.modbusID = modbusID;
this.device = device;
}
2024-12-05 17:52:25 +03:00
2025-01-14 11:31:23 +03:00
private async void buttonSetID_Click(object sender, EventArgs e)
{
2025-01-14 11:31:23 +03:00
Modbus.WriteSingleAsync(FunctionCode.WriteRegister, modbusID, 200, (byte)nudModbusID.Value);
byte[] data = null;
Modbus.ResponseReceived += (sndr, msg) =>
{
2025-01-14 11:31:23 +03:00
data = msg.Data;
};
await Task.Run(() =>
2024-12-09 16:24:02 +03:00
{
2025-01-14 11:31:23 +03:00
while (data is null) { continue; }
if (message[1] > 0x10) //exception code check
return;
2024-12-09 16:24:02 +03:00
});
}
2025-01-17 10:40:18 +03:00
private void buttonValve_Click(object sender, EventArgs e)
{
}
private void buttonAlarm_Click(object sender, EventArgs e)
{
}
}
}