Files
DP44/DataPRO/RibeyeCommands/CalibrationCommands.cs
2026-04-17 14:55:32 -04:00

116 lines
4.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using DTS.Common.Enums.DASFactory;
using DTS.Common.ICommunication;
using DTS.DASLib.Utility;
namespace DTS.DASLib.Command.Ribeye
{
public abstract class DiagnosticsCommands : CommandBase
{
protected enum Commands
{
Reserved = 0x00,
QueryCurrentPositions = 0x01,
};
protected abstract Commands _Command { get; }
protected DiagnosticsCommands(DTS.Common.Interface.DASFactory.ICommunication sock)
: base(sock)
{
command.Type = CommandPacket.CommandType.Diagnostics;
command.SetCommand((byte)_Command, _Command.ToString());
}
protected DiagnosticsCommands(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)
: base(sock, TimeoutMillisec)
{
command.Type = CommandPacket.CommandType.Diagnostics;
command.SetCommand((byte)_Command, _Command.ToString());
}
}
public class QueryCurrentPositions : DiagnosticsCommands
{
protected override DiagnosticsCommands.Commands _Command
{
get { return Commands.QueryCurrentPositions; }
}
private int _numChannels = 0;
private float[] _Positions;
const string QueryCurrentPositionsCommand = "CURRENT_POSITIONS";
/// <summary>
/// Read-only property to retrieve the number of stack channels being offset.
/// </summary>
public int NumberOfChannels
{
get { return _numChannels; }
}
/// <summary>
/// The list of stack channels to offset.
/// </summary>
/// <summary>
/// The millivolt value that the channel deflected to with the target deflection applied.
/// </summary>
public float[] Positions { get { return _Positions; } }
public QueryCurrentPositions(DTS.Common.Interface.DASFactory.ICommunication sock)
: base(sock)
{
InitializeMembers();
}
public QueryCurrentPositions(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)
: base(sock, TimeoutMillisec)
{
InitializeMembers();
}
private void InitializeMembers()
{
command.Parameter = new string[1];
command.SetParameter(0, QueryCurrentPositionsCommand);
}
protected override CommandReceiveAction WholePackage()
{
if (response.Status == DFConstantsAndEnums.CommandStatus.StatusNoError)
{
int NumberOfPositions;
response.GetParameter(1, out NumberOfPositions);
_numChannels = NumberOfPositions;
_Positions = new float[NumberOfPositions];
string PositionString;
response.GetParameter(2, out PositionString);
string[] PositionList = PositionString.Split(',');
// Mask firmware problem
if (PositionList[PositionList.Length - 1].Contains(" "))
{
string[] NewPositionList = new string[PositionList.Length + 1];
for (int CurrentPosition = 0; CurrentPosition < PositionList.Length; CurrentPosition++)
{
NewPositionList[CurrentPosition] = PositionList[CurrentPosition];
}
string[] FinalTwoPositions = PositionList[PositionList.Length - 1].Trim().Split(' ');
NewPositionList[NewPositionList.Length - 2] = FinalTwoPositions[0];
NewPositionList[NewPositionList.Length - 1] = FinalTwoPositions[1];
PositionList = NewPositionList;
}
for (int i = 0; i < NumberOfPositions; i++)
{
_Positions[i] = float.Parse(PositionList[i]);
}
}
return CommandReceiveAction.StopReceiving;
}
}
}