Reading Configuration Files

Forum for software developers to discuss BCI2000 software development
Locked
timo.veldt
Posts: 23
Joined: 12 Feb 2010, 04:08

Reading Configuration Files

Post by timo.veldt » 05 Mar 2010, 11:21

I'm working on a BCI2000 application (3rd filter for the operator) that controls an external piece of hardware to present stimuli. The module for this external hardware has been tried and tested and it works.

The module allows the user to specify certain parameters in a text file, which I would like to read in with my BCI2000 Application. When trying to read this config file (stored in the same directory as the executable) an error message is presented that tells me the file cannot be found.

After some testing I found the problem, which has to do with the current working directory.

Ingredients:
- BCI2000 v3.0
- Operator
- gUSBampSource
- DummySignalProcessing
- CustomStimulusPresentation (derived from ApplicationBase (because StimulusPresentationTask already defined too many parameters))

When running the program and pressing the Set Config button, the operator gives me the error the file cannot be found. The working directory has been changed to the data storage location (BCI2000\data\Name00) instead of the directory of the executable (BCI2000\prog).

Why does the program change the working directory?
[Edit]And why doesn't it change it back ;) [/edit]

timo.veldt
Posts: 23
Joined: 12 Feb 2010, 04:08

To go with this

Post by timo.veldt » 05 Mar 2010, 11:25

If I make a parameter which has the inputfile designation in the comment, enabling the "browse to location"-button, I have to adjust (i.e. type an extra character, remove it again) the string (obtained through the "browse"-button) before the value is updated in the program.

Is there a way to fix this?

mellinger
Posts: 1065
Joined: 12 Feb 2003, 11:06

Post by mellinger » 05 Mar 2010, 11:50

When running the program and pressing the Set Config button, the operator gives me the error the file cannot be found. The working directory has been changed to the data storage location (BCI2000\data\Name00) instead of the directory of the executable (BCI2000\prog).
Relying on a certain behavior wrt to the working directory is not a good strategy.
BCI2000 provides functions for dealing with the application's installation directory. These are declared in BCI2000/src/shared/fileio/BCIDirectory.h.
string BCIDirectory::InstallationDirectory()
returns the absolute path to the module's installation directory, and
string BCIDirectory::AbsolutePath(string)
translates an application-relative path into an absolute one (leaving an absolute path unchanged).
If I make a parameter which has the inputfile designation in the comment, enabling the "browse to location"-button, I have to adjust (i.e. type an extra character, remove it again) the string (obtained through the "browse"-button) before the value is updated in the program.

Is there a way to fix this?
This is a bug that has been fixed in rev. 2696.

stefan
Posts: 13
Joined: 22 Oct 2009, 16:43

Post by stefan » 03 Aug 2010, 14:02

Relying on a certain behavior wrt to the working directory is not a good strategy.
I just ran into a similar problem where I had a script with relative path executed from the --OnStart command and after loading a parameter file from a different folder it could not be found anymore. There also seems to be an inconsistency between running operat.exe --OnConnect "-LOAD PARAMETERFILE ..." (does not change working dir) and manually loading a parm file (changes working dir). It would be nice if BCI2000 could keep a consistent "working directory" for a session. That would also make it easier with regard to moving files to a different folder/drive/system.

Stefan

mellinger
Posts: 1065
Joined: 12 Feb 2003, 11:06

Post by mellinger » 04 Aug 2010, 10:23

Due to your requests, BCI2000 now no longer changes working directories. This applies to both the Operator module and core modules.

Best regards,
Juergen

stefan
Posts: 13
Joined: 22 Oct 2009, 16:43

Post by stefan » 06 Aug 2010, 16:09

This is great news, thank you!

Locked

Who is online

Users browsing this forum: No registered users and 1 guest