Cleanup and Enhancement
This commit is contained in:
@@ -49,9 +49,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
|
||||
protected async Task<(string, string)> ReceiveResponse(string? expectedCmd = null) {
|
||||
var line = Serial.ReadLine();
|
||||
if (line == null) {
|
||||
throw new IOException("Verbindung zu SPS (T1) verloren");
|
||||
} else if (line.Length < 8 || !line.StartsWith("(A") || !line.EndsWith(')') || line[^4] != '&') {
|
||||
if (line.Length < 8 || !line.StartsWith("(A") || !line.EndsWith(')') || line[^4] != '&') {
|
||||
throw new FormatException("Invalid response from PLC (T1)");
|
||||
}
|
||||
|
||||
@@ -90,7 +88,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
return (cmd, data);
|
||||
}
|
||||
|
||||
public async Task Test(string data = "PINGPONG") {
|
||||
public async Task Test(string data = "_Ping_Pong_0123456789_abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ_") {
|
||||
await SendCommand("TS", data);
|
||||
var (_, res) = await ReceiveResponse("TS");
|
||||
if (data.Replace(" ", "") != res) throw new T1Exception("Wrong test response from PLC (T1)");
|
||||
@@ -125,7 +123,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
}
|
||||
|
||||
public async Task<Status> DataWrite(params (string Register, ushort[] Values)[] registers) {
|
||||
await SendCommand("DW", string.Join(',', registers.Select(r => $"{r.Register},{r.Values.Length}," + string.Join(',', r.Values.Select(v => $"{v:X4}")))));
|
||||
await SendCommand("DW", string.Join(',', registers.Select(r => $"{r.Register},{r.Values.Length}," + string.Join(',', r.Values.Select(v => $"{v:X}")))));
|
||||
var (_, res) = await ReceiveResponse("ST");
|
||||
return new Status((Mode)(res[3] - '0'), ((res[0] - '0') << 4) | (res[1] - '0'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user