【问题标题】:how to copy data from one file to another in capl如何在capl中将数据从一个文件复制到另一个文件
【发布时间】:2018-08-14 06:35:55
【问题描述】:

我正在尝试将数据从一个文件复制到另一个文件。这里文件已成功打开和关闭,但数据未复制到文件中。源文件和目标文件位于同一位置。此外,复制到文件中的数据是字符串格式,在复制到文件之前如何将其转换为十六进制值。

variables
{

    dword fHandler;
    dword handle;
    char DataRecordBuf[15000][50];
    byte recordData[15000][50];
    byte dataRecordLen;
    byte dataRecordTyp;    
}

on start
{

    dword i = 0;
    dword len = 0;
    fHandler = openFileRead("TestFile.hex",0);

    if(fHandler == 0)
    {
        write("%s",fHandler);
        write("Error occured while opening file\n");        
    }
    else
    {
        write("File opened successfully for reading\n");
        while(fileGetStringSZ(DataRecordBuf[i++],elCount(DataRecordBuf),fHandler) != 0);
        len = i;
        i = 0;
        handle = openFileWrite("MyCaplData.txt",2);
        write("File opened successfully for writing\n");
        while(len--)
        {
            filePutString(DataRecordBuf[i++],elCount(DataRecordBuf),handle);
        }
        fileClose(handle);
        write("File Closed Successfully\n");
    }
}

【问题讨论】:

  • 有什么复制的吗?
  • 没有。每当我运行代码时,目标文件始终保持空白

标签: file copy capl


【解决方案1】:

如果你想读一个写二进制数据,你应该使用

openFileRead("TestFile.hex", 1);

openFileWrite("MyCaplData.txt", 3);

这将以二进制模式而不是 ASCII 模式打开文件。

然后您应该使用fileGetBinaryBlockfileWriteBinaryBlock 来读取和写入数据。

【讨论】:

  • ,我想要 ASCII 模式的数据而不是二进制模式的数据。 CAPL 中可用于将数据从字符串转换为 ascii 或直接以 ascii 模式从文件中读取数据的任何 API
  • 也许您可以发布一些示例,说明文件中存储的内容以及您期望的输出结果。现在我对你所说的 converting from string to ascii 感到困惑
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多