正如评论中已经提到的,您需要相应地在FileWrite FUB中设置偏移量。
我通常使用FileInfo FUB Guid执行此操作 6eaf42f0-4ce5-44b7-95cb-275ae1c2fac5 在AS帮助。它会告诉您文件是否已存在以及文件大小。
如果存在,则下一步是FileOpen,否则为FileCreate。
最近我在GitLab上创建了一个小项目,其中包括在文件中附加一行: https://gitlab.com/kirni/bur_robotic_sample/blob/master/bur_robotic_sample/Logical/Libraries/TeachLib/Teach.c
代码在C中,但我相信你明白了。
case stTEACH_INFO: /*setup fub*/ this->fbInfo.enable = 1; this->fbInfo.pDevice = (UDINT)inst->szDevice; this->fbInfo.pName = (UDINT)inst->szFile; this->fbInfo.pInfo = &this->Info; //call fub FileInfo(&this->fbInfo); //fub is done.. if(this->fbInfo.status != ERR_FUB_BUSY) { //file exists -> open it and append code if(this->fbInfo.status == ERR_OK) { //start writing to the end of the file this->Offset = this->Info.size; //open existing file this->Step = stTEACH_OPEN; } //file does not exist -> create it and insert code else if(this->fbInfo.status == fiERR_FILE_NOT_FOUND) { //start writing at the beginning of the file this->Offset = this->Info.size; //crete new file this->Step = stTEACH_CREATE; } //error else { //set error status and goto error state inst->Status = this->fbInfo.status; this->Step = stTEACH_ERROR; } //disable fub this->fbInfo.enable = 0; FileInfo(&this->fbInfo); } break; case stTEACH_CREATE: /*setup fub*/ this->fbCreate.enable = 1; this->fbCreate.pDevice = (UDINT)inst->szDevice; this->fbCreate.pFile = (UDINT)inst->szFile; //call fub FileCreate(&this->fbCreate); //fub is done.. if(this->fbCreate.status != ERR_FUB_BUSY) { //success if(this->fbCreate.status == ERR_OK) { this->Ident = this->fbCreate.ident; //open existing file this->Step = stTEACH_WRITE; } //error else { //set error status and goto error state inst->Status = this->fbCreate.status; this->Step = stTEACH_ERROR; } //disable fub this->fbCreate.enable = 0; FileCreate(&this->fbCreate); } break; case stTEACH_OPEN: /*setup fub*/ this->fbOpen.enable = 1; this->fbOpen.pDevice = (UDINT)inst->szDevice; this->fbOpen.pFile = (UDINT)inst->szFile; this->fbOpen.mode = fiREAD_WRITE; //call fub FileOpen(&this->fbOpen); //fub is done.. if(this->fbOpen.status != ERR_FUB_BUSY) { //success if(this->fbOpen.status == ERR_OK) { this->Ident = this->fbOpen.ident; //open existing file this->Step = stTEACH_WRITE; } //error else { //set error status and goto error state inst->Status = this->fbOpen.status; this->Step = stTEACH_ERROR; } //disable fub this->fbOpen.enable = 0; FileOpen(&this->fbOpen); } break; case stTEACH_WRITE: /*setup fub*/ this->fbWrite.enable = 1; this->fbWrite.ident = this->Ident; this->fbWrite.offset = this->Offset; this->fbWrite.pSrc = this->szLine; this->fbWrite.len = this->Lenght; //call fub FileWrite(&this->fbWrite); //fub is done.. if(this->fbWrite.status != ERR_FUB_BUSY) { //success if(this->fbWrite.status == ERR_OK) { this->Ident = this->fbWrite.ident; //Write existing file this->Step = stTEACH_CLOSE; } //error else { //set error status and goto error state inst->Status = this->fbWrite.status; this->Step = stTEACH_ERROR; } //disable fub this->fbWrite.enable = 0; FileWrite(&this->fbWrite); } break;
然而,这也应该与 filelen FileOpen FUB的输出 - 就像你做的那样。我建议你在写入之前设置一个制动点,并检查是否正确设置了FUB的偏移量。
我还建议你在完成后再调用每个FUB 使:= 0 (就像我在我的样本中所做的那样)即禁用它。有些FUB只在更高的边缘更新输入参数 启用,执行,启动, 等输入命令。
我希望这有帮助!