and also when i connected my PLC with my PC i didn’t find the directorie "D:" as you see in the image FileZila, i tried all the possibilities but anything worked.
Hello guys.
well i wanna thank you for your help.
finally i created and wrote in the file successfully, that’s why i will shared with you my code like a solution and the config that you should do so as to do this task.
this is my code :
CASE step OF
4:
DirCreate_0.enable := TRUE;
DirCreate_0.pDevice := ADR(deviceName);
DirCreate_0.pName := ADR('/');
DirCreate_0();
IF DirCreate_0.status = 0 THEN
DirCreate_0.enable := FALSE;
step :=0;
ELSIF DirCreate_0.status = 65535 THEN
DirCreate_0.enable := FALSE;
step :=4;
END_IF
0: // Créer le fichier
fbOpen.enable := TRUE;
fbOpen.pDevice := ADR(deviceName);
fbOpen.pFile := ADR(fileName);
fbOpen.mode := 2; // Lecture/écriture (vérifie la valeur dans ta doc)
fbOpen();
IF fbOpen.status = 0 THEN
hFile := fbOpen.ident;
fbOpen.enable := FALSE;
step := 1; // Passer à l'écriture
ELSIF fbOpen.status = 65535 THEN // Fichier non trouvé
fbOpen.enable := FALSE;
step := 10; // Créer le fichier
ELSE
status := fbOpen.status;
step := -1; // Erreur fatale
END_IF
10: // Création du fichier
fbCreate.enable := TRUE;
fbCreate.pDevice := ADR(deviceName);
fbCreate.pFile := ADR(fileName);
fbCreate();
IF fbCreate.status = 0 THEN
fbCreate.enable := FALSE;
step := 0; // Réessayer l'ouverture
ELSIF fbCreate.status = 20705 THEN
step := 0;
ELSE
step := -1; // Erreur de création
END_IF
1: // Écriture
fbWrite.enable := TRUE;
fbWrite.ident := hFile;
fbWrite.pSrc := ADR(writeBuffer);
fbWrite.len := SIZEOF(writeBuffer);
fbWrite.offset := 0;
fbWrite();
IF fbWrite.status = 0 THEN
fbWrite.enable := FALSE;
step := 2;
ELSIF fbWrite.status = 65535 THEN
fbOpen.enable := FALSE;
step := 0;
END_IF
2: // Fermer
fbClose.enable := TRUE;
fbClose.ident := hFile;
fbClose();
IF fbClose.status = 0 THEN
fbClose.enable := FALSE;
step := 3;
ELSIF fbClose.status <> 65535 THEN
status := fbClose.status;
step := -1;
END_IF
-1: // Erreur
IF fbCreate.status = 65535 THEN
fbCreate.enable := FALSE;
step := 10; // Réessayer l'ouverture
END_IF
IF fbWrite.status = 65535 THEN
fbWrite.enable := FALSE;
step := 1;
END_IF
// status contient l’erreur
3: // Terminé avec succès
;
END_CASE
Just a heads up to your working code: One shouldnot check for “0” and “65535” but ERR_OK and ERR_FUB_BUSY.
Please also note that your fb write code (step 1) does miss error handling and returning to step 0 in case of BUSY (65535) is surely wrong as well.