PDA

View Full Version : How to reset all camera properties?



marius.g
October 15, 2014, 17:36:48
How can I reset all camera properties? I could not find a method for this.

I tried manually iterating over all items->elements->interfaces and reset all interfaces to their defaults, but VCDSwitchProperties don't tell their default.

TIA
Marius

Stefan Geissler
October 15, 2014, 17:46:34
You may try following code:


public static void ResetProperties(ICImagingControl ic)
{
foreach (VCDPropertyItem VCDItem in ic.VCDPropertyItems)
{
Console.WriteLine(VCDItem.Name);
Log(VCDItem.Name);
VCDSwitchProperty Auto = (VCDSwitchProperty) VCDItem.FindInterface(VCDIDs.VCDElement_Auto +":"+ VCDIDs.VCDInterface_Switch);
if (Auto != null)
{
// Auto off, so we can set the default values.
Auto.Switch = false;
Console.WriteLine("-- auto off");
}

Console.WriteLine("-- All switches to off" );

foreach (VCDPropertyElement Element in VCDItem.Elements)
{

VCDSwitchProperty Switch = (VCDSwitchProperty)Element.FindInterface(VCDIDs.VC DInterface_Switch);
if (Switch != null)
{
Console.WriteLine("-- " + Element.Name);
try
{
Console.WriteLine("---- Switch off");
Switch.Switch = false;
}
catch (ICException iEx)
{
Console.WriteLine(String.Format("Failed to set switch interface {0} {1}", VCDItem.Name.ToString(), iEx.Message));
Log(String.Format("Failed to set range interface {0} {1}", VCDItem.Name.ToString(), iEx.Message));
}
}

}

Console.WriteLine("-- All Ranges to default");

foreach (VCDPropertyElement Element in VCDItem.Elements)
{
VCDRangeProperty Range = null;
try
{
Range = (VCDRangeProperty)Element.FindInterface(VCDIDs.VCD Interface_Range);
}
catch (ICException iEx)
{
Console.WriteLine(String.Format("Failed to query range interface {0} {1}", VCDItem.Name.ToString(), iEx.Message));
}

if (Range != null)
{
Console.WriteLine("-- " + Element.Name);

try
{
Console.WriteLine(String.Format("---- Range : {0}", Range.Value));
Range.Value = Range.Default;
}
catch (ICException iEx)
{
Console.WriteLine(String.Format("Failed to set range interface {0} {1}", VCDItem.Name.ToString(), iEx.Message));
}
}
}

Console.WriteLine("-- All Auto switches to On" );

foreach (VCDPropertyElement Element in VCDItem.Elements)
{

VCDSwitchProperty Switch = (VCDSwitchProperty)Element.FindInterface(VCDIDs.VC DInterface_Switch);
if (Switch != null)
{
if (Element.Name == "Auto")
{
Console.WriteLine("-- " + Element.Name);
try
{
Console.WriteLine("---- Switch on");
Switch.Switch = true;
}
catch (ICException iEx)
{
Console.WriteLine(String.Format("Failed to set switch interface {0} {1}", VCDItem.Name.ToString(), iEx.Message));
}
}
}

} // foreach (VCDPropertyElement Element in VCDItem.Elements)


if (Auto != null)
{
Auto.Switch = true;
Console.WriteLine("-- auto on");
}
}

}


This code does not answer your question, because switches have no default value, but it shows, how to differ between automatics and other switches.

marius.g
October 16, 2014, 09:40:57
Thanks Stefan!

Here are some follow up questions:

1) Is this basically what you do in the IC Capture menu item Device > Reset Properties?

2) How should I handle interfaces that have Readonly == true or Available == false? When I skip those, I get a lot of hits. If I ignore them, I only get 3 ICExceptions.

3) What about VCDMapStringsProperty interfaces? For some reason they don't show up in this loop:



foreach (VCDPropertyItem item in IcImagingControl.VCDPropertyItems) {
foreach (VCDPropertyElement element in item.Elements) {
foreach (VCDPropertyInterface iface in element) {
var map = iface as VCDMapStringsProperty;
if (map != null) {
...
}

Stefan Geissler
October 16, 2014, 10:26:30
1) Is this basically what you do in the IC Capture menu item Device > Reset Properties?
Nearly. This is C# code excerpt out of my camera test software.


2) How should I handle interfaces that have Readonly == true or Available == false? When I skip those, I get a lot of hits. If I ignore them, I only get 3 ICExceptions.
Readonly are to be ignored, not Availbe wont be in the list at all.


3) What about VCDMapStringsProperty interfaces? For some reason they don't show up in this loop:

This depends on the used camera and the property you want to set.
The loop above handles the properties supported by the camera only. Therefore, you wont see any "not available" ones.

marius.g
October 16, 2014, 11:02:39
This depends on the used camera and the property you want to set.
The loop above handles the properties supported by the camera only. Therefore, you wont see any "not available" ones.
Hm. Your loop or mine? With my loop, I do see unavailable interfaces, but it does apparently not always cause an exception to set their values.

Stefan Geissler
October 16, 2014, 12:11:32
Hm. Your loop or mine? With my loop, I do see unavailable interfaces, but it does apparently not always cause an exception to set their values.

I know my loop only. It works fine for all of our cameras. I use it in the camera test software.

marius.g
October 16, 2014, 13:59:28
Ok, I think its working now for me. Thanks again for your support.

FWIW, I extended your loop to also handle MapString properties. At least with my DFK USB2.0 camera this code is executed, so it is probably needed to reset those properties as well:



foreach (VCDPropertyElement element in item.Elements) {
var map = (VCDMapStringsProperty)element.FindInterface(VCDID s.VCDInterface_MapStrings);
if (map != null) {
try {
map.Value = map.Default;
}
catch (ICException) {
}
}
}