I would like to know a simple method how to check if a directory exists and then copy several files in it.
More detailed explanation of the problem would be like this: I need to know if user connects a usb key into plc and then copy some files, that PLC made, on to the usb key.
I was trying to do it with FILE.DirOpen, if it returns error directory doesn't exist and vice versa.
The code follows and it doesn't work:
VARSFileCheckUsb   :File.DirOpen;FileCheckUsb(xExecute:=TRUE,sDirName:=strUsbKeyDirectory);IFFileCheckUsb.xDone=TRUETHEN  xUsbConnected:=TRUE;  FileCheckUsb(xExecute:=FALSE);ELSIFFileCheckUsb.xError=TRUETHEN  xUsbConnected:=FALSE;  FileCheckUsb(xExecute:=FALSE);END_IF
And here is also code for copying the file from HardDisk to UsbKey. Doesn't work either.
VARSFileCopy    :File.Copy;IFxTransferToUsbTHEN  sFileNameCopy1:=CONCAT(g_sMainDirectory,'FooBar.Recipes.txtrecipe');  sFileNameCopy2:=CONCAT(strUsbKeyDirectory,'FooBar.Recipes.txtrecipe');    FileCopy(xExecute:=TRUE,sFileNameSource:=sFileNameCopy1,sFileNameDest:=sFileNameCopy2,xOverWrite:=TRUE);  IFFileCopy.xDone=TRUETHEN    FileCopy(xExecute:=FALSE);  ELSIFFileClose.xError=TRUETHEN    FileCopy(xExecute:=FALSE);  END_IF    xTransferToUsb:=FALSE;END_IF
The code is called inside the RECIPE_PRG.
My PLC is JanzTec em[VIEW] 12 with WindowsCE as an operating system.
All your help would be much appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think you need to setup a state machine using case statements. File system operations span multiple executions of you task. So when you trigger an operation by toggling an execute bit you have to advance to the next state where you wait for either the Done or the Error bit to be set. I would look something like the following
VARSFileCopy  :File.Copy;Step    :INT;IFxTransferToUsbTHEN  sFileNameCopy1:=CONCAT(g_sMainDirectory,'FooBar.Recipes.txtrecipe');  sFileNameCopy2:=CONCAT(strUsbKeyDirectory,'FooBar.Recipes.txtrecipe');  xTransferToUsb:=FALSE;  Step:=01;END_IF   CASEStepOF  00://Waitfortrigger     01://Initiatefilecopy    FileCopy(      xExecute:=TRUE,      sFileNameSource:=sFileNameCopy1,      sFileNameDest:=sFileNameCopy2,      xOverWrite:=TRUE    );    Step:=02;      02://Waitforoperationtocomplete    IFFileCopy.xDoneTHEN      Step:=03;    ELSIFFileClose.xErrorTHEN      Step:=04;    END_IF    03://Operationcompletedsuccessfully    //Dosomething    Step:=05;      04://Operationfailed    //Dosomethingelse    Step:=05;  05://Resetoperation    FileCopy(xExecute:=FALSE);    Step:=00; END_CASEÂ
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would like to know a simple method how to check if a directory exists and then copy several files in it.
More detailed explanation of the problem would be like this: I need to know if user connects a usb key into plc and then copy some files, that PLC made, on to the usb key.
I was trying to do it with FILE.DirOpen, if it returns error directory doesn't exist and vice versa.
The code follows and it doesn't work:
And here is also code for copying the file from HardDisk to UsbKey. Doesn't work either.
The code is called inside the RECIPE_PRG.
My PLC is JanzTec em[VIEW] 12 with WindowsCE as an operating system.
All your help would be much appreciated.
I think you need to setup a state machine using case statements. File system operations span multiple executions of you task. So when you trigger an operation by toggling an execute bit you have to advance to the next state where you wait for either the Done or the Error bit to be set. I would look something like the following