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?