Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting the Max and Min value for FLOAT parameters. Supporting the Min and Max value from register and not only from formula #110

Merged
merged 6 commits into from
Jul 21, 2024
10 changes: 10 additions & 0 deletions GenICam/Interfaces/ICategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,15 @@ public interface ICategory
/// Gets the PValue.
/// </summary>
public IPValue PValue { get; }

/// <summary>
/// Gets the Max PValue.
/// </summary>
public IPValue PMax { get; }

/// <summary>
/// Gets the Min PValue.
/// </summary>
public IPValue PMin { get; }
}
}
30 changes: 27 additions & 3 deletions GenICam/Models/GenCategories/GenFloat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ public class GenFloat : GenCategory, IFloat
/// <param name="categoryProperties">the category properties.</param>
/// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param>
/// <param name="pMin">The address pointer to min value.</param>
/// <param name="pMax">The address pointer to max value.</param>
/// <param name="inc">The increment.</param>
/// <param name="incMode">The increment mode.</param>
/// <param name="representation">The representation.</param>
/// <param name="value">The value.</param>
/// <param name="unit">The unit.</param>
/// <param name="pValue">The PValue.</param>
/// <param name="expressions">The expressions.</param>
public GenFloat(CategoryProperties categoryProperties, double min, double max, long inc, IncrementMode incMode, Representation representation, double value, string unit, IPValue pValue)
public GenFloat(CategoryProperties categoryProperties, double min, double max, IPValue pMin, IPValue pMax, long inc, IncrementMode incMode, Representation representation, double value, string unit, IPValue pValue)
: base(categoryProperties, pValue)
{
PMax = pMax;
PMin = pMin;
Min = min;
Max = max;
Inc = inc;
Expand All @@ -37,6 +41,16 @@ public GenFloat(CategoryProperties categoryProperties, double min, double max, l
GetValueCommand = new DelegateCommand(ExecuteGetValueCommand);
}

/// <summary>
/// Gets the pointer on the mathematical maximum value.
/// </summary>
public IPValue PMax { get; }

/// <summary>
/// Gets the pointer on the mathematical minimum value.
/// </summary>
public IPValue PMin { get; }

/// <summary>
/// Gets the minimum value.
/// </summary>
Expand Down Expand Up @@ -172,14 +186,24 @@ public List<double> GetListOfValidValue()
/// <exception cref="NotImplementedException">Not yet implemented.</exception>
public async Task<double> GetMaxAsync()
{
throw new NotImplementedException();
if (PMax is not null)
{
return (long)(await PMax.GetValueAsync());
}

return Max;
}

/// <inheritdoc/>
/// <exception cref="NotImplementedException">Not yet implemented.</exception>
public async Task<double> GetMinAsync()
{
throw new NotImplementedException();
if (PMin is not null)
{
return (long)(await PMin.GetValueAsync());
}

return Min;
}

/// <inheritdoc/>
Expand Down
14 changes: 14 additions & 0 deletions GenICam/Models/GenCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public GenCategory(CategoryProperties categoryProperties, IPValue pValue)
PValue = pValue;
}

public GenCategory(CategoryProperties categoryProperties, IPValue pValue, IPValue pMIn, IPValue pMax)
{
CategoryProperties = categoryProperties;
PValue = pValue;
PMax = pMax;
PMin = pMIn;
}

/// <inheritdoc/>
public CategoryProperties CategoryProperties { get; internal set; }

Expand All @@ -26,6 +34,12 @@ public GenCategory(CategoryProperties categoryProperties, IPValue pValue)
/// <inheritdoc/>
public IPValue PValue { get; internal set; }

/// <inheritdoc/>
public IPValue PMin { get; internal set; }

/// <inheritdoc/>
public IPValue PMax { get; internal set; }

