PDA

View Full Version : loadDeviceStateFromFile fails when bOpenDev is set to false



frapargo
September 19, 2012, 09:00:23
Hello, I am using Imaging Control 3.2 with VS2008, and I have an application that saves the camera settings with the function saveDeviceStateToFile, and then try to restore the settings with loadDeviceStateFromFile. If the parameter bOpenDev is true, there is no problem, but I need bOpenDev set to false because I want to apply the saved settings to different cameras of the same model. When I call loadDeviceStateFromFile(fileName, false), the function returns false, and the error returned is "One function parameter is invalid".

Here is a portion of the code:

// Save the device state
m_Grabber->saveDeviceStateToFile( fileName, false );

// Load the saved state.
bool bRet = m_Grabber->loadDeviceStateFromFile( fileName, false );
if (bRet == false)
{
if( m_Grabber->getLastError() )
{
char str_error[512];
sprintf(str_error, "%s", m_Grabber->getLastError().c_str());
}
}

Does anybody know what the problem is? Thanks in advance...

Michael Kirmse
September 19, 2012, 11:05:59
Hello frapargo,

in order to solve your problem, I would like to know what exactly the content of "fileName" is.

frapargo
September 19, 2012, 11:42:57
Hello frapargo,

in order to solve your problem, I would like to know what exactly "fileName" is.

fileName is the xml file where the camera settings are saved. This is the content of cam_settings.xml when I call to saveDeviceStateToFile("cam_settings.xml", false):

<device_state libver="3.2" filemajor="1" fileminor="0">
<device>
<videoformat>RGB24 (640x480)</videoformat>
<fps>87.000400201840932</fps>
<vcdpropertyitems>
<item guid="{284C0E0D-010B-45BF-8291-09D90A459B28}" name="WhiteBalance">
<element guid="{B57D3001-0AC6-4819-A609-272A33140ACA}" name="Auto">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E04}" value="0" />
</element>
<element guid="{6519038B-1AD8-4E91-9021-66D64090CC85}" name="White Balance Red">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="77" />
</element>
<element guid="{8407E480-175A-498C-8171-08BD987CC1AC}" name="White Balance Green">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="64" />
</element>
<element guid="{6519038A-1AD8-4E91-9021-66D64090CC85}" name="White Balance Blue">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="97" />
</element>
</item>
<item guid="{284C0E0F-010B-45BF-8291-09D90A459B28}" name="Gain">
<element guid="{B57D3000-0AC6-4819-A609-272A33140ACA}" name="Value">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="16" />
</element>
<element guid="{B57D3001-0AC6-4819-A609-272A33140ACA}" name="Auto">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E04}" value="0" />
</element>
</item>
<item guid="{90D5702E-E43B-4366-AAEB-7A7A10B448B4}" name="Exposure">
<element guid="{B57D3000-0AC6-4819-A609-272A33140ACA}" name="Value">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E08}" value="6.6100000000000006e-002" />
</element>
<element guid="{B57D3001-0AC6-4819-A609-272A33140ACA}" name="Auto">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E04}" value="0" />
</element>
<element guid="{6519038C-1AD8-4E91-9021-66D64090CC85}" name="Auto Reference">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="128" />
</element>
<element guid="{6519038F-1AD8-4E91-9021-66D64090CC85}" name="Auto Max Value">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E08}" value="0.25" />
</element>
<element guid="{65190390-1AD8-4E91-9021-66D64090CC85}" name="Auto">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E04}" value="0" />
</element>
</item>
<item guid="{90D57031-E43B-4366-AAEB-7A7A10B448B4}" name="Trigger">
<element guid="{B57D3000-0AC6-4819-A609-272A33140ACA}" name="Enable">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E04}" value="0" />
</element>
</item>
<item guid="{3A3A8F77-6440-46CC-940A-8752B02E6C29}" name="Color Enhancement">
<element guid="{B57D3000-0AC6-4819-A609-272A33140ACA}" name="Enable">
<itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E04}" value="0" />
</element>
</item>
</vcdpropertyitems>
</device>
</device_state>


Now, if I run loadDeviceStateToFile("cam_settings.xml", false), the function returns false and the error is "One function parameter is invalid".

Stefan Geissler
September 19, 2012, 12:11:03
Just to be sure:

The file exists and your current working directory is where the file is?

Thank you in advance.

frapargo
September 19, 2012, 16:18:38
Just to be sure:

The file exists and your current working directory is where the file is?

Thank you in advance.

I think there is no problem with the path of the file. When the file passed to the function doesn't exist, the error returned changes to "An error occured while trying to read data from a file".

After testing the functions to save and load from a file, I realized that the problem is in the second line of the generated file, which is different when the parameter bOpenDev changes:

With bOpenDev=true, the second line of the generated file is <device name="DFx 22BUC03" base_name="DFx 22BUC03" unique_name="DFx 22BUC03 6110445">. It includes information about the camera, and you can load the file whitout errors.

With bOpenDev=false, the second line of the generated file is <device>, and the function loadDeviceStateFromFile returns an error when this file is used.

Surprisingly, If I manually change the second line of the generated file to <device name="DFx 22BUC03" base_name="DFx 22BUC03">, then the function loadDeviceStateFromFile with bOpenDev = false works fine.

It seems that the problem is in the tag "device" of the generated file when bOpenDev is false. The function saveDeviceStateToFile doesn't include data in this tag, and loadDeviceStateFromFile expects to have information about "name" and "base_name"...

Thank you.

Stefan Geissler
September 19, 2012, 16:50:48
We tried the very same code on our own, before the first answer was posted. We got no error. Therefore, the problem may can be solved, if you install the latest IC Imaging Control version from http://www.theimagingsource.com/en_US/support/downloads/

I do not think, it is Visual Studio dependent, but I would like to know, which version you use.

frapargo
September 20, 2012, 10:52:18
We tried the very same code on our own, before the first answer was posted. We got no error. Therefore, the problem may can be solved, if you install the latest IC Imaging Control version from http://www.theimagingsource.com/en_US/support/downloads/

I do not think, it is Visual Studio dependent, but I would like to know, which version you use.

After installing the latest IC drivers and making some changes in code, I have solved my problem.

This is the code that works for me:

// Save the device state
m_Grabber->saveDeviceStateToFile( fileName, true);

// Load the saved state.
m_Grabber->loadDeviceStateFromFile( fileName, false );

It allows to save the camera settings to a file, and the generated file can be loaded in different cameras of the same model.

As you can see, the parameter bOpenDev has to be true when saving and false when loading the file. The generated file whith the second parameter set to false is not readable by the loading functions of the library.

Thank for your help.

Stefan Geissler
September 24, 2012, 15:25:33
Hi

I am sorry for coming so late back to you. I checked the code you posted on my own and confirm the issue. Therefore, you must work with the workaround you already found. I issue an error, so the programmers fix this in a later version of IC Imaging Control.