cancel
Showing results for 
Search instead for 
Did you mean: 

CubeProgrammer API Error: file does not exist, please check the file's path

hamzamaq
Associate II

Hello,

I am using the CubeProgrammerAPI.dll in a C# software and I get this error :
CubeprogrammerErrorNoFile = -4, when I use the download function.

I don't understand why this file path issue persists. Even after changing the directory, the problem persists without success.

Here is my function:

string filePath = @"D:\DFU\CodeChanges_18_GasTypeTempComp.hex";

var filePathAdapted = string.IsNullOrEmpty(filePath) ? "" : filePath.Replace(@"\", "/");

uint address = 0x08000000;
uint isverify = 1;
uint isSkipErase = 0;
var password = "";

var download = CubeProgrammerApi.downloadFile(filePathAdapted, address, isSkipErase, isverify, password);

if (download != 0)
{
Console.WriteLine($"Download Error {download}", "No USB DFU available\n");
CubeProgrammerApi.disconnect();
return;
}
1 ACCEPTED SOLUTION

Accepted Solutions

It has been resolved, I was not including "charSet.Unicode" in the DllImport for proper marshaling of string between C# and C.

[DllImport(CubeProgrammerDll64, SetLastError = true, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern int downloadFile(string filePath, uint address, uint skipErase, uint verify, string binPath);

Anyways, Thank you! 

View solution in original post

3 REPLIES 3
TDK
Guru

Does the file exist?

Perhaps try with the standard "\" directory separators that Windows expects. Supposed to work with either but not all software can handle it.

If you feel a post has answered your question, please click "Accept as Solution".
Andrew Neil
Evangelist

Please use this button to properly post source code:

AndrewNeil_0-1708620865189.png

 

 

It has been resolved, I was not including "charSet.Unicode" in the DllImport for proper marshaling of string between C# and C.

[DllImport(CubeProgrammerDll64, SetLastError = true, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern int downloadFile(string filePath, uint address, uint skipErase, uint verify, string binPath);

Anyways, Thank you!