-
Notifications
You must be signed in to change notification settings - Fork 53
Using the FrameNotifySink and software trigger
TIS-Stefan edited this page Dec 16, 2022
·
2 revisions
IC Imaging Control 3.5
This sample shows, how to use the FrameNotifySink and the software trigger.
Create a new Console project using .NET Framework up to version 4.8. Then add "System.Windows.Forms" and "IC Imaging Control" to the references.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TIS.Imaging;
The Listener will be passed to the FrameNotifySink. Its FrameReceived member function will be called each time a new frame arrives automatically.
class Listener : IFrameNotificationSinkListener
{
private System.Threading.AutoResetEvent frameAcquiredEvent;
public Listener(System.Threading.AutoResetEvent frameAcquiredEvent)
{
this.frameAcquiredEvent = frameAcquiredEvent;
}
public void SinkConnected(FrameType frameType) { }
public void SinkDisconnected() { }
public void FrameReceived(IFrame frame)
{
// do something with frame
// Set the event for main thread, so the
// next trigger can be pushed.
frameAcquiredEvent.Set();
}
}
An image processing can be done in the FrameReceived
member function. The frame
is deleted when FrameReceived
ends.
static void Main(string[] args)
{
ICImagingControl ic = new ICImagingControl();
var frameAcquiredEvent = new System.Threading.AutoResetEvent(false);
var listener = new Listener(frameAcquiredEvent);
// Create the sink
var sink = new FrameNotificationSink(listener);
ic.Sink = sink;
// Open a video capture device
ic.ShowDeviceSettingsDialog();
ic.LiveStart();
// Disable automatics
var autoprop = ic.VCDPropertyItems.Find<VCDSwitchProperty>(VCDGUIDs.VCDID_Exposure, VCDGUIDs.VCDElement_Auto);
if (autoprop != null)
autoprop.Switch = false;
autoprop = ic.VCDPropertyItems.Find<VCDSwitchProperty>(VCDGUIDs.VCDID_Gain, VCDGUIDs.VCDElement_Auto);
if (autoprop != null)
autoprop.Switch = false;
autoprop = ic.VCDPropertyItems.Find<VCDSwitchProperty>(VCDGUIDs.VCDID_WhiteBalance, VCDGUIDs.VCDElement_Auto);
if (autoprop != null)
autoprop.Switch = false;
// Enable the trigger mode
var triggermode = ic.VCDPropertyItems.Find<VCDSwitchProperty>(VCDGUIDs.VCDID_TriggerMode, VCDGUIDs.VCDElement_Value);
if (triggermode != null)
triggermode.Switch = true;
else
{
Console.WriteLine("Ups, no trigger mode?");
return;
}
// Get software trigger property
var softtrigger = ic.VCDPropertyItems.Find<VCDButtonProperty>(VCDGUIDs.VCDID_TriggerMode, VCDGUIDs.VCDElement_SoftwareTrigger);
// Now push the software trigger and wait for the `frameAcuiredEvend'
for (int i = 0; i < 5; i++)
{
softtrigger.Push();
frameAcquiredEvent.WaitOne(200);
}
ic.LiveStop();
}
}