Using File Operations in version 4.12.5.95

Greetings,

I cannot use the File Operations structure, which I have used frequently in my projects with Automation Studio in version 4.9.2.46, in version 4.12.5.95. I have to switch to this version due to the controller I use (X90CP154_60_00). I will tell you the structure I have set up as I used it in previous projects and I would like to get ideas and help from you about why it is not in my current project.

image

The configuration I used in the old structure is as above. It works completely in the improvements I made in the code. If there was a problem there, I would have had the same problem in previous projects, so I don’t think there is a problem with the code.

In my researches about the error, I realized 2 different points. First, I cannot use the D:\ path that I used in the image I threw above in this version. However, I could not find a place that explains exactly what I should write instead, the problem did not improve when I used A. I would appreciate if someone can explain this in detail.

Secondly, after every FILE_OPEN and FILE_CREATE operation after 4.12, FILE_CLOSE is executed. In version 4.9 I didn’t do this and didn’t have a problem, but this time I added a FILE_CLOSE under all FILE_OPEN and FILE_CREATE operations to be sure.

The configuration of the project I am currently using is as follows.

The first thing I do in my project is to open a file and try to read it. If the file does not exist, I automatically recreate it, but I get the following error when I try to open the file.

image

Hi @omer.alumur ,

due to missing code I can only speculate, but here are my findings and input:

a) You used the name “HARDDISK” in your old config but “HDD” in your new one. Does your code reflect that change?

b) Regarding not being able to use "D:" anymore: See B&R Online Help, scroll all the way down to Error numbers - “fiERR_ACCESS” explains: Read and write operations on the partitions of the safe module system (D: and E:) are no longer possible.

c) You assigned the letter "A:" - what device is it / should it be?
Regularly you have (had) access to C:, D:\ and E:\ (Safe Partition Scheme) and a User partition, which is meant for - guess - user files. You can create one in the same settings by specifying a minimum user partition size, it’s all the way up in the cpu configuration. It will then be located at F:. Starting from some (not so recent, but newer than the one you had before) AR, writing to the system’s partitions was forbidden.

So the error might be either the A:\ partition or the rename of HDD (or a combination of both)

Regarding your file close: Every file open should be matched with a FileClose. A CPU only has so many handles for files and you could run out of them. It should not be a problem if you open a file once, but once you start opening files regularly you might be facing Error 20702: fiERR_NO_MORE_ENTRIES

Hope anything of this could help you
Best regards

2 Likes

To solve your D: issue: Configure a USER partition and save your data on the default “USER” file device!

image

Hi @michael_w

a-) Yes, I made the change in the part used in the code. I defined a macro for this and updated it in the same way as below.
image

b-) I also discovered that D and E cannot be used by using the help, so I did not use it in my new project, as you can already see.

c-) I don’t know exactly why I defined ‘A’, I just looked at a B&R help page and I did it because I saw that an example was given in this way. Whatever I need to define here, I already want help from you on that subject. I have attached the screenshot of the help page I took as an example from B&R below.

I am also sharing my main code that I used for file operations below.

#include <bur/plctypes.h>
#include <AsDefault.h>
#include <sys_lib.h>

#include "FileOperation_Variable.h"

_INIT void Init(void)
{
	memset(&(file.Flag)  , 0, sizeof(file.Flag));
	memset(&(file.status), 0, sizeof(file.status));
	memset(&(file.Error) , 0, sizeof(file.Error));
	memset(&(file.Ident) , 0, sizeof(file.Ident));
	
}

void Assign_WriteData(struct fileData_Struct *data)
{
	data->portNumber = serverPort;
	
	data->stabilizationAngle.rollAngle = stabilizationReference.rollAngle;
	data->stabilizationAngle.pitchAngle = stabilizationReference.pitchAngle;
	data->motorOffsetVariables[0]		= Motor_Offset_Var[0];
	data->motorOffsetVariables[1]		= Motor_Offset_Var[1];
	data->offset.rollAngle  = offsetReference.rollAngle;
	data->offset.pitchAngle = offsetReference.pitchAngle;
	
	for (i = 0; i < 3; i++)
	{
	  data->operationTime[i]	= Time_SystemWorking[i];
	  data->systemTime[i]		= Time_SystemAll[i];	
	}
}

