LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

pxi realtime GetFirstFile not working

Hi,

I need to do a "dir" or "ls" equivalent

1. GetFirstFile, GetNextFile aren't supported in realtime
2. MS SDK's FindFirstFileA, GetNextFileA also don't appear to work.

Any hints, clues, workarounds?

0 Kudos
Message 1 of 9
(3,594 Views)

To help further troubleshoot this issue,  would you please check the following example code and let me know if that works on the LabWindows/CVI Real Time.

https://decibel.ni.com/content/docs/DOC-9732

 

Thank you

0 Kudos
Message 2 of 9
(3,578 Views)

 

Hi,

 

There are two problems with the test you pointed to:

 

1. CVI C realtme does not support GUI's. There's no lib/dll to link to.

 

2. CVI C realtime does not support the call "GetFirstFile" or GetNextFile. There's no lib/dll to link to.

 

I am not running on a "normal" PC, this is a PXI chassis attached to a laptop running CVI through a TCP/IP connection.

Its running a version of Phar-Lap that magically "works" with CVI. There is no display, there is no keyboard. 

 

bob s.

0 Kudos
Message 3 of 9
(3,575 Views)

You're correct that the utility functions GetFirstFile and GetNextFile are not defined on RT, but the Windows SDK functions, FindFirstFile and FindNextFile (and FindClose) are supported and should work just fine. You can call and link them just like you would on Windows.

 

What problems do you run into when trying to use FindFirstFile/FindNextFile? The following code worked for me:

 

WIN32_FIND_DATA findData;
HANDLE searchHandle = FindFirstFile("c:\\*", &findData);
while (FindNextFile(searchHandle, &findData))
    ;
DWORD err = GetLastError();
if (err != ERROR_NO_MORE_FILES)
    ; // handle error    
FindClose(searchHandle);

 

Mert A.

National Instruments

0 Kudos
Message 4 of 9
(3,560 Views)

 

Hi,

  I did not find FindFirstFile, but I did find a FindFirstFileA.

 

  The first call to FindFirstFileA returns 0. Which indicates success.

  The data structure element .cFileName contains "."
  In the unix world, "." means current directory. This was promising, but...

  
  The first call to FindNextFileA using the handle returned from FindFirstFileA
  returns the error value 1, ERROR_INVALID_FUNCTION.

  

  Any chance that NI or the windows SDK supports something the C library call "system()"
  so I can send commands directly to the Phar Lap OS?  Something like system("ls > dir.txt")? 

 

bob s.

0 Kudos
Message 5 of 9
(3,549 Views)

I don't believe RT systems have support for shell commands like "dir" or "ls".

 

What do you mean by "I did not find FindFirstFile"? Where are you looking for it and not finding it? If you're building an RT DLL project, CVI automatically links against special versions of the Windows SDK import libraries that contain only the functions actually supported by the RT platform. Calls to FindFirstFile (or FindFirstFileA) should link just fine and run properly on the target. Are you doing something else? Can you try just calling them as usual?

 

Mert A.

National Instruments

0 Kudos
Message 6 of 9
(3,536 Views)

The PharLap FTP Server used on LabVIEW RT gets a programmatic listing of files/directories, exactly like you want to do.  It is a DLL like yours, and if it didn't work you wouldn't have FTP access to the target.  Here's what it does:


char path[MAX_FTP_PATH_LENGTH] = {'\0'};
WIN32_FIND_DATA findData;
HANDLE dirHandle = FindFirstFile( path, &findData );
do {
...
//Do something with File/Directory
doSomethingWithFileName( findData.cFileName );
...
} while( FindNextFile( dirHandle, &findData ) );
FindClose( dirHandle );

 Let us know if this doesn't work, and if it doesn't then let us know what version of RT you're using.

 

-Danny

0 Kudos
Message 7 of 9
(3,524 Views)

Hi,

 

Meas and Automation shows: Labwindows/CVI runtime engine for rt 10.0.0.

 

I went back the code and changed GetFirstFileA to GetFirstFile in order to generate the linker error message to get that back to you but this time it did not generate an error, so I decided to “go with it” to see what would happen and the same thing happened. GetFirstFile did not generate an error on the call but GetNextFile using the handle returned from GetFirstFile returned the value “1”, which means ERROR_INVALID_FUNCTION.

Is there any way I can the source code for these functions, build them and set a breakpoint and walk through to where the errror is generated?

0 Kudos
Message 8 of 9
(3,512 Views)

I found my bug. FindNext returns a positive Non-zero value on success. I was taking the positive not zero value as an error.

I'm all set. Thank you.

0 Kudos
Message 9 of 9
(3,503 Views)