Skip to main content
Associate
February 22, 2024
Solved

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

  • February 22, 2024
  • 2 replies
  • 1566 views

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;
}
This topic has been closed for replies.
Best answer by hamzamaq

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! 

2 replies

TDK
Super User
February 22, 2024

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""."
hamzamaqAuthorBest answer
Associate
February 22, 2024

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! 

Andrew Neil
Super User
February 22, 2024

Please use this button to properly post source code:

AndrewNeil_0-1708620865189.png

 

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.