2024-02-22 07:19 AM - edited 2024-02-22 09:17 AM
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;
}
Solved! Go to Solution.
2024-02-22 09:24 AM
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!
2024-02-22 08:49 AM
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.
2024-02-22 08:54 AM - edited 2024-02-22 09:04 AM
Please use this button to properly post source code:
2024-02-22 09:24 AM
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!