- Extended CJMS11 camera handling with new functionalities, including image grabbing, resolution configuration, and improved ROI support. - Added new `ToString` method implementations for enhanced debugging and logging in key classes like `JmsMessage`, `JmsPacket`, and `RoiCfg`. - Introduced additional commands (`start_stream_images`, `stop_stream_images`) in `CommandM` and its enum. - Implemented new resolution handling in `RoiCfg` with support for configurable image frames. - Refactored resolution-related UI elements in `RoiCfgCtrl` to add a dropdown for selecting resolution. - Made minor UX improvements by replacing inconsistent string formats with verbatim strings in console messages. - Updated project dependencies with new resolution-related utilities (`Frame` and `ResolutionFrames`). - Resolved camera-specific symbolic issues by transitioning to `CJMS11.Camera` over prior naming inconsistencies.
179 lines
5.2 KiB
C#
179 lines
5.2 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using log4net;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Network.Telnet;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace TBF.Rig.Network.Camera.CJMS11
|
|
{
|
|
public class GrabImagesOp : IOperation
|
|
{
|
|
/// TODO: Implement support for grabbing multiple images, now imgFileNames.Lenght should be 1
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(GrabImagesOp));
|
|
public override string ToString() { return string.Format("GrabImageOp()"); }
|
|
|
|
readonly Camera camera;
|
|
|
|
readonly string[] imgFileNames;
|
|
readonly bool blackAndWhite;
|
|
readonly bool lowResolution;
|
|
readonly ImageRotation imageRotation;
|
|
|
|
string command;
|
|
bool grabImageCommandSent;
|
|
string response;
|
|
bool grabPassed;
|
|
bool grabFailed;
|
|
bool transferringGrabbedImage;
|
|
|
|
Image grabedImage;
|
|
|
|
|
|
/// <summary>
|
|
/// Events: Event.None or Event.Error
|
|
/// </summary>
|
|
/// <param name="camera">CLP1611.Camera reference</param>
|
|
public GrabImagesOp(Camera camera, string[] imgFileNames, bool blackAndWhite, bool lowResolution, ImageRotation imageRotation)
|
|
{
|
|
/// TODO: Implement support for grabbing multiple images, now imgFileNames.Lenght should be 1
|
|
|
|
this.camera = camera;
|
|
//this.telnet = camera.Telnet;
|
|
this.imgFileNames = imgFileNames;
|
|
this.blackAndWhite = blackAndWhite;
|
|
this.lowResolution = lowResolution;
|
|
this.imageRotation = imageRotation;
|
|
|
|
grabImageCommandSent = false;
|
|
transferringGrabbedImage = false;
|
|
|
|
if (camera.DebugLevel == DebugMode.Normal || camera.DebugLevel == DebugMode.DetectedOn)
|
|
{
|
|
Camera.ImageCameraHandler += ImageReceived;
|
|
}
|
|
//TODO BUMI improve by simulate image
|
|
Camera.ImageCameraHandler += ImageReceived;
|
|
}
|
|
|
|
void PromptReceived(object sndr, PromptReceivedJMSEventArgs a)
|
|
{
|
|
response = a.Response;
|
|
}
|
|
|
|
void ImageReceived(object sndr, PromptReceivedImageEventArgs a)
|
|
{
|
|
if(a.idxCamera != camera.CameraIdx) return;
|
|
grabedImage = a.image;
|
|
grabPassed = true;
|
|
}
|
|
|
|
|
|
public void Start()
|
|
{
|
|
grabImageCommandSent = false;
|
|
transferringGrabbedImage = false;
|
|
grabPassed = false;
|
|
grabedImage = null;
|
|
|
|
if ((imgFileNames != null) && (imgFileNames.Length > 0) && File.Exists(imgFileNames[0]))
|
|
{
|
|
///
|
|
/// An image specified, (1) delete previous image, (2) check if this is a simulation
|
|
///
|
|
File.Delete(imgFileNames[0]);
|
|
|
|
/* if (camera.CameraCfg.DebugLevel == DebugMode.Simulate || camera.CameraCfg.DebugLevel == DebugMode.DetectedOff)
|
|
{
|
|
///
|
|
/// Camera is in simulation mode => create a simulated image
|
|
///
|
|
File.Copy(string.Format("{0}\\Pictures\\sample.jpg", Program.ExecutableDir), imgFileNames[0]);
|
|
}*/
|
|
}
|
|
}
|
|
|
|
public Event Run()
|
|
{
|
|
if ((imgFileNames == null) || (imgFileNames.Length < 1) || (imgFileNames[0] == null))
|
|
{
|
|
///
|
|
/// No images to be grabbed => Done
|
|
///
|
|
return Event.GrabPassed;
|
|
}
|
|
/*else if (camera.CameraCfg.DebugLevel == DebugMode.Simulate ||
|
|
camera.CameraCfg.DebugLevel == DebugMode.DetectedOff)
|
|
{
|
|
///
|
|
/// Camera is in simulation mode => create a simulated image and complete
|
|
///
|
|
return Event.GrabPassed;
|
|
}*/
|
|
else if (camera.IsGrabImageListenerThreadAlive)
|
|
{
|
|
return Event.CameraBusy;
|
|
}
|
|
else if (!grabImageCommandSent)
|
|
{
|
|
///
|
|
/// Normal operation, no command sent yet => (1) wait until telnet state = Inactive, (2) send a command
|
|
///
|
|
camera.StartGrabImageListener();
|
|
grabImageCommandSent = true;
|
|
return Event.CameraBusy;
|
|
}
|
|
else if (grabPassed)
|
|
{
|
|
///
|
|
/// Normal operation, grab passed => transfer/transferring the image
|
|
|
|
|
|
if (transferringGrabbedImage)
|
|
{
|
|
/// Grab passed and image transfer is in progress
|
|
return Event.GrabPassed;
|
|
}
|
|
else if (camera.IsSaveImageListenerThreadAlive)
|
|
{
|
|
/// Wait until the previous image transfer completes
|
|
return Event.CameraBusy;
|
|
}
|
|
else //if (0 == camera.DownloadFile(blackAndWhite ? "grabbed.jpg" : "grabbed.bmp", imgFileNames[0]))
|
|
{
|
|
camera.StartSaveImageToFileListener(grabedImage, imgFileNames[0]);
|
|
/// File transfer successfully started
|
|
transferringGrabbedImage = true;
|
|
return Event.GrabPassed;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
///
|
|
/// Normal operation, grab failed => there in no image to transfer
|
|
///
|
|
return Event.GrabFailed;
|
|
}
|
|
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
//if (camera.CameraCfg.DebugLevel == DebugMode.Simulate) return;
|
|
|
|
if (camera.IsGrabImageListenerThreadAlive)
|
|
{
|
|
camera.SetStopGrabImageListenerFlag();
|
|
}
|
|
}
|
|
}
|
|
}
|