我有 ReadBinFile()//从bin文件中读取2048字节 {
transferlength = fileGetBinaryBlock(buffer,2048,fileHandle); }
现在我想阅读.hex和.mhx扩展文件我无法找到内置函数在capl脚本中执行此操作的选项。
答案 0 :(得分:0)
dword openFileRead(char filename[], dword mode);
此函数打开名为filename的文件以进行读取访问。
如果mode = 0,则以ASCII模式打开文件; 如果mode = 1,则以二进制模式打开文件。
To open hexfile
dword HexFileHandle;
HexFileHandle = openFileRead(HEX_File_Path, 0);
返回值是必须用于读取操作的文件句柄。
如果发生错误,则返回值为0.
答案 1 :(得分:0)
*.hex 或 *.mhx 格式的文件可以在 OpenFileRead 函数的帮助下读取。 下面的一段代码将有助于阅读 .hex 文件。
void readhexfile(void)
{
dword i;
char LineBuffer[0xFF];
int ByteCount;
char CountAscii[5];
int Data;
char Ascii[5];
dword readaccess = 0;
dword bufferpointer = 0;
byte buffer[1*1024*1024]; //1MB hex file size
if ((-1) != strstr_regex(FILENAME, ".hex")) //FILENAME-> Sysvariable
{
readaccess = OpenFileRead (FILENAME,0);
/* --> identified as IntelHEX-Input */
if (readaccess != 0)
{
/* read line until cr+lf */
while (fileGetString(LineBuffer, elcount(LineBuffer), readaccess) != 0)
{
// check for Record Type 00 (Data Record)
if (LineBuffer[0] == ':'
&& LineBuffer[7] == '0'
&& LineBuffer[8] == '0'
)
{
// extract ByteCount parameter
strncpy(CountAscii, "0x", elcount(CountAscii));
substr_cpy_off(CountAscii, 2, LineBuffer, 1, 2, elcount(CountAscii));
ByteCount = atol(CountAscii);
// extract Data parameter
for (i = 0; i < ByteCount; i++)
{
strncpy(Ascii, "0x", elcount(Ascii));
substr_cpy_off(Ascii, 2, LineBuffer, 9+i*2, 2, elcount(Ascii));
Data = atol(Ascii);
buffer[bufferpointer++] = Data;
};
}
}
fileClose(readaccess);
}
}
}
类似方法可用于读取 .mhx 文件格式。