IDS camera added
This commit is contained in:
@@ -19,9 +19,9 @@ public class EmulationSettings : ISettings
|
|||||||
|
|
||||||
public void RegisterSettings(InspectronSettings settings)
|
public void RegisterSettings(InspectronSettings settings)
|
||||||
{
|
{
|
||||||
settings.RegisterSimple(this, () => CycleDelay, CameraName+"/Emulation", nameof(CycleDelay));
|
settings.RegisterSimple(this, () => CycleDelay, CameraName+"/Sources/Emulation", nameof(CycleDelay));
|
||||||
settings.RegisterSimple(this, () => PerImageDelay, CameraName + "/Emulation", nameof(PerImageDelay));
|
settings.RegisterSimple(this, () => PerImageDelay, CameraName + "/Sources/Emulation", nameof(PerImageDelay));
|
||||||
settings.RegisterSimple(this, () => SingleRun, CameraName + "/Emulation", nameof(SingleRun));
|
settings.RegisterSimple(this, () => SingleRun, CameraName + "/Sources/Emulation", nameof(SingleRun));
|
||||||
settings.RegisterSimple(this, () => EmulationPath, CameraName + "/Emulation", nameof(EmulationPath));
|
settings.RegisterSimple(this, () => EmulationPath, CameraName + "/Sources/Emulation", nameof(EmulationPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\VisionBuilder.UI.Common\VisionBuilder.UI.Common.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="uEyeDotNet">
|
||||||
|
<HintPath>uEyeDotNet.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
228
Hawkeye.VisionBuilder.UI.Sources.IDS/IDSImageSource.cs
Normal file
228
Hawkeye.VisionBuilder.UI.Sources.IDS/IDSImageSource.cs
Normal file
@@ -0,0 +1,228 @@
|
|||||||
|
using OpenCvSharp;
|
||||||
|
using Serilog;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Channels;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using uEye.Defines;
|
||||||
|
using VisionBuilder.UI.Common;
|
||||||
|
using VisionBuilder.UI.Common.RecipeProcessing;
|
||||||
|
using Point = System.Drawing.Point;
|
||||||
|
|
||||||
|
namespace Inspectron.Camera.UEye
|
||||||
|
{
|
||||||
|
|
||||||
|
public class IDSImageSource : IImageSource, IVisionBuilderModule
|
||||||
|
{
|
||||||
|
private readonly IDSImageSourceSettings _settings;
|
||||||
|
private uEye.Camera _camera = null;
|
||||||
|
|
||||||
|
|
||||||
|
int cameraIdx;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public IDSImageSource(IDSImageSourceSettings settings)
|
||||||
|
{
|
||||||
|
_settings = settings;
|
||||||
|
_camera = new uEye.Camera();
|
||||||
|
cameraIdx = _settings.CameraId;
|
||||||
|
System.AppDomain.CurrentDomain.ProcessExit += AppDomain_ProcessExit;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AppDomain_ProcessExit(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Mat MemoryToImage(int idx)
|
||||||
|
{
|
||||||
|
uEye.Defines.ColorMode mode;
|
||||||
|
_camera.PixelFormat.Get(out mode);
|
||||||
|
int channels = 0;
|
||||||
|
|
||||||
|
if (mode == uEye.Defines.ColorMode.Mono8)
|
||||||
|
{
|
||||||
|
channels = 1;
|
||||||
|
}
|
||||||
|
else if (mode == uEye.Defines.ColorMode.BGR8Packed || mode == uEye.Defines.ColorMode.RGB8Packed)
|
||||||
|
{
|
||||||
|
channels = 3;
|
||||||
|
}
|
||||||
|
else if (mode == uEye.Defines.ColorMode.BGRA8Packed)
|
||||||
|
{
|
||||||
|
channels = 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("unknown image format");
|
||||||
|
}
|
||||||
|
|
||||||
|
var size = new uEye.Types.Size<int>();
|
||||||
|
_camera.Memory.GetSize(idx, out size);
|
||||||
|
int pitch;
|
||||||
|
_camera.Memory.GetPitch(idx, out pitch);
|
||||||
|
|
||||||
|
Byte[] u8img;
|
||||||
|
_camera.Memory.CopyToArray(idx, out u8img);
|
||||||
|
//Console.WriteLine($"Image size: {size.Width}x{size.Height}, channels: {channels}({mode}), data size: {u8img.Length}, pitch: {pitch}");
|
||||||
|
//Console.ReadLine();
|
||||||
|
Mat mat = new Mat(size.Height,pitch, MatType.CV_8UC(channels));
|
||||||
|
mat.SetArray(u8img);
|
||||||
|
return mat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Open()
|
||||||
|
{
|
||||||
|
if (_camera.IsOpened)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uEye.Defines.Status statusRet = 0;
|
||||||
|
|
||||||
|
// Open _camera
|
||||||
|
statusRet = _camera.Init(cameraIdx);
|
||||||
|
if (statusRet != uEye.Defines.Status.Success)
|
||||||
|
{
|
||||||
|
throw new Exception("_camera initializing failed: "+statusRet);
|
||||||
|
}
|
||||||
|
uEye.Types.SensorInfo info = new uEye.Types.SensorInfo();
|
||||||
|
_camera.Information.GetSensorInfo(out info);
|
||||||
|
Console.WriteLine($"Camera {cameraIdx} opened: {info.SensorName} ({info.SensorID})");
|
||||||
|
_camera.Parameter.Load();
|
||||||
|
Console.WriteLine($"Camera {cameraIdx} parameters loaded");
|
||||||
|
|
||||||
|
_camera.Trigger.Set(uEye.Defines.TriggerMode.Continuous);
|
||||||
|
|
||||||
|
statusRet = _camera.Memory.Allocate();
|
||||||
|
Console.WriteLine("Memory allocated");
|
||||||
|
if (statusRet != uEye.Defines.Status.Success)
|
||||||
|
{
|
||||||
|
throw new Exception("Allocate Memory failed");
|
||||||
|
|
||||||
|
}
|
||||||
|
_camera.EventFrame += onFrameEvent;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_camera.Device.Feature.ShutterMode.Set(uEye.Defines.Shuttermode.Global);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
if (!_camera.IsOpened)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uEye.Defines.Status statusRet;
|
||||||
|
statusRet = _camera.Exit();
|
||||||
|
|
||||||
|
if (statusRet != uEye.Defines.Status.Success)
|
||||||
|
{
|
||||||
|
throw new Exception("failed to close camera");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void LoadParameters(string parameters_file)
|
||||||
|
{
|
||||||
|
uEye.Defines.Status statusRet = 0;
|
||||||
|
|
||||||
|
Int32[] memList;
|
||||||
|
statusRet = _camera.Memory.GetList(out memList);
|
||||||
|
if (statusRet != uEye.Defines.Status.Success)
|
||||||
|
{
|
||||||
|
throw new Exception("Get memory list failed: " + statusRet);
|
||||||
|
}
|
||||||
|
|
||||||
|
statusRet = _camera.Memory.Free(memList);
|
||||||
|
if (statusRet != uEye.Defines.Status.Success)
|
||||||
|
{
|
||||||
|
throw new Exception("Free memory list failed: " + statusRet);
|
||||||
|
}
|
||||||
|
|
||||||
|
statusRet = _camera.Parameter.Load(parameters_file);
|
||||||
|
if (statusRet != uEye.Defines.Status.Success)
|
||||||
|
{
|
||||||
|
throw new Exception("Loading parameter failed: " + statusRet);
|
||||||
|
}
|
||||||
|
|
||||||
|
uEye.Types.Size<int> t = new uEye.Types.Size<int>();
|
||||||
|
|
||||||
|
|
||||||
|
statusRet = _camera.Memory.Allocate();
|
||||||
|
if (statusRet != uEye.Defines.Status.SUCCESS)
|
||||||
|
{
|
||||||
|
throw new Exception("Allocate Memory failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveParameters(string parameters_file)
|
||||||
|
{
|
||||||
|
uEye.Defines.Status statusRet = 0;
|
||||||
|
|
||||||
|
statusRet = _camera.Parameter.Save(parameters_file);
|
||||||
|
if (statusRet != uEye.Defines.Status.SUCCESS)
|
||||||
|
{
|
||||||
|
throw new Exception("failed to save Parameters");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void onFrameEvent(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uEye.Camera camera = sender as uEye.Camera;
|
||||||
|
int s32MemId;
|
||||||
|
int active = (int)camera.Memory.GetActive(out s32MemId);
|
||||||
|
int num1 = (int)camera.Memory.Lock(s32MemId);
|
||||||
|
var image = this.MemoryToImage(s32MemId);
|
||||||
|
int num2 = (int)camera.Memory.Unlock(s32MemId);
|
||||||
|
|
||||||
|
if (!_channel.Writer.TryWrite(image))
|
||||||
|
{
|
||||||
|
Log.Warning("Image channel is full, dropping image");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (TaskCanceledException ex)
|
||||||
|
{
|
||||||
|
int num = (int)(sender as uEye.Camera).Acquisition.Stop();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private Channel<Mat> _channel = Channel.CreateBounded<Mat>(new BoundedChannelOptions(1)
|
||||||
|
{
|
||||||
|
FullMode = BoundedChannelFullMode.DropOldest,
|
||||||
|
SingleReader = true,
|
||||||
|
SingleWriter = true,
|
||||||
|
AllowSynchronousContinuations = true
|
||||||
|
});
|
||||||
|
public async Task<Mat> GetImage(CancellationToken token)
|
||||||
|
{
|
||||||
|
return await _channel.Reader.ReadAsync(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InitializeModule()
|
||||||
|
{
|
||||||
|
Open();
|
||||||
|
if(!(string.IsNullOrEmpty(_settings.CameraFile)))
|
||||||
|
LoadParameters(_settings.CameraFile);
|
||||||
|
_camera.Trigger.Set(uEye.Defines.TriggerMode.Continuous);
|
||||||
|
_camera.Acquisition.Capture();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using System.Text;
|
||||||
|
using Inspectron.Settings;
|
||||||
|
using Inspectron.Settings.Attributes;
|
||||||
|
using VisionBuilder.UI.Common;
|
||||||
|
|
||||||
|
namespace Inspectron.Camera.UEye;
|
||||||
|
|
||||||
|
public class IDSImageSourceSettings:ISettings
|
||||||
|
{
|
||||||
|
public string CameraName { get; }
|
||||||
|
|
||||||
|
public IDSImageSourceSettings(string cameraName)
|
||||||
|
{
|
||||||
|
CameraName = cameraName;
|
||||||
|
}
|
||||||
|
|
||||||
|
[SettingPreview(typeof(IDSImageSourceSettings), nameof(CameraIdsPreview))]
|
||||||
|
public int CameraId { get; set; } = 0;
|
||||||
|
|
||||||
|
[File("*.ini")] public string CameraFile { get; set; } = "";
|
||||||
|
|
||||||
|
public void RegisterSettings(InspectronSettings settings)
|
||||||
|
{
|
||||||
|
settings.RegisterSimple(this, () => CameraId, $"{CameraName}/Sources/IDS", nameof(CameraId));
|
||||||
|
settings.RegisterSimple(this, () => CameraFile, $"{CameraName}/Sources/IDS", nameof(CameraFile));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string CameraIdsPreview(int _)
|
||||||
|
{
|
||||||
|
uEye.Info.Camera.GetCameraList(out var cameraList);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
foreach (var camera in cameraList)
|
||||||
|
{
|
||||||
|
sb.AppendLine($"Camera ID: {camera.CameraID}, Name: {camera.SerialNumber}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
Hawkeye.VisionBuilder.UI.Sources.IDS/uEyeDotNet.dll
Normal file
BIN
Hawkeye.VisionBuilder.UI.Sources.IDS/uEyeDotNet.dll
Normal file
Binary file not shown.
19
IDSTest/IDSTest.csproj
Normal file
19
IDSTest/IDSTest.csproj
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="OpenCvSharp4" Version="4.11.0.20250507" />
|
||||||
|
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.11.0.20250507" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Hawkeye.VisionBuilder.UI.Sources.IDS\Hawkeye.VisionBuilder.UI.Sources.IDS.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
13
IDSTest/Program.cs
Normal file
13
IDSTest/Program.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using Inspectron.Camera.UEye;
|
||||||
|
|
||||||
|
IDSImageSource imageSource = new IDSImageSource();
|
||||||
|
|
||||||
|
Console.WriteLine("Opening");
|
||||||
|
imageSource.InitializeModule();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Getting image");
|
||||||
|
var image=imageSource.GetImage(CancellationToken.None).Result;
|
||||||
|
image.SaveImage("test.png");
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Hawkeye.VisionBuilder.UI.Sources.Emulation;
|
using Hawkeye.VisionBuilder.UI.Sources.Emulation;
|
||||||
|
using Inspectron.Camera.UEye;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using Ninject.Extensions.ChildKernel;
|
using Ninject.Extensions.ChildKernel;
|
||||||
using VisionBuilder.UI.Common;
|
using VisionBuilder.UI.Common;
|
||||||
@@ -12,6 +13,7 @@ public static class ModuleExtensions
|
|||||||
{
|
{
|
||||||
self.Bind<CameraSettings, ISettings>().ToConstant(new CameraSettings(cameraName));
|
self.Bind<CameraSettings, ISettings>().ToConstant(new CameraSettings(cameraName));
|
||||||
self.Bind<EmulationSettings, ISettings>().ToConstant(new EmulationSettings(cameraName));
|
self.Bind<EmulationSettings, ISettings>().ToConstant(new EmulationSettings(cameraName));
|
||||||
|
self.Bind<IDSImageSourceSettings, ISettings>().ToConstant(new IDSImageSourceSettings(cameraName));
|
||||||
self.Bind<SingleCameraVM>().ToSelf().InSingletonScope();
|
self.Bind<SingleCameraVM>().ToSelf().InSingletonScope();
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -26,6 +28,7 @@ public static class ModuleExtensions
|
|||||||
case CameraSettings.EImageSource.Hawkeye:
|
case CameraSettings.EImageSource.Hawkeye:
|
||||||
break;
|
break;
|
||||||
case CameraSettings.EImageSource.IDS:
|
case CameraSettings.EImageSource.IDS:
|
||||||
|
kernel.Bind<IImageSource, IVisionBuilderModule>().To<IDSImageSource>().InSingletonScope();
|
||||||
break;
|
break;
|
||||||
case CameraSettings.EImageSource.Basler:
|
case CameraSettings.EImageSource.Basler:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Hawkeye.VisionBuilder.UI.Sources.Emulation\Hawkeye.VisionBuilder.UI.Sources.Emulation.csproj" />
|
<ProjectReference Include="..\Hawkeye.VisionBuilder.UI.Sources.Emulation\Hawkeye.VisionBuilder.UI.Sources.Emulation.csproj" />
|
||||||
|
<ProjectReference Include="..\Hawkeye.VisionBuilder.UI.Sources.IDS\Hawkeye.VisionBuilder.UI.Sources.IDS.csproj" />
|
||||||
<ProjectReference Include="..\VisionBuilder.UI.Common\VisionBuilder.UI.Common.csproj" />
|
<ProjectReference Include="..\VisionBuilder.UI.Common\VisionBuilder.UI.Common.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -33,12 +33,13 @@ public static class Extensions
|
|||||||
{
|
{
|
||||||
if (service != null)
|
if (service != null)
|
||||||
{
|
{
|
||||||
|
Log.Information($"Initializing module {service.GetType().Name}");
|
||||||
service.InitializeModule();
|
service.InitializeModule();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Error($"Error initializing module {service.GetType().Name}: {e.Message}", e);
|
Log.Error($"Error initializing module {service.GetType().Name}: {e}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,5 @@ namespace VisionBuilder.UI.Common.RecipeProcessing;
|
|||||||
|
|
||||||
public interface IImageSource
|
public interface IImageSource
|
||||||
{
|
{
|
||||||
string GetName();
|
|
||||||
Task<Mat> GetImage(CancellationToken token);
|
Task<Mat> GetImage(CancellationToken token);
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,6 @@ public static class ModuleExtensions
|
|||||||
public static IKernel UseIOCommanderWindowsDebug(this IKernel self)
|
public static IKernel UseIOCommanderWindowsDebug(this IKernel self)
|
||||||
{
|
{
|
||||||
TypeDescriptor.AddAttributes(typeof(List<PinLabel>), new TypeConverterAttribute(typeof(PinLabelListConverter)));
|
TypeDescriptor.AddAttributes(typeof(List<PinLabel>), new TypeConverterAttribute(typeof(PinLabelListConverter)));
|
||||||
|
|
||||||
self.Rebind<IIOCommanderDebugViewService>().To<WindowsIOCommanderDebugViewService>().InSingletonScope();
|
self.Rebind<IIOCommanderDebugViewService>().To<WindowsIOCommanderDebugViewService>().InSingletonScope();
|
||||||
self.Bind<WindowsIOCommanderDebugViewSettings,ISettings>().ToConstant(new WindowsIOCommanderDebugViewSettings());
|
self.Bind<WindowsIOCommanderDebugViewSettings,ISettings>().ToConstant(new WindowsIOCommanderDebugViewSettings());
|
||||||
return self;
|
return self;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ public class IOCommander : IIOCommander
|
|||||||
SerialPort _port;
|
SerialPort _port;
|
||||||
public IOCommander(string COMPort)
|
public IOCommander(string COMPort)
|
||||||
{
|
{
|
||||||
|
|
||||||
_port = new SerialPort(COMPort);
|
_port = new SerialPort(COMPort);
|
||||||
_port.BaudRate = 57600;
|
_port.BaudRate = 57600;
|
||||||
_port.ReadTimeout = 100;
|
_port.ReadTimeout = 100;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class IOCommanderCameraModule: IVisionBuilderModule
|
|||||||
_recognitionControl.ImageProcessed += _recognitionControl_ImageProcessed;
|
_recognitionControl.ImageProcessed += _recognitionControl_ImageProcessed;
|
||||||
_recognitionControl.SessionStarted += _recognitionControl_SessionStarted;
|
_recognitionControl.SessionStarted += _recognitionControl_SessionStarted;
|
||||||
_recognitionControl.SessionEnded += _recognitionControl_SessionEnded;
|
_recognitionControl.SessionEnded += _recognitionControl_SessionEnded;
|
||||||
mainModule.OnPinChangedEvent += MainModule_OnPinChangedEvent;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ public class IOCommanderCameraModule: IVisionBuilderModule
|
|||||||
|
|
||||||
public void InitializeModule()
|
public void InitializeModule()
|
||||||
{
|
{
|
||||||
|
_mainModule.OnPinChangedEvent += MainModule_OnPinChangedEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _recognitionControl_SessionEnded(SessionEndedEvent obj)
|
private void _recognitionControl_SessionEnded(SessionEndedEvent obj)
|
||||||
|
|||||||
@@ -33,15 +33,12 @@ public class IOCommanderModule:IVisionBuilderModule
|
|||||||
|
|
||||||
}
|
}
|
||||||
ConcurrentDictionary<int, bool> _pinStates = new ConcurrentDictionary<int, bool>();
|
ConcurrentDictionary<int, bool> _pinStates = new ConcurrentDictionary<int, bool>();
|
||||||
public event Action<int, bool>? OnPinChangedEvent
|
public event Action<int, bool>? OnPinChangedEvent = delegate { };
|
||||||
{
|
|
||||||
add => _ioCommander!.OnPinChanged += value;
|
|
||||||
remove => _ioCommander!.OnPinChanged -= value;
|
|
||||||
}
|
|
||||||
private void OnPinChanged(int arg1, bool arg2)
|
private void OnPinChanged(int arg1, bool arg2)
|
||||||
{
|
{
|
||||||
_pinStates.TryAdd(arg1, arg2);
|
_pinStates.TryAdd(arg1, arg2);
|
||||||
_debugViewService.SetInputPinStatus(arg1, arg2);
|
_debugViewService.SetInputPinStatus(arg1, arg2);
|
||||||
|
OnPinChangedEvent?.Invoke(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetOutput(int pin, bool value)
|
public void SetOutput(int pin, bool value)
|
||||||
|
|||||||
@@ -25,11 +25,6 @@ namespace VisionBuilder.UI.Recipes.HawkeyeRecipe
|
|||||||
_loadingService = loadingService;
|
_loadingService = loadingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCameraName()
|
|
||||||
{
|
|
||||||
return _imageSource.GetName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<RecipeData> GetRecipesData()
|
public List<RecipeData> GetRecipesData()
|
||||||
{
|
{
|
||||||
_loadingService.StartLoading($"Loading recipes for {_recognitionConfiguration.CameraName}...");
|
_loadingService.StartLoading($"Loading recipes for {_recognitionConfiguration.CameraName}...");
|
||||||
@@ -171,7 +166,7 @@ namespace VisionBuilder.UI.Recipes.HawkeyeRecipe
|
|||||||
AnalysisTime = sw.Elapsed,
|
AnalysisTime = sw.Elapsed,
|
||||||
ErrorNames = errorNames.ToList(),
|
ErrorNames = errorNames.ToList(),
|
||||||
HasError = errorNames.Length > 0,
|
HasError = errorNames.Length > 0,
|
||||||
ImageSource = _imageSource.GetName(),
|
ImageSource = _recognitionConfiguration.CameraName,
|
||||||
ImageOriginal = _workflow.Context.LastCameraImage.ImageData,
|
ImageOriginal = _workflow.Context.LastCameraImage.ImageData,
|
||||||
ImageAnalysis = annotated
|
ImageAnalysis = annotated
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,10 +41,10 @@ namespace VisionBuilder.UI.Windows.Test
|
|||||||
|
|
||||||
var mainKernel = Common.VisionBuilder.CreateMainKernel(settings);
|
var mainKernel = Common.VisionBuilder.CreateMainKernel(settings);
|
||||||
mainKernel
|
mainKernel
|
||||||
|
.UseConsole()
|
||||||
.UseIOCommander([CAMERA1])
|
.UseIOCommander([CAMERA1])
|
||||||
.UseIOCommanderWindowsDebug()
|
.UseIOCommanderWindowsDebug()
|
||||||
.UseIOCommanderVirtualInput()
|
.UseIOCommanderVirtualInput()
|
||||||
.UseConsole()
|
|
||||||
.UseWindowsServices();
|
.UseWindowsServices();
|
||||||
|
|
||||||
// CAMERA 1 //
|
// CAMERA 1 //
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using OpenCvSharp.Extensions;
|
using OpenCvSharp;
|
||||||
|
using OpenCvSharp.Extensions;
|
||||||
using VisionBuilder.UI.Common.ViewModel;
|
using VisionBuilder.UI.Common.ViewModel;
|
||||||
|
|
||||||
namespace VisionBuilder.UI.Windows.Components;
|
namespace VisionBuilder.UI.Windows.Components;
|
||||||
@@ -18,7 +19,15 @@ public class PreviewWindow:PictureBox
|
|||||||
switch (e.PropertyName)
|
switch (e.PropertyName)
|
||||||
{
|
{
|
||||||
case nameof(PreviewVM.ImagePreview):
|
case nameof(PreviewVM.ImagePreview):
|
||||||
var bmp = _previewVm.ImagePreview?.ToBitmap();
|
var tmp = _previewVm.ImagePreview?.ToBitmap();
|
||||||
|
var bmp = new Bitmap(_previewVm.ImagePreview?.Width ?? 0, _previewVm.ImagePreview?.Height ?? 0);
|
||||||
|
// hack to avoid IDS image glitch
|
||||||
|
using (Graphics g = Graphics.FromImage(bmp))
|
||||||
|
{
|
||||||
|
g.Clear(Color.Pink);
|
||||||
|
g.DrawImage(tmp,0,0);
|
||||||
|
}
|
||||||
|
|
||||||
using (Graphics g = Graphics.FromImage(bmp))
|
using (Graphics g = Graphics.FromImage(bmp))
|
||||||
{
|
{
|
||||||
// draw red border around the image if it's an error
|
// draw red border around the image if it's an error
|
||||||
@@ -31,6 +40,7 @@ public class PreviewWindow:PictureBox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Image = bmp;
|
Image = bmp;
|
||||||
|
Invalidate();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Utility", "Utility", "{250F
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisionBuilder.UI.IOCommander.Windows", "VisionBuilder.UI.IOCommander.Windows\VisionBuilder.UI.IOCommander.Windows.csproj", "{254841AD-0706-4C92-A364-7E5DC17AF4AD}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisionBuilder.UI.IOCommander.Windows", "VisionBuilder.UI.IOCommander.Windows\VisionBuilder.UI.IOCommander.Windows.csproj", "{254841AD-0706-4C92-A364-7E5DC17AF4AD}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hawkeye.VisionBuilder.UI.Sources.IDS", "Hawkeye.VisionBuilder.UI.Sources.IDS\Hawkeye.VisionBuilder.UI.Sources.IDS.csproj", "{86511F06-AABC-4F1D-AB4E-9763AE4A0EF2}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{F2406FBB-DFD3-4CBE-9644-A9FFC2FCBB71}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IDSTest", "IDSTest\IDSTest.csproj", "{AD1A176C-B19F-4E60-9935-728722BAE3C1}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -163,6 +169,14 @@ Global
|
|||||||
{254841AD-0706-4C92-A364-7E5DC17AF4AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{254841AD-0706-4C92-A364-7E5DC17AF4AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{254841AD-0706-4C92-A364-7E5DC17AF4AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{254841AD-0706-4C92-A364-7E5DC17AF4AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{254841AD-0706-4C92-A364-7E5DC17AF4AD}.Release|Any CPU.Build.0 = Release|Any CPU
|
{254841AD-0706-4C92-A364-7E5DC17AF4AD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{86511F06-AABC-4F1D-AB4E-9763AE4A0EF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{86511F06-AABC-4F1D-AB4E-9763AE4A0EF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{86511F06-AABC-4F1D-AB4E-9763AE4A0EF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{86511F06-AABC-4F1D-AB4E-9763AE4A0EF2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{AD1A176C-B19F-4E60-9935-728722BAE3C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{AD1A176C-B19F-4E60-9935-728722BAE3C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{AD1A176C-B19F-4E60-9935-728722BAE3C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{AD1A176C-B19F-4E60-9935-728722BAE3C1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -185,6 +199,8 @@ Global
|
|||||||
{FBDCC120-B6B3-4A28-8845-DF1690F619C1} = {C828783C-1CE1-4245-8731-4AE18A28F590}
|
{FBDCC120-B6B3-4A28-8845-DF1690F619C1} = {C828783C-1CE1-4245-8731-4AE18A28F590}
|
||||||
{E0F75E78-F7FA-4B7D-BA5F-A8A91C0A9AD9} = {C828783C-1CE1-4245-8731-4AE18A28F590}
|
{E0F75E78-F7FA-4B7D-BA5F-A8A91C0A9AD9} = {C828783C-1CE1-4245-8731-4AE18A28F590}
|
||||||
{254841AD-0706-4C92-A364-7E5DC17AF4AD} = {250F2B27-FA2B-4CE6-BFDE-54D0B7FC9FAF}
|
{254841AD-0706-4C92-A364-7E5DC17AF4AD} = {250F2B27-FA2B-4CE6-BFDE-54D0B7FC9FAF}
|
||||||
|
{86511F06-AABC-4F1D-AB4E-9763AE4A0EF2} = {D05689E3-04C6-4E3B-ACA7-3F4507CED4CC}
|
||||||
|
{AD1A176C-B19F-4E60-9935-728722BAE3C1} = {F2406FBB-DFD3-4CBE-9644-A9FFC2FCBB71}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {3CE42AE5-D79F-4E97-A246-AA8FD228B677}
|
SolutionGuid = {3CE42AE5-D79F-4E97-A246-AA8FD228B677}
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ public class DefaultControlFactory : IControlFactory
|
|||||||
{
|
{
|
||||||
return CreateListControl(name, description, type, initialValue, valueChangedCallback, optionsWindow, settingDescription, previewLabel, getPreview);
|
return CreateListControl(name, description, type, initialValue, valueChangedCallback, optionsWindow, settingDescription, previewLabel, getPreview);
|
||||||
}
|
}
|
||||||
|
else if (type == typeof(string) && propertyInfo.GetCustomAttribute<FileAttribute>()!=null)
|
||||||
|
{
|
||||||
|
return CreateFileControl(name, description, initialValue, valueChangedCallback, optionsWindow, settingDescription, previewLabel, getPreview, propertyInfo.GetCustomAttribute<FileAttribute>().Filter);
|
||||||
|
}
|
||||||
else if (type == typeof(string) && name.EndsWith("Path", StringComparison.OrdinalIgnoreCase))
|
else if (type == typeof(string) && name.EndsWith("Path", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return CreatePathControl(name, description, initialValue, valueChangedCallback, optionsWindow, settingDescription, previewLabel, getPreview);
|
return CreatePathControl(name, description, initialValue, valueChangedCallback, optionsWindow, settingDescription, previewLabel, getPreview);
|
||||||
@@ -156,7 +160,36 @@ public class DefaultControlFactory : IControlFactory
|
|||||||
|
|
||||||
return CreateOuterPanel(settingDescription, previewLabel, label, textBox, browseButton);
|
return CreateOuterPanel(settingDescription, previewLabel, label, textBox, browseButton);
|
||||||
}
|
}
|
||||||
|
private Control CreateFileControl(string name, string description, object initialValue, Action<object> valueChangedCallback,
|
||||||
|
OptionsWindow optionsWindow, string settingDescription, Label previewLabel, Func<object, string> getPreview, string filter)
|
||||||
|
{
|
||||||
|
var textBox = new TextBox { Text = initialValue as string, Width = 400 };
|
||||||
|
var label = new Label { Text = description, AutoSize = true, Padding = new Padding(0, 5, 0, 0) };
|
||||||
|
var browseButton = new Button { Text = "Browse", AutoSize = true };
|
||||||
|
|
||||||
|
browseButton.Click += (s, e) =>
|
||||||
|
{
|
||||||
|
using (var dialog = new CommonOpenFileDialog {Filters = { new CommonFileDialogFilter(filter, filter) }})
|
||||||
|
{
|
||||||
|
if (dialog.ShowDialog(optionsWindow.Handle) == CommonFileDialogResult.Ok)
|
||||||
|
{
|
||||||
|
textBox.Text = dialog.FileName;
|
||||||
|
valueChangedCallback(dialog.FileName);
|
||||||
|
if (previewLabel != null && getPreview != null)
|
||||||
|
previewLabel.Text = getPreview(dialog.FileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
textBox.TextChanged += (s, e) =>
|
||||||
|
{
|
||||||
|
valueChangedCallback(textBox.Text);
|
||||||
|
if (previewLabel != null && getPreview != null)
|
||||||
|
previewLabel.Text = getPreview(textBox.Text);
|
||||||
|
};
|
||||||
|
|
||||||
|
return CreateOuterPanel(settingDescription, previewLabel, label, textBox, browseButton);
|
||||||
|
}
|
||||||
private Control CreateStringControl(string description, object initialValue, Action<object> valueChangedCallback,
|
private Control CreateStringControl(string description, object initialValue, Action<object> valueChangedCallback,
|
||||||
string settingDescription, Label previewLabel, Func<object, string> getPreview)
|
string settingDescription, Label previewLabel, Func<object, string> getPreview)
|
||||||
{
|
{
|
||||||
|
|||||||
15
framework/Inspectron.Settings/Attributes/FileAttribute.cs
Normal file
15
framework/Inspectron.Settings/Attributes/FileAttribute.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Inspectron.Settings.Attributes
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Property)]
|
||||||
|
public class FileAttribute:Attribute
|
||||||
|
{
|
||||||
|
public string Filter { get; }
|
||||||
|
|
||||||
|
public FileAttribute(string filter)
|
||||||
|
{
|
||||||
|
Filter = filter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user