void Assign_BRData(struct fileData_Struct *data)
{
	serverPort = data->portNumber;
	
	Server.UdpOpen_0.enable = 1;
	Server.UdpOpen_0.port 	= serverPort;	
	UdpOpen(&Server.UdpOpen_0);
	
	stabilizationReference.rollAngle = data->stabilizationAngle.rollAngle;
	stabilizationReference.pitchAngle = data->stabilizationAngle.pitchAngle;
	Motor_Offset_Var[0] = data->motorOffsetVariables[0];
	Motor_Offset_Var[1] = data->motorOffsetVariables[1];
	
	offsetReference.rollAngle  = data->offset.rollAngle;
	offsetReference.pitchAngle = data->offset.pitchAngle;
	
	for (i = 0; i < 3; i++)
	{
		Time_SystemWorking[i]	= data->operationTime[i];
		Time_SystemAll[i]		= data->systemTime[i];
	}
}

/***** Cyclic part *****/
_CYCLIC void Cyclic(void)
{	
	switch (file.State)
	{
		case FILE_INIT:
        
			
			break;
		
		case FILE_OPEN:
			
			/* Initialize file open structure */
			file.FileOpen_0.enable    = 1;
			file.FileOpen_0.pDevice   = (UDINT) DEVICENAME;
			file.FileOpen_0.pFile     = (UDINT) FILENAME;
			file.FileOpen_0.mode      = fiREAD_WRITE;
			FileOpen(&(file.FileOpen_0));

			/* Get FBK output information */
			file.Ident.FileOpen_0  = file.FileOpen_0.ident;
			file.status.FileOpen_0 = file.FileOpen_0.status;
		
			if (file.status.FileOpen_0 == fiERR_FILE_NOT_FOUND)
				file.State = FILE_CREATE;
			
			else if (file.status.FileOpen_0 == 0)
			{
				if (file.WorkingMode == WRITE)
					file.State = FILE_WRITE;
				else if(file.WorkingMode == READ)
					file.State = FILE_READ;
			}

			else if (file.status.FileOpen_0 != 65535)
			{
				file.State = FILE_INIT;
				if (file.status.FileOpen_0 == fiERR_SYSTEM)
					file.Error.FileOpen_0 = FileIoGetSysError();
			}
        
			break;
		
		case FILE_CREATE:
	
			/* Initialize file create structure */
			file.FileCreate_0.enable  = 1;
			file.FileCreate_0.pDevice = (UDINT) DEVICENAME;
			file.FileCreate_0.pFile   = (UDINT) FILENAME;
			FileCreate(&(file.FileCreate_0));
		
			/* Get FBK output information */
			file.Ident.FileCreate_0  = file.FileCreate_0.ident;
			file.status.FileCreate_0 = file.FileCreate_0.status;
		
			/* Verify status */
			if (file.status.FileCreate_0 == 0)
				file.State = FILE_WRITE;
			else if (file.status.FileCreate_0 != 65535)
			{
				file.State = FILE_INIT;
                               
				if (file.status.FileCreate_0 == fiERR_SYSTEM)
					file.Error.FileCreate_0 = FileIoGetSysError();
			}
      
			break;
		
		case FILE_WRITE:
	
			Assign_WriteData(&(file.WriteData));

			/* Initialize file create structure */
			file.FileWrite_0.enable   = 1;
			file.FileWrite_0.ident    = file.Ident.FileOpen_0;
			file.FileWrite_0.offset   = 0;
			file.FileWrite_0.pSrc     = (UDINT) &(file.WriteData);
			file.FileWrite_0.len      = sizeof (file.WriteData);
			FileWrite(&(file.FileWrite_0));
		
			/* Get status */
			file.status.FileWrite_0 = file.FileWrite_0.status;
		
			/* Verify status */
			if (file.status.FileWrite_0 == 0)
				file.State = FILE_CLOSE;
			else if (file.status.FileWrite_0 != 65535)
			{
				file.State = FILE_INIT;

				if (file.status.FileWrite_0 == fiERR_SYSTEM)
					file.Error.FileWrite_0 = FileIoGetSysError();
			}
      
			break;
		
		case FILE_READ:
	
			/* Initialize file create structure */
			file.FileRead_0.enable    = 1;
			file.FileRead_0.ident     = file.Ident.FileOpen_0;
			file.FileRead_0.offset    = 0;
			file.FileRead_0.pDest     = (UDINT) &(file.ReadData);
			file.FileRead_0.len       = sizeof (file.ReadData);
			FileRead(&(file.FileRead_0));
		
			/* Get status */
			file.status.FileRead_0 = file.FileRead_0.status;
		
			/* Verify status */
			if (file.status.FileRead_0 == 0)
			{
				file.State = FILE_CLOSE;
				Assign_BRData(&(file.ReadData));
			}
			else if (file.status.FileRead_0 != 65535)
			{
				file.State = FILE_INIT;
				if (file.status.FileRead_0 == fiERR_SYSTEM)
					file.Error.FileRead_0 = FileIoGetSysError();
			}
       
			break;
		
		case FILE_CLOSE:
	
			file.FileClose_0.enable   = 1;
			file.FileClose_0.ident    = file.Ident.FileOpen_0;
			FileClose(&(file.FileClose_0));
	
			/* Get status */
			file.status.FileClose_0 = file.FileClose_0.status;
	
			/* Verify status */
			if (file.status.FileClose_0 == 0)
				file.State = FILE_INIT;
			else if (file.status.FileClose_0 != BUSY)
			{
				file.State = FILE_INIT;
				if (file.status.FileClose_0 == fiERR_SYSTEM)
					file.Error.FileClose_0 = FileIoGetSysError();
			}
	      
			break;
		
		case FILE_DELETE:
      
//			file.FileDelete_0.enable   = 1;
//			file.FileCreate_0.pDevice = (UDINT) DEVICENAME;
//			file.FileCreate_0.pFile   = (UDINT) FILENAME;
//			FileDelete(&(file.FileDelete_0));
//	
//			/* Get status */
//			file.status.FileDelete_0 = file.FileDelete_0.status;
//	
//			/* Verify status */
//			if (file.status.FileDelete_0 == 0)
//				file.State = FILE_INIT;
//			else if (file.status.FileDelete_0 != BUSY)
//			{
//				file.State = FILE_INIT;
//				if (file.status.FileDelete_0 == fiERR_SYSTEM)
//					file.Error.FileDelete_0 = FileIoGetSysError();
//			}
			
			break;
		
		default:

			break;
	}
}

