/***************************************************************************** * * * Application Control Interface Example for Phyton Programmers * * * * Description: Selects a device, loads .hex file into buffer 0, * * then executes Auto Programming and exits. * * * * Code to modify: See main() function at the end of this file. Change * * the path to the programmer executable file, device type and path to * * .hex file. * * * * (C) Phyton * * * ******************************************************************************/ #define _CRT_SECURE_NO_WARNINGS #define WIN32_LEAN_AND_MEAN #include #include #include #include "..\aciprog.h" void PrintError(UINT error_code); BOOL Attach(const char * exe, const char * command_line, BOOL debug); UINT SetDevice(const char * manufacturer, const char * device_name); UINT GetSelectedDevice(void); BOOL LoadHexFile(char * file_name, UINT buffer_num, UINT layer_num); BOOL ExecAutoProgramming(UINT buffer_num, BOOL silent); ACI_PStatus_Params Status = { sizeof(ACI_PStatus_Params) }; /*+ PrintError ° 01.07.09 15:07:30*/ void PrintError(UINT error_code) { const char * msg; char text[48]; switch (error_code) { case ACI_ERR_SUCCESS: return; case ACI_ERR_INVALID_PARAMS_SIZE: msg = "ACI_ERR_INVALID_PARAMS_SIZE: Invalid structure size in ACI function"; break; case ACI_ERR_INVALID_EXE: msg = "ACI_ERR_INVALID_EXE: Invalid executable in ACI_Launch()"; break; case ACI_ERR_EXE_FAILED: msg = "ACI_ERR_EXE_FAILED: Programmer executable failed to launch"; break; case ACI_ERR_FILE_ERROR: msg = "ACI_ERR_FILE_ERROR: File error"; break; case ACI_ERR_ATTACH_FAILED: msg = "ACI_ERR_ATTACH_FAILED: ACI_Launch() failed"; break; case ACI_ERR_INVALID_PARAMETER: msg = "ACI_ERR_INVALID_PARAMETER: Invalid parameter in function structure"; break; case ACI_ERR_FUNCTION_FAILED: msg = "ACI_ERR_FUNCTION_FAILED: Function execution failed in ACI_ExecFunction()"; break; case ACI_ERR_NOT_CONNECTED: msg = "ACI_ERR_NOT_CONNECTED: No connection to the target hardware"; break; case ACI_ERR_NOT_AVAILABLE_NOW: msg = "ACI_ERR_NOT_AVAILABLE_NOW: Requested operation is not available at the moment"; break; case ACI_ERR_INVALID_LAYER: msg = "ACI_ERR_INVALID_LAYER: Invalid buffer or layer number"; break; case ACI_ERR_INVALID_ADDR: msg = "ACI_ERR_INVALID_ADDR: Invalid address"; break; case ACI_ERR_OUT_OF_RANGE: msg = "ACI_ERR_OUT_OF_RANGE: Value is out of range"; break; default: sprintf(text, "%u: Unknown error code", error_code); msg = text; break; } printf("Error: %s\n", msg); } /*+ Attach ° 01.07.09 15:04:27*/ BOOL Attach(const char * exe, const char * command_line, BOOL debug) { UINT r; static ACI_Launch_Params params; params.Size = sizeof(ACI_Launch_Params); // UINT Size; // (in) Size of structure, in bytes params.ProgrammerExe = exe; // LPCSTR ProgrammerExe; // (in) Programmer executable file name params.CommandLine = command_line; // LPCSTR CommandLine; // (in) Optional programmer command-line parameters params.DebugMode = debug; // BOOL DebugMode; // (in) Debug mode. Programmer window is not hidden r = ACI_Launch(¶ms); PrintError(r); return r == ACI_ERR_SUCCESS;} /*+ SetDevice ° 01.07.09 15:15:01*/ UINT SetDevice(const char * manufacturer, const char * device_name) { UINT r; ACI_Device_Params params = { sizeof(ACI_Device_Params) }; strcpy(params.Manufacturer, manufacturer); strcpy(params.Name, device_name); r = ACI_SetDevice(¶ms); PrintError(r); return r == ACI_ERR_SUCCESS; } /*+ GetSelectedDevice ° 01.07.09 18:01:25*/ UINT GetSelectedDevice(void) { ACI_Device_Params params = { sizeof(ACI_Device_Params) }; UINT r = ACI_GetDevice(¶ms); PrintError(r); if (r == ACI_ERR_SUCCESS) printf("Device selected: %s %s\n", params.Manufacturer, params.Name); return r == ACI_ERR_SUCCESS; } /*+ LoadHexFile ° 25.05.09 14:41:50*/ BOOL LoadHexFile(char * file_name, UINT buffer_num, UINT layer_num) { UINT r; ACI_File_Params params = { sizeof(ACI_File_Params) }; params.FileName = file_name; params.Format = ACI_PLF_INTEL_HEX; params.BufferNumber = buffer_num; params.LayerNumber = layer_num; r = ACI_FileLoad(¶ms); PrintError(r); if (r == ACI_ERR_SUCCESS) printf("File %s loaded to buffer %u, layer %u\n", file_name, buffer_num, layer_num); return r == ACI_ERR_SUCCESS; } /*+ ExecAutoProgramming ° 01.07.09 16:57:04*/ BOOL ExecAutoProgramming(UINT buffer_num, BOOL silent) { UINT r; ACI_Function_Params params = { sizeof(ACI_Function_Params) }; params.FunctionName = NULL; // NULL means execute auto programming params.BufferNumber = buffer_num; params.Silent = silent; printf("--- Executing Auto Programming... ---\n"); r = ACI_ExecFunction(¶ms); PrintError(r); if (r == ACI_ERR_SUCCESS) printf("Auto Programming complete.\n"); else printf("Auto Programming error: %s.\n", params.ErrorMessage); return r == ACI_ERR_SUCCESS; } /*+ main ° 01.07.09 17:37:24*/ int main(void /*int argc, char ** argv*/) { // Launch the programmer executable if (!Attach("C:\\Program Files\\ChipProgUSB\\4_72_00\\UPrognt2.exe", "", FALSE)) return -1; // Select device to operate on if (!SetDevice("Microchip", "PIC18F242")) return -1; // Just for demonstration GetSelectedDevice(); // Load .hex file to buffer 0, layer 0 if (!LoadHexFile("C:\\Program\\test.hex", 0, 0)) return -1; // Set all programming options to their default values ACI_AllProgOptionsDefault(); // Execute automatic programming, i.e. predefined set of operations: // Erase, Blank Check, Program, Verify... ExecAutoProgramming(0, TRUE); return 0; }