(1) StandardCamera.TestStartEndForm fixed (exclamation), (2) Simulate mode for camera with sample.bmp.

This commit is contained in:
Milan Hanajik 2019-09-21 15:08:39 +02:00
parent 688580c29f
commit 4fc427d875
6 changed files with 120 additions and 74 deletions

View File

@ -471,17 +471,20 @@ namespace TBF.BenchControl.DataEntry.StandardCamera
///
void UpdateExclamation(int uiCtrlPos) /// uiCtrlPos = 0 .. TextBoxesCount-1
{
try
{
double startVolumeLtr = Utils.ParseUDouble(startTextBoxes[uiCtrlPos].Text) * regReaders[phys2wm[uiCtrlPos] - 1].LtrsPerPulse;
double endVolumeLtr = Utils.ParseUDouble(endTextBoxes[uiCtrlPos].Text) * regReaders[phys2wm[uiCtrlPos] - 1].LtrsPerPulse;
double err = 100.0 * (endVolumeLtr - startVolumeLtr - refVolume) / refVolume;
exclamations[uiCtrlPos].Visible = (err < warningLimLo) || (err > warningLimHi);
}
catch
{
exclamations[uiCtrlPos].Visible = false;
}
if ((mode == Tst.End) || (mode == Tst.Both))
{
try
{
double startVolumeLtr = Utils.ParseUDouble(startTextBoxes[uiCtrlPos].Text) * regReaders[phys2wm[uiCtrlPos] - 1].LtrsPerPulse;
double endVolumeLtr = Utils.ParseUDouble(endTextBoxes[uiCtrlPos].Text) * regReaders[phys2wm[uiCtrlPos] - 1].LtrsPerPulse;
double err = 100.0 * (endVolumeLtr - startVolumeLtr - refVolume) / refVolume;
exclamations[uiCtrlPos].Visible = (err < warningLimLo) || (warningLimHi < err);
}
catch
{
exclamations[uiCtrlPos].Visible = false;
}
}
}

View File