If you define A:\ it tells the system to use partition A which does not exist in your case. As a solution see my reply above.

You could also rename the filedevice in the config of the CPU:

image

Okay, I’ll try it right away.

When I make the settings as shown here, I get the following error when transferring the project. Even though I reduced the Mib to 10, it did not improve.

The system will have to make an initial installation since you need a new partition (F:) on the CF card. The easiest way would be to recreate the CF in a card reader if you have issues transferring…

The controller I’m using doesn’t have a cf card, I can just boot it and try to transfer the project again.

1 Like

Yes I saw. But you asked about details, which I provided in my reply.

Yup, it’s not the best example, it also says “Floppy”, because floppy disk drives used to be A:\ back when they were still a thing.

I think regarding the user partition, everything else has been said multiple times by now.

Already said so in my reply :wink:

1 Like

After I booted the controller and reconnected, I tried to set my partition settings as Marcel did and tried to embed my project again, but it didn’t work. Is there any way to know the partition size I can use in my controller? Maybe 100 is too big for me.

You can check in “Online → Info → Partitions CF/HD”

I made all the changes you shared with me as you can see in the screenshots below and imported my project into the controller, but unfortunately I am still getting errors.

image

image

  • Did you update the file device name from HDD to USER?
  • Did you check the info dialog? Is the USER partition (F:) there?
  • Did you check for logger entries?

1-)
image
Yes i changed.

2-)


If you mentioning this windows yes i see USER here?

3-)


I cant see anything about file operations.

Then you’ll have to check your code… The error number suggests the handle is invalid or something like it. To verify the user partition is fine, you can:

  • Use a sample task or create a minimal task with a FileCreate.
  • Configure FTP access to the user partition, so you can connect with a ftp client to check / modify / place files.
1 Like

Hello everyone again,

After booting the controller, I transferred the project again and was able to run the file operations successfully, thank you for your support. :slight_smile:

2 Likes