/// <summary>
/// Gets the group name.
/// </summary>
Expand Down
65 changes: 61 additions & 4 deletions GenICam/Services/XmlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ private async Task<IMathematical> GetFormula(XmlNode xmlNode)
/// </summary>
/// <param name="name">The name of the register.</param>
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
public async Task<(IPValue pValue, IRegister register)> GetRegisterByName(string name)
public async Task<(IPValue pValue, IRegister register, IPValue minPValue, IPValue maxPValue)> GetRegisterByName(string name)
{
try
{
(IPValue pValue, IRegister register) tuple = new(null, null);
(IPValue pValue, IRegister register, IPValue minPValue, IPValue maxPValue) tuple = new(null, null, null, null);
if (GetAllNodesByAttirbuteValue(attirbuteValue: name) is XmlNodeList xmlNodeList)
{
ICategory category = null;
Expand All @@ -171,6 +171,16 @@ private async Task<IMathematical> GetFormula(XmlNode xmlNode)
tuple.pValue = pValue;
}

if (category.PMin is IPValue minPValue)
{
tuple.minPValue = minPValue;
}

if (category.PMax is IPValue MaxPValue)
{
tuple.maxPValue = MaxPValue;
}

if (category.PValue is IRegister register)
{
tuple.register = register;
Expand Down Expand Up @@ -292,6 +302,9 @@ private async Task<ICategory> GetFloatCategory(XmlNode xmlNode)
string unit = string.Empty;
Representation representation = Representation.PureNumber;
XmlNode pNode;
IPValue pMin = null;
IPValue pMax = null;

foreach (XmlNode node in xmlNode.ChildNodes)
{
switch (node.Name)
Expand All @@ -309,11 +322,19 @@ private async Task<ICategory> GetFloatCategory(XmlNode xmlNode)
break;

case NodePMin:
pNode = ReadPNode(node.InnerText);
if (pNode != null)
{
pMin = await PNodeToPValue(pNode);
}

break;

case NodePMax:
pNode = ReadPNode(node.InnerText);
if (pNode != null)
{
expressions.Add(node.Name, await GetFormula(pNode));
pMax = await PNodeToPValue(pNode);
}

break;
Expand All @@ -338,6 +359,8 @@ private async Task<ICategory> GetFloatCategory(XmlNode xmlNode)
{
var register = await GetRegisterByName(pNode.Attributes["Name"].Value).ConfigureAwait(false);
pValue = register.pValue;
pMin = register.minPValue;
pMax = register.maxPValue;
}
}

Expand All @@ -356,7 +379,7 @@ private async Task<ICategory> GetFloatCategory(XmlNode xmlNode)
}
}

return new GenFloat(categoryPropreties, min, max, inc, IncrementMode.fixedIncrement, representation, value, unit, pValue);
return new GenFloat(categoryPropreties, min, max, pMin, pMax, inc, IncrementMode.fixedIncrement, representation, value, unit, pValue);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -587,6 +610,40 @@ private async Task<ICategory> GetIntegerCategory(XmlNode xmlNode)
throw new GenICamException($"Failed to get Integer Category by the given node {xmlNode.Name}", ex);
}
}

private async Task<GenCategory> ReadPMaxAndPmin(XmlNode xmlNode)
{
try
{
IPValue pMax = null;
IPValue pMin = null;

foreach (XmlNode node in xmlNode.ChildNodes)
{
switch (node.Name)
{
case NodePMin:
var pNode = ReadPNode(node.InnerText);
pMin = await PNodeToPValue(pNode);

break;
case NodePMax:
pNode = ReadPNode(node.InnerText);
pMax = await PNodeToPValue(pNode);
break;

default:
break;
}
}

return new GenCategory(null, null, pMin, pMax);
}
catch (Exception ex)
{
throw new GenICamException($"Failed to get Integer Category by the given node {xmlNode.Name}", ex);
}
}

private async Task<IPValue> PNodeToPValue(XmlNode pNode)
{
Expand Down
5 changes: 4 additions & 1 deletion GigeVision.Core/Services/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ public int ReceiveTimeoutInMilliseconds
set
{
Gvcp.ReceiveTimeoutInMilliseconds = value;
StreamReceiver.ReceiveTimeoutInMilliseconds = value;
if (StreamReceiver != null)
{
StreamReceiver.ReceiveTimeoutInMilliseconds = value;
}

OnPropertyChanged(nameof(ReceiveTimeoutInMilliseconds));
}
Expand Down
5 changes: 4 additions & 1 deletion GigeVision.Core/Services/Gvcp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ public async Task<List<CameraInformation>> GetAllGigeDevicesInNetworkAsnyc(strin
public async Task<(IPValue pValue, IRegister register)> GetRegister(string name)
{
(IPValue pValue, IRegister register) tuple = new(null, null);
return await xmlHelper.GetRegisterByName(name);
var extendedTuple = await xmlHelper.GetRegisterByName(name);
tuple.register = extendedTuple.register;
tuple.pValue = extendedTuple.pValue;
return tuple;
}

/// <summary>
Expand Down