@ -32,9 +32,9 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
this.GetType().Namespace.Substring(17),
CameraCfg.Name,
CameraCfg.HardwareAddress,
ipAddress == null ? "not detected" : ipAddress.ToString(),
string.IsNullOrEmpty(cpuSerialNr) ? "not detected" : cpuSerialNr,
string.IsNullOrEmpty(sdCardVer) ? "not detected" : sdCardVer);
CameraCfg.DebugLevel == DebugMode.Simulate ? "simulated" : ((ipAddress == null) ? "not detected" : ipAddress.ToString()),
CameraCfg.DebugLevel == DebugMode.Simulate ? "simulated" : (string.IsNullOrEmpty(cpuSerialNr) ? "not detected" : cpuSerialNr),
CameraCfg.DebugLevel == DebugMode.Simulate ? "simulated" : (string.IsNullOrEmpty(sdCardVer) ? "not detected" : sdCardVer));
}
@ -161,13 +161,16 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
{
cameraIdx = GetCameraIdx();
if (CameraCfg.DebugLevel == DebugMode.Simulate) return;
if (CameraCfg.DebugLevel == DebugMode.Simulate)
{
UiBridge.Bridge.OnCameraInfo(this.cameraIdx, string.Format("{0} s/n {1} si simulated", Name, CameraCfg.HardwareAddress));
return;
}
/// Detect a camera
bool cameraDetected = DetectCamera(CameraCfg.HardwareAddress % 100, ref ipAddress, true,
out cpuHardware, out cpuRevision, out cpuSerialNr, out sdCardVer);
if (CameraCfg.DebugLevel == DebugMode.AutoDetect)
{
CameraCfg.DebugLevel = cameraDetected ? DebugMode.DetectedOn : DebugMode.DetectedOff;
@ -219,46 +222,55 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
public void StopDevice()
{
running = false;
if ((CameraCfg.DebugLevel != DebugMode.Simulate) && (CameraCfg.DebugLevel != DebugMode.DetectedOff))
{
running = false;
stopScpThreadFlag = true;
stopRtpListenerFlag = true;
stopMsrmntListenerFlag = true;
stopScpThreadFlag = true;
stopRtpListenerFlag = true;
stopMsrmntListenerFlag = true;
if (Telnet != null)
{
Telnet.Dispose();
Telnet = null;
}
if (Telnet != null)
{
Telnet.Dispose();
Telnet = null;
}
}
}
public void StopDevice2()
{
if (scpThread != null) scpThread.Join(50);
if (rtpListenerThread != null) rtpListenerThread.Join(50);
if (msrmntListenerThread != null) msrmntListenerThread.Join(50);
if ((CameraCfg.DebugLevel != DebugMode.Simulate) && (CameraCfg.DebugLevel != DebugMode.DetectedOff))
{
if (scpThread != null) scpThread.Join(50);
if (rtpListenerThread != null) rtpListenerThread.Join(50);
if (msrmntListenerThread != null) msrmntListenerThread.Join(50);
if (rtpUdpClient != null)
{
rtpUdpClient.Close();
rtpUdpClient = null;
}
if (rtpUdpClient != null)
{
rtpUdpClient.Close();
rtpUdpClient = null;
}
if (msrmntUdpClient != null)
{
msrmntUdpClient.Close();
msrmntUdpClient = null;
}
if (msrmntUdpClient != null)
{
msrmntUdpClient.Close();
msrmntUdpClient = null;
}
}
}
public void RunDeviceBefore()
{
if (sha1sumResponse != null && !sha1sumResponseProcessed)
{
scpThread = new Thread(new ThreadStart(ScpWorker));
scpThread.Start();
sha1sumResponseProcessed = true;
if ((CameraCfg.DebugLevel != DebugMode.Simulate) && (CameraCfg.DebugLevel != DebugMode.DetectedOff))
{
if (sha1sumResponse != null && !sha1sumResponseProcessed)
{
scpThread = new Thread(new ThreadStart(ScpWorker));
scpThread.Start();
sha1sumResponseProcessed = true;
}
}
}
public void RunDeviceAfter() { }

View File

@ -50,10 +50,13 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
grabImageCommandSent = false;
transferringGrabbedImage = false;
telnet.promptReceivedHandler += delegate(object sndr, PromptReceivedEventArgs a)
{
OnPromptReceived(sndr, a);
};
if (camera.DebugLevel == DebugMode.Normal || camera.DebugLevel == DebugMode.DetectedOn)
{
telnet.promptReceivedHandler += delegate(object sndr, PromptReceivedEventArgs a)
{
OnPromptReceived(sndr, a);
};
}
}
void OnPromptReceived(object sndr, PromptReceivedEventArgs a)
@ -65,33 +68,58 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
public void Start()
{
if (camera.CameraCfg.DebugLevel == Config.Entities.DebugMode.Simulate) return;
grabImageCommandSent = false;
transferringGrabbedImage = false;
if (File.Exists(imgFileNames[0])) File.Delete(imgFileNames[0]);
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 == Config.Entities.DebugMode.Simulate || camera.CameraCfg.DebugLevel == Config.Entities.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 (camera.CameraCfg.DebugLevel == Config.Entities.DebugMode.Simulate) return Event.None;
if (imgFileNames.Length < 1 || imgFileNames[0] == null)
if ((imgFileNames == null) || (imgFileNames.Length < 1) || (imgFileNames[0] == null))
{
return Event.GrabPassed;
///
/// No images to be grabbed => Done
///
return Event.GrabPassed;
}
else if (!grabImageCommandSent)
else if (camera.CameraCfg.DebugLevel == Config.Entities.DebugMode.Simulate ||
camera.CameraCfg.DebugLevel == Config.Entities.DebugMode.DetectedOff)
{
///
/// Camera is in simulation mode => create a simulated image and complete
///
return Event.GrabPassed;
}
else if (!grabImageCommandSent)
{
///
/// Normal operation, no command sent yet => (1) wait until telnet state = Inactive, (2) send a command
///
if (camera.Running && (telnet.State == TelnetClient.TelnetState.Inactive))
{
//
// State variables
//
///
/// State variables
///
response = null;
//
// Prepare command
//
///
/// Prepare a command
///
int rotation = 0;
if (imageRotation == ImageRotation.Deg90)
rotation = 90;
@ -119,7 +147,10 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
}
else if (grabPassed)
{
if (transferringGrabbedImage)
///
/// Normal operation, grab passed => transfer/transferring the image
///
if (transferringGrabbedImage)
{
/// Grab passed and image transfer is in progress
return Event.GrabPassed;
@ -138,12 +169,17 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
}
else if (grabFailed)
{
/// Grab failed, there in no image to transfer
///
/// Normal operation, grab failed => there in no image to transfer
///
return Event.GrabFailed;
}
else if (response != null)
{
if (response.Contains("completed"))
///
/// Normal operation
///
if (response.Contains("completed"))
{
grabPassed = true;

View File

@ -127,17 +127,11 @@ namespace TBF.BenchControl.Network.Camera.RoiForFixedStart
public IOperation GrabImageOp(string imageFileName)
{
if (NetCamera != null)
{
/// TODO: Implement support for sharing one camera by multiple ROI-s
return NetCamera.GrabImagesOp(new string[] { imageFileName }, roiCfg.BlackAndWhite, roiCfg.LowResolution, roiCfg.ImageRotation);
}
else
return null;
return GrabImageOp(imageFileName, roiCfg.BlackAndWhite, roiCfg.LowResolution, roiCfg.ImageRotation);
}
public IOperation GrabImageOp(string imageFileName, bool blackAndWhite,
bool lowResolution, Config.Entities.ImageRotation imageRotation)
public IOperation GrabImageOp(string imageFileName,
bool blackAndWhite, bool lowResolution, Config.Entities.ImageRotation imageRotation)
{
if (NetCamera != null)
{

BIN
TBF/Pictures/sample.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 KiB

View File

@ -3362,6 +3362,7 @@
<Content Include="Pictures\reversed_dir_right.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Pictures\sample.bmp" />
<Content Include="Resources\empty.png" />
<Content Include="Resources\switch-off.png" />
<Content Include="Resources\switch-on.png" />