MeasurementOp moved to camera
This commit is contained in:
@@ -60,6 +60,18 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
|
||||
private TerminalDlg terminalDlg;
|
||||
|
||||
|
||||
///
|
||||
/// UDP Port number for 'MeasurementOp'
|
||||
///
|
||||
const int UdpPortRangeStart = 49152;
|
||||
const int UdpPortRangeEnd = 65535;
|
||||
static int nextUdpPortNr = UdpPortRangeStart;
|
||||
public static int GetNextUdpPortNr() { return nextUdpPortNr++; }
|
||||
///
|
||||
readonly int measurementUdpPortNr;
|
||||
UdpClient measurementListener;
|
||||
|
||||
|
||||
public Camera() {}
|
||||
|
||||
public Camera(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
||||
@@ -72,6 +84,8 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
|
||||
Telnet = null;
|
||||
terminalDlg = null;
|
||||
|
||||
measurementUdpPortNr = GetNextUdpPortNr();
|
||||
|
||||
running = false;
|
||||
|
||||
log.Debug(this.ToString());
|
||||
@@ -99,6 +113,9 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
|
||||
|
||||
Telnet.Enqueue(new Telnet.Command(Network.Telnet.CmdAction.CONNECT, ipAddress.ToString(), 10, 30));
|
||||
|
||||
measurementListener = new UdpClient(new IPEndPoint(NetAdapter.IPAddress, measurementUdpPortNr));
|
||||
new Thread(new ThreadStart(MeasurementUdpListener)).Start();
|
||||
|
||||
running = true;
|
||||
|
||||
log.FatalFormat("Successfully initialized device {0}", ToString());
|
||||
@@ -125,6 +142,18 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
|
||||
}
|
||||
|
||||
|
||||
public IOperation MeasurementOp()
|
||||
{
|
||||
if (Telnet != null)
|
||||
{
|
||||
return new MeasurementOp(this, NetAdapter.IPAddress.ToString(), measurementUdpPortNr, string.Empty); /// TODO
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Detect the camera with specified hardware address (DIP switches)
|
||||
@@ -228,5 +257,32 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
|
||||
byte[] dataToSend = Encoding.ASCII.GetBytes(strToSend);
|
||||
udpClient.Send(dataToSend, dataToSend.Length, new IPEndPoint(NetAdapter.BroadcastAddress, 1852));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MeasurementUdpListener()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 0);
|
||||
byte[] byteArray = measurementListener.Receive(ref ipEndPoint);
|
||||
string receivedData = Encoding.ASCII.GetString(byteArray, 0, byteArray.Length);
|
||||
int from = receivedData.IndexOf('[');
|
||||
int to = receivedData.IndexOf(']');
|
||||
int locPulses;
|
||||
if (from >= 0 && to >= 0 && to > from &&
|
||||
int.TryParse(receivedData.Substring(from + 1, to - from - 1), out locPulses))
|
||||
{
|
||||
//wmPulses = locPulses;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
log.FatalFormat("Camera : MeasurementUdpListener() thread failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-17
@@ -1,10 +1,9 @@
|
||||
using TBF.BenchControl.Network.Telnet;
|
||||
|
||||
namespace TBF.BenchControl.Network.Camera.Roi
|
||||
namespace TBF.BenchControl.Network.Camera.CLP1611
|
||||
{
|
||||
public class MeasurementOp : IOperation
|
||||
{
|
||||
readonly Roi roi;
|
||||
readonly CLP1611.Camera camera;
|
||||
readonly Telnet.TelnetClient telnet;
|
||||
|
||||
@@ -15,29 +14,18 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
string command;
|
||||
bool measurementCommandSent;
|
||||
|
||||
readonly int roiX;
|
||||
readonly int roiY;
|
||||
readonly int roiWid;
|
||||
readonly int roiHgh;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Events: Event.None or Event.Error
|
||||
/// </summary>
|
||||
/// <param name="camera">CLP1611.Camera reference</param>
|
||||
public MeasurementOp(Roi roi, string ipAddress, int portNr, string args, int roiX, int roiY, int roiWid, int roiHgh)
|
||||
public MeasurementOp(Camera camera, string ipAddress, int portNr, string args)
|
||||
{
|
||||
this.roi = roi;
|
||||
this.camera = roi.NetCamera;
|
||||
this.telnet = roi.Telnet;
|
||||
this.camera = camera;
|
||||
this.telnet = camera.Telnet;
|
||||
this.ipAddress = ipAddress;
|
||||
this.portNr = portNr;
|
||||
this.args = args;
|
||||
this.roiX = roiX;
|
||||
this.roiY = roiY;
|
||||
this.roiWid = roiWid;
|
||||
this.roiHgh = roiHgh;
|
||||
|
||||
measurementCommandSent = false;
|
||||
}
|
||||
@@ -57,7 +45,8 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
//
|
||||
// Prepare and send (=enqueue) command
|
||||
//
|
||||
command = string.Format("clp/Measurement -roi {0} {1} {2} {3} -o {4}:{5} {6}", roiX, roiY, roiWid, roiHgh, ipAddress, portNr, args);
|
||||
command = string.Format("clp/Measurement -o {4}:{5} {6}", ipAddress, portNr, args);
|
||||
//command = string.Format("clp/Measurement -r {0} {1} {2} {3} -o {4}:{5} {6}", roiX, roiY, roiWid, roiHgh, ipAddress, portNr, args);
|
||||
telnet.Enqueue(new Telnet.Command(Telnet.CmdAction.SEND_STRING, command));
|
||||
measurementCommandSent = true;
|
||||
}
|
||||
@@ -3,10 +3,7 @@
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using log4net;
|
||||
using Config.Entities;
|
||||
|
||||
@@ -29,15 +26,6 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
public readonly Telnet.TelnetClient Telnet;
|
||||
public readonly Roi PreviousRoi;
|
||||
|
||||
///
|
||||
/// UDP Port number management
|
||||
///
|
||||
const int UdpPortRangeStart = 49152;
|
||||
const int UdpPortRangeEnd = 65535;
|
||||
protected static int NextUdpPortNr = UdpPortRangeStart;
|
||||
readonly int udpPortNr;
|
||||
UdpClient listener;
|
||||
|
||||
///
|
||||
/// ICamera interface functions
|
||||
///
|
||||
@@ -75,11 +63,6 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
NetCamera = TbfComponents.FindComponent(cfg.ParentName, components) as CLP1611.Camera;
|
||||
if (NetCamera != null) Telnet = NetCamera.Telnet;
|
||||
|
||||
udpPortNr = NextUdpPortNr++;
|
||||
|
||||
listener = new UdpClient(new IPEndPoint(IPAddress.Any, udpPortNr));
|
||||
new Thread(new ThreadStart(UdpListener)).Start();
|
||||
|
||||
PreviousRoi = TbfComponents.FindComponent(roiCfg.PreviousRoi, components) as Roi;
|
||||
|
||||
Detected = false;
|
||||
@@ -117,41 +100,7 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
|
||||
public IOperation MeasurementOp()
|
||||
{
|
||||
if (NetCamera != null && Telnet != null)
|
||||
{
|
||||
return new MeasurementOp(this, NetCamera.NetAdapter.IPAddress.ToString(), udpPortNr,
|
||||
roiCfg.Args, RoiX.Val, RoiY.Val, RoiWid.Val, RoiHgh.Val);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UdpListener()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 0);
|
||||
byte[] byteArray = listener.Receive(ref ipEndPoint);
|
||||
string receivedData = Encoding.ASCII.GetString(byteArray, 0, byteArray.Length);
|
||||
int from = receivedData.IndexOf('[');
|
||||
int to = receivedData.IndexOf(']');
|
||||
int locPulses;
|
||||
if (from >= 0 && to >= 0 && to > from &&
|
||||
int.TryParse(receivedData.Substring(from + 1, to - from - 1), out locPulses))
|
||||
{
|
||||
wmPulses = locPulses;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
log.FatalFormat("Roi : UdpListener() thread failed");
|
||||
}
|
||||
return null; /// TODO: To be implemented in a Camera
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user