AS6: Create and use file devices in the code

I’ve just started to use Automation Studio 6 and now I’m facing problem with how to manage file devices in my code.
We have a library with different wrappers for using a single axis, a scara axis group or a CNC axis group. The idea is that if you need to add another axis in your project, you just copy the “axis wrapper” task from our library. When using a scara axis group or a CNC axis group, we want to use the MappMotion features “Motion Packet Log” and “CNC & robotic programs”. To use these features we need to define file devices to use for the robot programs and for the Motion Packet log files. The default names of the file devices for these features is “CNC_PrgDir” and “MpLogDir”. I know that I could simply define these file devices in my CPU configuration (in the physical view). But I really want to configure the file devices in my code instead. So I use the DevLink FB to set up my file devices. Then I want to use the DirInfo FB to find out if the folders I want exists or not, and if the don’t I use the CreateDir FB to create the folder. But I’m not sure how to make this work.

Does anyone have a working example of how to set up a file device with DevLink and then use DirInfo and DirCreate (or something similar) in Automation Studio 6?

I was trying to save the CNC_PrgDir folder and the MpLogDir folder in the USER folder. This is how I used DevLink FB to set up the file devices in the program init:

// File device init parameters
Local.Var.FileDevice.FileDeviceName_CNC_PrgDir := 'CNC_PrgDir';
Local.Var.FileDevice.FileDevicePath_CNC_PrgDir := '/DEVICE=USER_PATH\CNC_Prg\';

// Robot program file device
Local.FB.DevLinkConfig_CNC_PrgDir.enable := TRUE;
Local.FB.DevLinkConfig_CNC_PrgDir.pDevice := ADR(Local.Var.FileDevice.FileDeviceName_CNC_PrgDir);
Local.FB.DevLinkConfig_CNC_PrgDir.pParam := ADR(Local.Var.FileDevice.FileDevicePath_CNC_PrgDir);
Local.FB.DevLinkConfig_CNC_PrgDir();

// File device init parameters
Local.Var.FileDevice.FileDeviceName_MPLogDir := 'MPLogDir';
Local.Var.FileDevice.FileDevicePath_MPLogDir := '/DEVICE=USER_PATH\MPLog\';

// Motion Packet Log file device
Local.FB.DevLinkConfig_MPLogDir.enable := TRUE;
Local.FB.DevLinkConfig_MPLogDir.pDevice := ADR(Local.Var.FileDevice.FileDeviceName_MPLogDir);
Local.FB.DevLinkConfig_MPLogDir.pParam := ADR(Local.Var.FileDevice.FileDevicePath_MPLogDir);
Local.FB.DevLinkConfig_MPLogDir();

// Wait for DevLink to finish
WHILE Local.FB.DevLinkConfig_CNC_PrgDir.status = ERR_FUB_BUSY DO
	Local.FB.DevLinkConfig_CNC_PrgDir();
END_WHILE

// Wait for DevLink to finish
WHILE Local.FB.DevLinkConfig_MPLogDir.status = ERR_FUB_BUSY DO
	Local.FB.DevLinkConfig_MPLogDir();
END_WHILE

I then use the same input for the device and the path for the DirInfo FB and the DirCreate FB in my program cyclic:

Local.FB.ConfigDirInfo_CNC_PrgDir.pDevice := ADR(Local.Var.FileDevice.FileDeviceName_CNC_PrgDir);
Local.FB.ConfigDirInfo_CNC_PrgDir.pPath := ADR(Local.Var.FileDevice.FileDevicePath_CNC_PrgDir);

Local.FB.ConfigDirInfo_MPLogDir.pDevice := ADR(Local.Var.FileDevice.FileDeviceName_MPLogDir);
Local.FB.ConfigDirInfo_MPLogDir.pPath := ADR(Local.Var.FileDevice.FileDevicePath_MPLogDir);

Local.FB.CreateDir_CNC_PrgDir.pDevice := ADR(Local.Var.FileDevice.FileDeviceName_CNC_PrgDir);
Local.FB.CreateDir_CNC_PrgDir.pName := ADR(Local.Var.FileDevice.FileDevicePath_CNC_PrgDir);

Local.FB.CreateDir_MPLogDir.pDevice := ADR(Local.Var.FileDevice.FileDeviceName_MPLogDir);
Local.FB.CreateDir_MPLogDir.pName := ADR(Local.Var.FileDevice.FileDevicePath_MPLogDir);

I do not get any error from the DevLink FB, but the DirInfo FB always return status fiERR_DIR_NOT_EXIST = Directory does not exist, and the DirCreate FB always return status fiERR_FILE_DEVICE = Invalid device name ( pDevice is too long, empty or NULL).

I tried to follow the example in the help documentation, but I can’t make it work. I guess there something about this that I don’t fully understand. What is wrong with my code?

The CNC_PrgDir and MPLogDir folders are not existing yet on the user partition F:.
So the first step should be a DevLink to /DEVICE/USER_PATH and then do the DirInfo and then if needed subsequent CreateDirs.

There are also other ways for creating these folders:

  • with an FTP-client
  • using Automatic transfer of userfiles (with Initial Transfer->Settings)

1 Like

Do you mean I should use the USER device as input when using DirInfo and CreateDir?

Local.Var.FileDevice.FileDeviceName_User := 'USER';
Local.FB.ConfigDirInfo_CNC_PrgDir.pDevice := ADR(Local.Var.FileDevice.FileDeviceName_User );
Local.FB.CreateDir_CNC_PrgDir.pDevice := ADR(Local.Var.FileDevice.FileDeviceName_User );

If you have kept the default settings for FileDevice 1, Yes.
image
It is best to keep these default settings, because then the software would also work an ArSim without changes.

OK, I’ll try this. There is one thing that I’m uncertain of about this. Do I have to use the USER_PATH for all my file devices in Automation Studio 6? When using AS 4.12, I used these names and paths on my file devices:

  • Name = USER
    Path = F:\

  • Name = USER
    Path = F:\

  • Name CNC_PrgDir
    Path = F:\PrgDir\

  • Name = MpLogDir
    Path = F:\MpLofg\

In AS 6, should I just replace F:\ with ‘USER_PATH’?

Hello,

You can use both. USER_PATH is better, as @corne.geerts has already mentioned. See help.