82 lines
1.9 KiB
C#
82 lines
1.9 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using TBF.BenchControl.Network.Telnet;
|
|
|
|
namespace TBF.BenchControl.Network.Camera.CLP1611
|
|
{
|
|
public class MeasurementOp : IOperation
|
|
{
|
|
readonly CLP1611.Camera camera;
|
|
readonly CLP1611.CameraCfg cameraCfg;
|
|
readonly Telnet.TelnetClient telnet;
|
|
|
|
readonly string ipAddress;
|
|
readonly int portNr;
|
|
readonly IList<string> roiParams;
|
|
|
|
string command;
|
|
bool measurementCommandSent;
|
|
|
|
|
|
/// <summary>
|
|
/// Events: Event.None or Event.Error
|
|
/// </summary>
|
|
/// <param name="camera">CLP1611.Camera reference</param>
|
|
public MeasurementOp(Camera camera, string ipAddress, int portNr, IList<string> roiParams)
|
|
{
|
|
this.camera = camera;
|
|
this.cameraCfg = camera.CameraCfg;
|
|
this.telnet = camera.Telnet;
|
|
this.ipAddress = ipAddress;
|
|
this.portNr = portNr;
|
|
this.roiParams = roiParams;
|
|
|
|
measurementCommandSent = false;
|
|
}
|
|
|
|
|
|
public void Start()
|
|
{
|
|
measurementCommandSent = false;
|
|
}
|
|
|
|
public Event Run()
|
|
{
|
|
if (!measurementCommandSent)
|
|
{
|
|
if (telnet.State == TelnetClient.TelnetState.Inactive)
|
|
{
|
|
//
|
|
// Prepare and send (=enqueue) command
|
|
//
|
|
StringBuilder sb = new StringBuilder();
|
|
foreach (var s in roiParams)
|
|
{
|
|
sb.Append(" ");
|
|
sb.Append(s);
|
|
}
|
|
command = string.Format("clp/Measurement -udp {0} {1}{2}{3} 1 1 0 0 0",
|
|
ipAddress,
|
|
portNr,
|
|
cameraCfg.UseTestImages ? (" -l " + cameraCfg.TestImagesCount.ToString()) : string.Empty,
|
|
sb);
|
|
telnet.Enqueue(new Telnet.Command(Telnet.CmdAction.SEND_STRING, command));
|
|
measurementCommandSent = true;
|
|
}
|
|
}
|
|
return Event.None;
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
if (measurementCommandSent)
|
|
{
|
|
telnet.Enqueue(new Telnet.Command(Telnet.CmdAction.SEND_COMMAND, Telnet.TelnetClient.CtrlCCommand));
|
|
}
|
|
}
|
|
}
|
|
}
|